-
-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create an event runner with closure call support
- Loading branch information
Showing
8 changed files
with
796 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace Crunz\Console\Command; | ||
|
||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use SuperClosure\Serializer; | ||
use Crunz\Invoker; | ||
use Crunz\Configuration\Configurable; | ||
|
||
class ClosureRunCommand extends Command | ||
{ | ||
use Configurable; | ||
|
||
/** | ||
* Configures the current command | ||
* | ||
*/ | ||
protected function configure() | ||
{ | ||
$this->configurable(); | ||
$this->setName('closure:run') | ||
->setDescription('Executes a closure as a process.') | ||
->setDefinition([ | ||
new InputArgument('closure', InputArgument::REQUIRED, 'The closure to run'), | ||
]) | ||
->setHelp('This command executes a closure as a separate process.'); | ||
} | ||
|
||
/** | ||
* Executes the current command | ||
* | ||
* @param use Symfony\Component\Console\Input\InputInterface $input | ||
* @param use Symfony\Component\Console\Input\OutputIterface $output | ||
* | ||
* @return null|int null or 0 if everything went fine, or an error code | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$this->arguments = $input->getArguments(); | ||
parse_str($this->arguments['closure'], $args); | ||
|
||
$serializer = new Serializer(); | ||
(new Invoker())->call($serializer->unserialize($args[0])); | ||
} | ||
|
||
} |
Oops, something went wrong.