Beispiel #1
0
 /**
  * Constructor application.
  *
  * @param \Psr\Http\Message\ServerRequestInterface $request
  * @param \Psr\Http\Message\ResponseInterface $response
  * @param \Interop\Container\ContainerInterface $container
  */
 public function __construct(ContainerInterface $container, ServerRequestInterface $request, ResponseInterface $response)
 {
     $this->container = $container;
     $this->request = $request;
     $this->response = $response;
     // Check container set exist
     if (method_exists($this->container, 'set')) {
         // Inject self application for middlewares freedom
         $this->container->set(ApplicationInterface::class, $this);
     }
 }
Beispiel #2
0
 /**
  * Application initialization.
  *
  * @param mixed              $router    Routing system.
  * @param ContainerInterface $container Dependency Injection container.
  */
 public function __construct($router = null, ContainerInterface $container = null)
 {
     $this->container = $container ?: $this->buildContainer(Loader::load());
     $container =& $this->container;
     $this->response = new Response();
     $this->request = ServerRequestFactory::fromGlobals();
     if ($router == null && $container->has('router') == false) {
         throw new Exception('Define router config');
     }
     if ($container->has('router') == false) {
         $container->set('router', $router);
     }
     $container->set('event_manager', DI\object('Zend\\EventManager\\EventManager'));
     $container->set('dispatcher', DI\object('GianArb\\Penny\\Dispatcher')->constructor($container->get('router')));
     $container->set('di', $container);
 }
Beispiel #3
0
 /**
  * Define an object or a value in the container.
  *
  * @param string $name Entry name
  * @param mixed $value Value, use definition helpers to define objects
  * @throws \Exception
  */
 public function set($name, $value)
 {
     if (!method_exists($this->container, 'set')) {
         throw new Exception('Container method not found');
     }
     return $this->container->set($name, $value);
 }