public function run(ApplicationInterface $app) { $connector = Connector::getInstance(); $connector->setSourcesBasePath(getcwd()); $matcher = new Matcher(); // redirect errors to PhpConsole \PhpConsole\Handler::getInstance()->start(); $app->getEventsHandler()->bind('*', function (EventInterface $event) use($app, $connector, $matcher) { /** * @var $connector \PhpConsole\Connector */ if ($connector->isActiveClient()) { $console = \PhpConsole\Handler::getInstance(); $context = $event->getContext(); $origin = $event->getOrigin(); switch (true) { case $event->getName() == 'application.workflow.step.run': $console->debug(sprintf('Starting running step %s', $origin->getName()), 'workflow.step'); break; case $event->getName() == 'application.workflow.hook.run': $middleware = $origin->getMiddleware(); $console->debug(sprintf('Running Middleware %s (%s)', $middleware->getReference(), $middleware->getDescription()), 'workflow.hook'); $this->dumpNotifications($console, $middleware->getNotifications()); break; case $matcher->match(ServicesFactory::EVENT_INSTANCE_BUILT . '.*', $event->getName()): $console->debug(sprintf('Built service %s (%s)', $context['serviceSpecs']->getId(), is_object($context['instance']) ? get_class($context['instance']) : get_type($context['instance'])), 'services'); break; case $matcher->match($event->getName(), '*.notify.*'): $this->dumpNotifications($console, $event->getContext('notifications')); break; } } }); }
public function testAlternativesExtractor() { $matcher = new Matcher(); $this->assertEquals(['name', 'alternate'], $matcher->extractAlternatives('[name|alternate]')); $this->assertEquals(['name', 'alternate', 'last'], $matcher->extractAlternatives('[name|alternate||last]')); // missing trailing ']' $this->expectsException(function () use($matcher) { $matcher->extractAlternatives('[invalid|syntax'); }, Exception::class); // no alternatives $this->expectsException(function () use($matcher) { $matcher->extractAlternatives('[]'); }, Exception::class); // no alternatives $this->expectsException(function () use($matcher) { $matcher->extractAlternatives('[|]'); }, Exception::class); }
/** * @param $service * * @return ServiceSpecsInterface */ public function getServiceSpecs($service) { if ($service instanceof ServiceReference) { $service = $service->getId(); } $specs = $this->services[$service] ?? null; if (is_null($specs)) { $matcher = new Matcher(); foreach ($this->services as $id => $specs) { if ($matcher->match($service, $id)) { return (clone $specs)->setId($service); break; } $specs = null; } } return $specs; }