A
A
Alexander Maslov2016-09-30 00:00:52
Laravel
Alexander Maslov, 2016-09-30 00:00:52

How in php from one class to make a call to other classes depending on their name?

Good day!
There was such question, I hope that I will formulate it is accessible.
The crux of the matter is this. There is a class object that receives a certain parameter as input, it is necessary to call the class depending on the name of this parameter (which is called like this parameter, while I think so).
For example:

  • Http/StartController.php - class, to the method of which the required parameter is passed
  • Commands /TestCommand.php - the command to be called depending on the parameter
  • Commands /HelloCommand.php - command etc
  • Commands /WeatherCommand.php - etc command

For example, we pass the weather command to the StartController class method and should receive a response from the WeatherCommand class method, etc.
In general, the structure of all this is not clear to me (
It is clear that it will be necessary to use the same methods in the command classes, and in fact nothing more ...
This is necessary for the Bot of the VK communities. Maybe there are links to examples or something else. I watched the implementation of telegram-sdk -laravel but it is written in such a way that my current level of knowledge of php and OOP in particular is not enough to parse everything (
In general, I ask for help! Thank you in advance, and I apologize if I described something wrong

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DevMan, 2016-09-30
@MrRino

php.net/manual/en/function.call-user-func.php
php.net/manual/en/function.call-user-func-array.php
php.net/manual/en/reflectionmethod.invoke.php

S
Stanislav Pochepko, 2016-09-30
@DJZT

It seems you are doing something wrong. And I think you need to rebuild the application here using interfaces

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question