public function testSerializeAndUnserializeOfReflection()
 {
     $this->container->setAutoResolve(false);
     $this->container->params['Aura\\Di\\FakeParamsClass'] = array('array' => array(), 'empty' => 'abc');
     $instance = $this->container->newInstance('Aura\\Di\\FakeParamsClass');
     $this->assertInstanceOf('Aura\\Di\\FakeParamsClass', $instance);
     $this->container = serialize($this->container);
     $this->container = unserialize($this->container);
     $instance = $this->container->newInstance('Aura\\Di\\FakeParamsClass', array('array' => array('a' => 1)));
     $this->assertInstanceOf('Aura\\Di\\FakeParamsClass', $instance);
 }
Exemple #2
0
 public function modify(Container $di)
 {
     $dispatcher = $di->get('aura/cli-kernel:dispatcher');
     $dispatcher->setObject('logger', $di->newInstance('Mbrevda\\MonologServer\\ServerRunner'));
     $help_service = $di->get('aura/cli-kernel:help_service');
     $help = $di->newInstance('Aura\\Cli\\Help');
     $help_service->set('logger', function () use($help) {
         $help->setSummary('Runs the Streaming Logger Server');
         $help->setOptions(['addr:' => 'The address that the server will listen on']);
         return $help;
     });
 }
Exemple #3
0
 protected function modifyLogger(Container $di)
 {
     $project = $di->get('project');
     $mode = $project->getMode();
     $file = $project->getPath("tmp/log/{$mode}.log");
     $logger = $di->get('aura/project-kernel:logger');
     $logger->pushHandler($di->newInstance('Monolog\\Handler\\StreamHandler', array('stream' => $file)));
 }
Exemple #4
0
 /**
  * @throws Exception\ContentTypeNotValidException
  * @throws NotFoundException
  * @throws \Exception
  */
 public function execute()
 {
     $config = $this->config->getConfig();
     // Figure out the route information.
     try {
         $routepath = $this->evaluateRoute();
         $route = $routepath->params;
         $components = $this->determineRouteComponents($route);
         $params = $route;
         unset($params['action']);
         unset($params['responder']);
         unset($params['method']);
     } catch (NotFoundException $e) {
         if (isset($config['error_page']['404'])) {
             $lastRoute = $this->router->getLastRoute();
             $this->eventLog->info(sprintf("No route was found that matches '%s'", $lastRoute));
             $responder = $this->serviceLocator->newInstance($config['error_page']['404']);
             $this->responseManager->process(new Payload(), $responder);
             return;
         }
         // No 404 page was set, so let's throw the exception.
         throw $e;
     }
     // Load the responder that we identified from routes.
     $responder = $this->serviceLocator->newInstance($components['responderClass']);
     // Load the action we identified from routes, if one exists.
     if (!is_null($components['actionClass'])) {
         $action = $this->serviceLocator->newInstance($components['actionClass']);
         if (!is_callable([$action, $components['actionMethod']])) {
             throw new NoValidMethod(sprintf('The method %s does not exist on action %s', $components['actionMethod'], $components['actionClass']));
         }
         // Call the action.
         $result = call_user_func_array([$action, $components['actionMethod']], $params);
     }
     // Let's not leave the response hanging...
     if (!isset($result) || !$result) {
         $result = new Payload();
     }
     // Call and send the response, if possible.
     $this->responseManager->process($result, $responder);
 }
 /**
  *
  * Creates a new DI container, adds pre-existing service objects, applies
  * Config classes to define() services, locks the container, and applies
  * the Config instances to modify() services.
  *
  * @param array $services Pre-existing service objects to set into the
  * container.
  *
  * @param array $configClasses A list of Config classes to instantiate and
  * invoke for configuring the container.
  *
  * @param bool $autoResolve Enable or disable auto-resolve after the
  * define() step?
  *
  * @return Container
  *
  */
 public function newInstance(array $services = [], array $configClasses = [], $autoResolve = true)
 {
     $di = new Container(new Factory());
     $di->setAutoResolve($autoResolve);
     foreach ($services as $key => $val) {
         $di->set($key, $val);
     }
     $configs = [];
     foreach ($configClasses as $class) {
         $configs[] = $config = is_string($class) ? $di->newInstance($class) : $class;
         $config->define($di);
     }
     $di->lock();
     foreach ($configs as $config) {
         $config->modify($di);
     }
     return $di;
 }
