Answer the question
In order to leave comments, you need to log in
How to call a class method that is passed as an option in the artisan command?
In Lumen I want to make a command that will parse data and enter it into the database, the option of this command will be the name of the class that will perform the parsing, i.e. something like this php artisan parse --service=SomeParser
Can I do this in the method that is called when executing the command:
$this->getLaravel()->call($this->arguments('service') . '@parse')
parse
will take the data and put it into the database. All parser classes implement a common interface in which the method is defined. parse
Answer the question
In order to leave comments, you need to log in
With this option, you need to specify the class name with a namespace. This option, although it works, looks like a crutch. It would be better to call some factory class in the command and pass the name of the parser there, which, in principle, I did.
First, stop using Lumen. It is suitable for a business card site with reviews.
Secondly, did you test the functionality of the specified code, or not?)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question