/**
  * @param ApplicationInterface $app
  *
  * @throws Exception
  */
 public function run(ApplicationInterface $app)
 {
     $this->application = $app;
     $action = $app->getRequest()->getAction();
     if ($action) {
         $actionMiddleware = new ActionMiddleware(Invokable::cast($action));
         $serviceId = $action instanceof ServiceReference ? $action->getId() : $this->computeServiceName($app->getRequest()->getUri()->getPath());
         $app->getStep('action')->plug($actionMiddleware);
     } else {
         $route = $app->getRequest()->getRoute();
         // compute service id
         $serviceId = $this->computeServiceName($route);
         // if no service matching the route has been registered,
         // try to locate a class that could be used as service
         if (!$app->getServicesFactory()->isServiceRegistered($serviceId)) {
             $actionClass = $this->resolveActionClassName($route);
             $action = $this->resolveActionFullyQualifiedName($actionClass);
             if (!$action) {
                 throw new Exception(sprintf('No callback found to map the requested route "%s"', $route), Exception::ACTION_NOT_FOUND);
             }
             $app->getServicesFactory()->registerService(['id' => $serviceId, 'class' => $action]);
         }
         // replace action by serviceId to ensure it will be fetched using the ServicesFactory
         $actionReference = new ServiceReference($serviceId);
         // wrap action to inject returned value in application
         $app->getStep('action')->plug($actionMiddleware = new ActionMiddleware($actionReference));
     }
     // store action as application parameter for further reference
     $app->setParam('runtime.action.middleware', $actionMiddleware);
     $app->setParam('runtime.action.service-id', $serviceId);
 }
 /**
  * @param ApplicationInterface $app
  *
  * @throws Exception
  */
 public function run(ApplicationInterface $app)
 {
     if (empty($app->getSteps()[$this->bootstrapStep])) {
         throw new Exception(sprintf('Cannot plug Beanstalk services registration to specified application step: "%s" because this step has not been defined.', $this->bootstrapStep));
     }
     $app->getStep($this->bootstrapStep)->plug([$this, 'registerServices']);
 }
 public function __invoke(ApplicationInterface $application)
 {
     $appConfig = $application->getConfig();
     foreach ($appConfig->packages->registered as $packageClass) {
         $application->getStep('init')->plug($packageClass);
     }
 }
 public function __invoke(ApplicationInterface $application)
 {
     $application->getStep('bootstrap')->plug([$this, 'buildEntityManagers']);
     // initialize entities locations
     //$application->getConfig()->merge(['doctrine.em.default.entities.locations' => []]);
 }
 /**
  * @param ApplicationInterface $app
  */
 public function __invoke(ApplicationInterface $app)
 {
     $app->getStep('bootstrap')->plug([$this, 'bootstrapEloquent']);
 }