Exemple #6
0
 public function modify(Container $di)
 {
     /**
      * Setup HTTP middlewares
      */
     $di->get('http_middlewares')->addMany([[$di->newInstance('asylgrp\\workbench\\Http\\Middleware\\ExceptionHandler'), 1], [$di->newInstance('asylgrp\\workbench\\Http\\Middleware\\HttpsEnforcer'), 2], [$di->newInstance('asylgrp\\workbench\\Http\\Middleware\\HttpRefererChecker'), 3], [$di->newInstance('asylgrp\\workbench\\Http\\Middleware\\HttpCacheDisabler'), 4], [$di->newInstance('asylgrp\\workbench\\Http\\Middleware\\Router'), 999]]);
     /**
      * Setup the event dispatcher
      */
     $subscribers = ['asylgrp\\workbench\\Storage\\ContactStorageSubscriber', 'asylgrp\\workbench\\Storage\\ClaimStorageSubscriber'];
     foreach ($subscribers as $subscriberClass) {
         $di->get('event_dispatcher')->addSubscriber($di->newInstance($subscriberClass));
     }
     // Create manifest
     $di->get('router_map')->get('manifest', '', $di->lazyNew('asylgrp\\workbench\\Http\\Action\\RespondingAction', ['responder' => $di->lazyNew('asylgrp\\workbench\\Http\\Responder\\ManifestResponder')]));
     /**
      * Setup routes for the CONTACTS namespace
      */
     $di->get('router_map')->attach('contacts.', '/contacts', function ($map) use($di) {
         $map->get('coll.read', '', $di->lazyNew('asylgrp\\workbench\\Http\\Action\\RespondingAction', ['responder' => $di->lazyNew('asylgrp\\workbench\\Http\\Responder\\ContactCollectionResponder')]));
         $map->get('item.read', '/{id}', $di->lazyNew('asylgrp\\workbench\\Http\\Action\\ReadIdAction', ['responder' => $di->lazyNew('asylgrp\\workbench\\Http\\Responder\\ContactItemResponder')]));
         $map->get('item.claims', '/{id}/claims', $di->lazyNew('asylgrp\\workbench\\Http\\Action\\ReadIdAction', ['responder' => $di->lazyNew('asylgrp\\workbench\\Http\\Responder\\ClaimCollectionResponder')]));
         $map->delete('item.delete', '/{id}', $di->lazyNew('asylgrp\\workbench\\Http\\Action\\DeleteContactAction'));
         // TODO ...
         $map->post('item.create', '', $di->lazyNew('TODO asylgrp\\workbench\\Http\\Action\\CreateContact'));
         $map->put('item.update', '/{id}', $di->lazyNew('TODO asylgrp\\workbench\\Http\\Action\\UpdateContact'));
     });
     /**
      * Setup routes for the CLAIMS namespace
      */
     $di->get('router_map')->attach('claims.', '/claims', function ($map) use($di) {
         $map->get('coll.read', '', $di->lazyNew('asylgrp\\workbench\\Http\\Action\\RespondingAction', ['responder' => $di->lazyNew('asylgrp\\workbench\\Http\\Responder\\GroupedClaimCollectionResponder')]));
         $map->get('item.read', '/{id}', $di->lazyNew('asylgrp\\workbench\\Http\\Action\\ReadIdAction', ['responder' => $di->lazyNew('asylgrp\\workbench\\Http\\Responder\\ClaimItemResponder')]));
         $map->delete('coll.truncate', '', $di->lazyNew('asylgrp\\workbench\\Http\\Action\\TruncateClaimsAction'));
         $map->delete('item.delete', '/{id}', $di->lazyNew('asylgrp\\workbench\\Http\\Action\\DeleteClaimAction'));
         // TODO ...
         $map->post('item.create', '', $di->lazyNew('TODO asylgrp\\workbench\\Http\\Action\\CreateClaim'));
         $map->put('item.update', '/{id}', $di->lazyNew('TODO asylgrp\\workbench\\Http\\Action\\UpdateClaim'));
     });
 }
Exemple #7
0
 public function modify(Container $di)
 {
     $twig = $di->get('twig');
     $twig->addExtension($di->newInstance('Twig_Extension_Debug'));
 }