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; } } }); }
/** * @param ApplicationInterface $app * * @throws \ObjectivePHP\ServicesFactory\Exception\Exception * @internal param ApplicationInterface $application * */ protected function injectInitialServices(ApplicationInterface $app) { $app->getServicesFactory()->registerService(['id' => 'application', 'instance' => $app], ['id' => 'config', 'instance' => $app->getConfig()], ['id' => 'events-handler', 'instance' => $app->getEventsHandler()]); }