From b7801e1e9030cadf46e726382cfdac69bd7fab43 Mon Sep 17 00:00:00 2001 From: Emanuele Minotto Date: Mon, 5 Oct 2015 07:47:28 +0200 Subject: [PATCH] process contract (fixes #6) --- src/Event/AbstractProcessEvent.php | 11 +++--- src/Event/ProcessGeneratedBufferEvent.php | 11 +++--- src/Process/Channel/Channels.php | 8 ++-- src/Process/ClosureProcess.php | 4 +- src/Process/Process.php | 12 +++++- src/Process/ProcessInterface.php | 45 +++++++++++++++++++++++ 6 files changed, 72 insertions(+), 19 deletions(-) create mode 100644 src/Process/ProcessInterface.php diff --git a/src/Event/AbstractProcessEvent.php b/src/Event/AbstractProcessEvent.php index 697cead..b506405 100644 --- a/src/Event/AbstractProcessEvent.php +++ b/src/Event/AbstractProcessEvent.php @@ -2,27 +2,26 @@ namespace Liuggio\Spawn\Event; -use Liuggio\Spawn\Process\ClosureProcess; -use Liuggio\Spawn\Process\Process; +use Liuggio\Spawn\Process\ProcessInterface; use Symfony\Component\EventDispatcher\Event; abstract class AbstractProcessEvent extends Event { /** - * @var ClosureProcess|Process + * @var ProcessInterface */ protected $process; /** - * @param ClosureProcess|Process $process + * @param ProcessInterface $process */ - public function __construct($process) + public function __construct(ProcessInterface $process) { $this->process = $process; } /** - * @return ClosureProcess|Process + * @return ProcessInterface */ public function getProcess() { diff --git a/src/Event/ProcessGeneratedBufferEvent.php b/src/Event/ProcessGeneratedBufferEvent.php index 18f79ea..dd87bf2 100644 --- a/src/Event/ProcessGeneratedBufferEvent.php +++ b/src/Event/ProcessGeneratedBufferEvent.php @@ -2,27 +2,26 @@ namespace Liuggio\Spawn\Event; -use Liuggio\Spawn\Process\ClosureProcess; -use Liuggio\Spawn\Process\Process; +use Liuggio\Spawn\Process\ProcessInterface; use Symfony\Component\EventDispatcher\Event; final class ProcessGeneratedBufferEvent extends Event { /** - * @var Process|ClosureProcess + * @var ProcessInterface */ private $process; /** - * @param Process|ClosureProcess $process + * @param ProcessInterface $process */ - public function __construct($process) + public function __construct(ProcessInterface $process) { $this->process = $process; } /** - * @return Process|ClosureProcess + * @return ProcessInterface */ public function getProcess() { diff --git a/src/Process/Channel/Channels.php b/src/Process/Channel/Channels.php index afced08..e6e9860 100644 --- a/src/Process/Channel/Channels.php +++ b/src/Process/Channel/Channels.php @@ -2,7 +2,7 @@ namespace Liuggio\Spawn\Process\Channel; -use Liuggio\Spawn\Process\Process; +use Liuggio\Spawn\Process\ProcessInterface; class Channels { @@ -38,10 +38,10 @@ public static function createWaiting($channelsNumber) /** * Assign a channel to a processes. * - * @param Channel $channel - * @param Process $process + * @param Channel $channel + * @param ProcessInterface $process */ - public function assignAProcess(Channel $channel, Process $process) + public function assignAProcess(Channel $channel, ProcessInterface $process) { $this->channels[$channel->getId()] = $channel->assignToAProcess($process); } diff --git a/src/Process/ClosureProcess.php b/src/Process/ClosureProcess.php index aed396e..31bd017 100644 --- a/src/Process/ClosureProcess.php +++ b/src/Process/ClosureProcess.php @@ -6,7 +6,7 @@ use Liuggio\Spawn\Process\Channel\Channel; use Symfony\Component\Process\PhpProcess; -class ClosureProcess extends PhpProcess +class ClosureProcess extends PhpProcess implements ProcessInterface { /** * @var ProcessEnvironment @@ -85,7 +85,7 @@ public function getIncrementalNumber() } /** - * The channel where the processes is executed. + * The channel where the process is executed. * * @return Channel */ diff --git a/src/Process/Process.php b/src/Process/Process.php index 05ce258..ad236df 100644 --- a/src/Process/Process.php +++ b/src/Process/Process.php @@ -5,7 +5,7 @@ use Liuggio\Spawn\CommandLine; use Symfony\Component\Process\Process as BaseProcess; -class Process extends BaseProcess +class Process extends BaseProcess implements ProcessInterface { /** * @var ProcessEnvironment @@ -52,11 +52,21 @@ public function getCommandLine() return new CommandLine(parent::getCommandLine()); } + /** + * The current Id of the processes. + * + * @return int + */ public function getIncrementalNumber() { return $this->processEnvironment->getIncrementalNumber(); } + /** + * The channel where the process is executed. + * + * @return Channel + */ public function getChannel() { return $this->processEnvironment->getChannel(); diff --git a/src/Process/ProcessInterface.php b/src/Process/ProcessInterface.php new file mode 100644 index 0000000..b8d55e7 --- /dev/null +++ b/src/Process/ProcessInterface.php @@ -0,0 +1,45 @@ +