Skip to content

Commit

Permalink
Create an event runner with closure call support
Browse files Browse the repository at this point in the history
  • Loading branch information
lavary committed Aug 2, 2016
1 parent 395a2b8 commit cabc7a0
Show file tree
Hide file tree
Showing 8 changed files with 796 additions and 220 deletions.
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"cron",
"Task Scheduler",
"PHP Task Scheduler",
"Laravel Task Scheduler"
"Job Scheduler",
"Job Manager",
"Event Runner"
],
"homepage": "https://github.com/lavary/crunz",
"license": "MIT",
Expand All @@ -31,7 +33,8 @@
"symfony/process": "^3.0",
"guzzlehttp/guzzle": "^6.1",
"symfony/console": "^3.0",
"symfony/config": "^3.0"
"symfony/config": "^3.0",
"jeremeamia/superclosure": "^2.2"
},
"require-dev": {
"phpunit/phpunit": "^4.8 || ^5.0"
Expand Down
49 changes: 49 additions & 0 deletions src/Console/Command/ClosureRunCommand.php
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]));
}

}
Loading

0 comments on commit cabc7a0

Please sign in to comment.