Skip to content

Commit

Permalink
process contract (fixes #6)
Browse files Browse the repository at this point in the history
  • Loading branch information
EmanueleMinotto committed Oct 5, 2015
1 parent 64dfe99 commit b7801e1
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 19 deletions.
11 changes: 5 additions & 6 deletions src/Event/AbstractProcessEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
11 changes: 5 additions & 6 deletions src/Event/ProcessGeneratedBufferEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
8 changes: 4 additions & 4 deletions src/Process/Channel/Channels.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Liuggio\Spawn\Process\Channel;

use Liuggio\Spawn\Process\Process;
use Liuggio\Spawn\Process\ProcessInterface;

class Channels
{
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Process/ClosureProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -85,7 +85,7 @@ public function getIncrementalNumber()
}

/**
* The channel where the processes is executed.
* The channel where the process is executed.
*
* @return Channel
*/
Expand Down
12 changes: 11 additions & 1 deletion src/Process/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
45 changes: 45 additions & 0 deletions src/Process/ProcessInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Liuggio\Spawn\Process;

use Liuggio\Spawn\CommandLine;

interface ProcessInterface
{
/**
* @param CommandLine $commandLine
* @param ProcessEnvironment $processEnvironment
* @param int|float|null $timeout
* @param string|null $cwd
*/
public function __construct(

This comment has been minimized.

Copy link
@liuggio

liuggio Oct 5, 2015

Owner

I think we can remove the __construct in the interface WDYT?

This comment has been minimized.

Copy link
@EmanueleMinotto

EmanueleMinotto Oct 5, 2015

Author Collaborator

That's right, I'm going to remove it. 👍

A new (minor) issue is related to this interface: #8
Let me know what you think about it. :)

CommandLine $commandLine,
ProcessEnvironment $processEnvironment,
$timeout = null,
$cwd = null
);

/**
* @return mixed
*/
public function getInputLine();

/**
* @return CommandLine
*/
public function getCommandLine();

/**
* The current Id of the processes.
*
* @return int
*/
public function getIncrementalNumber();

/**
* The channel where the process is executed.
*
* @return Channel
*/
public function getChannel();
}

0 comments on commit b7801e1

Please sign in to comment.