-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Will add Lifecycle and event logic. - First event 'before engine is started'. - Console format moved to lifecycle. - Shark Printer moved to lifecylce and removed from runner! - paraunit bin cleanup - container isolation wip
- Loading branch information
Showing
11 changed files
with
235 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ bin | |
vendor | ||
composer.lock | ||
build/ | ||
swiftmailer/ |
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
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,84 @@ | ||
<?php | ||
|
||
namespace Paraunit\Lifecycle; | ||
|
||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
class CompilerPass implements CompilerPassInterface | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $dispatcherService; | ||
/** | ||
* @var string | ||
*/ | ||
protected $listenerTag; | ||
/** | ||
* @var string | ||
*/ | ||
protected $subscriberTag; | ||
/** | ||
* Constructor. | ||
* | ||
* @param string $dispatcherService Service name of the event dispatcher in processed container | ||
* @param string $listenerTag Tag name used for listener | ||
* @param string $subscriberTag Tag name used for subscribers | ||
*/ | ||
public function __construct($dispatcherService = 'event_dispatcher', $listenerTag = 'kernel.event_listener', $subscriberTag = 'kernel.event_subscriber') | ||
{ | ||
$this->dispatcherService = $dispatcherService; | ||
$this->listenerTag = $listenerTag; | ||
$this->subscriberTag = $subscriberTag; | ||
} | ||
|
||
public function process(ContainerBuilder $container) | ||
{ | ||
if (!$container->hasDefinition($this->dispatcherService) && !$container->hasAlias($this->dispatcherService)) { | ||
return; | ||
} | ||
$definition = $container->findDefinition($this->dispatcherService); | ||
foreach ($container->findTaggedServiceIds($this->listenerTag) as $id => $events) { | ||
$def = $container->getDefinition($id); | ||
if (!$def->isPublic()) { | ||
throw new \InvalidArgumentException(sprintf('The service "%s" must be public as event listeners are lazy-loaded.', $id)); | ||
} | ||
if ($def->isAbstract()) { | ||
throw new \InvalidArgumentException(sprintf('The service "%s" must not be abstract as event listeners are lazy-loaded.', $id)); | ||
} | ||
foreach ($events as $event) { | ||
$priority = isset($event['priority']) ? $event['priority'] : 0; | ||
if (!isset($event['event'])) { | ||
throw new \InvalidArgumentException(sprintf('Service "%s" must define the "event" attribute on "%s" tags.', $id, $this->listenerTag)); | ||
} | ||
if (!isset($event['method'])) { | ||
$event['method'] = 'on'.preg_replace_callback(array( | ||
'/(?<=\b)[a-z]/i', | ||
'/[^a-z0-9]/i', | ||
), function ($matches) { return strtoupper($matches[0]); }, $event['event']); | ||
$event['method'] = preg_replace('/[^a-z0-9]/i', '', $event['method']); | ||
} | ||
$definition->addMethodCall('addListenerService', array($event['event'], array($id, $event['method']), $priority)); | ||
} | ||
} | ||
foreach ($container->findTaggedServiceIds($this->subscriberTag) as $id => $attributes) { | ||
$def = $container->getDefinition($id); | ||
if (!$def->isPublic()) { | ||
throw new \InvalidArgumentException(sprintf('The service "%s" must be public as event subscribers are lazy-loaded.', $id)); | ||
} | ||
if ($def->isAbstract()) { | ||
throw new \InvalidArgumentException(sprintf('The service "%s" must not be abstract as event subscribers are lazy-loaded.', $id)); | ||
} | ||
// We must assume that the class value has been correctly filled, even if the service is created by a factory | ||
$class = $container->getParameterBag()->resolveValue($def->getClass()); | ||
$refClass = new \ReflectionClass($class); | ||
$interface = 'Symfony\Component\EventDispatcher\EventSubscriberInterface'; | ||
if (!$refClass->implementsInterface($interface)) { | ||
throw new \InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface)); | ||
} | ||
$definition->addMethodCall('addSubscriberService', array($id, $class)); | ||
} | ||
} | ||
} |
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,47 @@ | ||
<?php | ||
|
||
namespace Paraunit\Lifecycle; | ||
|
||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\EventDispatcher\Event; | ||
|
||
/*** | ||
* Class EngineEvent | ||
* @package Paraunit\Lifecycle | ||
*/ | ||
class EngineEvent extends Event | ||
{ | ||
// This Event will be triggered before the whole paraunit engine is started | ||
const BEFORE_START = 'engine_event.before_start'; | ||
|
||
/** @var array */ | ||
protected $files; | ||
|
||
/** @var OutputInterface */ | ||
protected $outputInterface; | ||
|
||
/** | ||
* EngineEvent constructor. | ||
* @param $files | ||
* @param OutputInterface $outputInterface | ||
*/ | ||
public function __construct($files, OutputInterface $outputInterface) | ||
{ | ||
$this->files = $files; | ||
$this->outputInterface = $outputInterface; | ||
} | ||
|
||
public static function buildFromContext($files, OutputInterface $outputInteface){ | ||
|
||
return new EngineEvent($files, $outputInteface); | ||
|
||
} | ||
|
||
/** | ||
* @return OutputInterface | ||
*/ | ||
public function getOutputInterface(){ | ||
return $this->outputInterface; | ||
} | ||
|
||
} |
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,41 @@ | ||
<?php | ||
|
||
namespace Paraunit\Printer; | ||
|
||
use Paraunit\Lifecycle\EngineEvent; | ||
use Symfony\Component\Console\Formatter\OutputFormatterStyle; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Class ConsoleFormatter | ||
* @package Paraunit\Printer | ||
*/ | ||
class ConsoleFormatter | ||
{ | ||
/** | ||
* @param EngineEvent $engineEvent | ||
*/ | ||
public function onEngineStart(EngineEvent $engineEvent){ | ||
|
||
$outputInterface= $engineEvent->getOutputInterface(); | ||
|
||
if ($outputInterface->getFormatter()) { | ||
$style = new OutputFormatterStyle('green', null, array('bold', 'blink')); | ||
$outputInterface->getFormatter()->setStyle('ok', $style); | ||
|
||
$style = new OutputFormatterStyle('yellow', null, array('bold', 'blink')); | ||
$outputInterface->getFormatter()->setStyle('skipped', $style); | ||
|
||
$style = new OutputFormatterStyle('blue', null, array('bold', 'blink')); | ||
$outputInterface->getFormatter()->setStyle('incomplete', $style); | ||
|
||
$style = new OutputFormatterStyle('red', null, array('bold', 'blink')); | ||
$outputInterface->getFormatter()->setStyle('fail', $style); | ||
|
||
$style = new OutputFormatterStyle('red', null, array('bold', 'blink')); | ||
$outputInterface->getFormatter()->setStyle('error', $style); | ||
} | ||
|
||
} | ||
|
||
} |
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
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