/**
  * {@inheritdoc}
  */
 public function configureDependencyInjection(DependencyInjectionContainer $dic, array $moduleConfig, array $globalConfig)
 {
     $dic->alias(TemplateEngine::class, TwigTemplateEngine::class);
     if (!isset($moduleConfig[self::CONFIG_DEBUG])) {
         $moduleConfig[self::CONFIG_DEBUG] = false;
     }
     $dic->setClassParameters(TwigTemplateEngine::class, ['debug' => $moduleConfig[self::CONFIG_DEBUG]]);
 }
 /**
  * {@inheritdoc}
  */
 public function configureDependencyInjection(DependencyInjectionContainer $dic, array $moduleConfig, array $globalConfig)
 {
     $dic->alias(ControllerViewProcessor::class, TemplateViewProcessor::class);
     if (!array_key_exists(self::CONFIG_TEMPLATE_ROOTS, $moduleConfig)) {
         $moduleConfig[self::CONFIG_TEMPLATE_ROOTS] = [];
     }
     $templateRoots = $moduleConfig[self::CONFIG_TEMPLATE_ROOTS];
     $dic->setClassParameters(TemplateViewProcessor::class, ['templateRoots' => $templateRoots]);
 }
 /**
  * {@inheritdoc}
  */
 public function configureDependencyInjection(DependencyInjectionContainer $dic, array $moduleConfig, array $globalConfig)
 {
     $dic->alias(Router::class, FastRouteRouter::class);
     if (!$this->isArrayInArray($moduleConfig, 'routes')) {
         throw new FastRouteConfigurationException('Missing or invalid configuration option \'' . $this->getModuleKey() . '.routes\' for ' . __CLASS__);
     }
     if (!$this->isArrayInArray($moduleConfig, 'errorHandlers')) {
         throw new FastRouteConfigurationException('Missing or invalid configuration option \'' . $this->getModuleKey() . '.errorHandlers\' for ' . __CLASS__);
     }
     $dic->setClassParameters(FastRouteConfiguration::class, ['routes' => $moduleConfig['routes'], 'errorHandlers' => $moduleConfig['errorHandlers']]);
 }
 /**
  * Configures the TemplateRenderingChain with the previously registered templating engines.
  *
  * @param DependencyInjectionContainer $dic
  * @param array                        $moduleConfig
  * @param array                        $globalConfig
  *
  * @throws ConfigurationException if no templating module was loaded.
  */
 public function configureDependencyInjection(DependencyInjectionContainer $dic, array $moduleConfig, array $globalConfig)
 {
     $engines = [];
     if (empty($moduleConfig[self::CONFIG_ENGINES])) {
         throw new ConfigurationException('The templating module itself was loaded, but there is no module ' . ' for the actual template engine present. Did you forget to load your templating module?');
     }
     //Create the instances of the template engine to be used with the TemplateRenderingChain
     foreach ($moduleConfig[self::CONFIG_ENGINES] as $engineClass) {
         $engines[] = $dic->make($engineClass);
     }
     $dic->setClassParameters(TemplateRenderingChain::class, ['templateEngines' => $engines]);
 }
Esempio n. 5
0
 /**
  * Load a module by class name.
  *
  * @param string                       $moduleClass The module class to load.
  * @param Module[]                     $modules     The list of already loaded modules.
  * @param array                        $moduleList  The complete module list.
  * @param DependencyInjectionContainer $dic         The dependency injection container to use for the module.
  *
  * @return void
  *
  * @throws ConfigurationException
  */
 private function loadModule($moduleClass, array &$modules, array $moduleList, DependencyInjectionContainer $dic)
 {
     /**
      * @var Module $module
      */
     $module = $dic->make($moduleClass);
     if (!$module instanceof Module) {
         throw new ConfigurationException(get_class($module) . ' was configured as a module, but doesn\'t implement ' . Module::class);
     }
     if (!\in_array($module, $modules)) {
         $dic->share($module);
         $this->loadRequiredModules($module, $modules, $moduleList, $dic);
         $modules[] = $module;
     }
 }
 public function test500()
 {
     //setup
     //act
     /**
      * @var RequestProcessor $requestProcessor
      */
     $requestProcessor = $this->dic->make(ControllerRequestProcessor::class);
     $request = new ServerRequest('GET', '/exception');
     $response = new Response();
     $response = $requestProcessor->execute($request, $response);
     //assert
     $this->assertEquals(500, $response->getStatusCode());
     $this->assertEquals('Error!', $response->getBody()->getContents());
 }
 /**
  * {@inheritdoc}
  */
 public function configureDependencyInjection(DependencyInjectionContainer $dic, array $moduleConfig, array $globalConfig)
 {
     $dic->alias(RequestProcessor::class, ControllerRequestProcessor::class);
     $dic->alias(PSR7ControllerResponseHandler::class, ControllerResponseProcessor::class);
     $dic->alias(StringControllerResponseHandler::class, ControllerResponseProcessor::class);
     $dic->alias(ArrayControllerResponseHandler::class, ControllerResponseProcessor::class);
     if (!isset($moduleConfig['filters'])) {
         $moduleConfig['filters'] = [];
     }
     $psr7Filters = [];
     if (!isset($moduleConfig['filters']['psr7'])) {
         $moduleConfig['filters']['psr7'] = [];
     }
     foreach ($moduleConfig['filters']['psr7'] as $filterClass) {
         $psr7Filters[] = new DICFilterFactory($dic, $filterClass);
     }
     $stringFilters = [];
     if (!isset($moduleConfig['filters']['string'])) {
         $moduleConfig['filters']['string'] = [];
     }
     foreach ($moduleConfig['filters']['string'] as $filterClass) {
         $stringFilters[] = new DICFilterFactory($dic, $filterClass);
     }
     $arrayFilters = [];
     if (!isset($moduleConfig['filters']['array'])) {
         $moduleConfig['filters']['array'] = [];
     }
     foreach ($moduleConfig['filters']['array'] as $filterClass) {
         $arrayFilters[] = new DICFilterFactory($dic, $filterClass);
     }
     $dic->setClassParameters(ControllerResponseProcessor::class, ['stringFilterFactories' => $stringFilters, 'arrayFilterFactories' => $arrayFilters, 'psr7FilterFactories' => $psr7Filters]);
     $dic->setClassParameters(DICRouteDispatcher::class, ['dic' => $dic]);
     $routingResponseFilters = $this->makeFilters($moduleConfig[self::CONFIG_FILTERS_ROUTING_RESPONSE], $dic);
     $dic->setClassParameters(RouteProcessor::class, ['routingResponseFilters' => $routingResponseFilters]);
     $requestFilters = $this->makeFilters($moduleConfig[self::CONFIG_FILTERS_REQUEST], $dic);
     $responseFilters = $this->makeFilters($moduleConfig[self::CONFIG_FILTERS_RESPONSE], $dic);
     $dic->setClassParameters(ControllerRequestProcessor::class, ['requestFilters' => $requestFilters, 'responseFilters' => $responseFilters]);
 }
 /**
  * {@inheritdoc}
  */
 public function configureDependencyInjection(DependencyInjectionContainer $dic, array $moduleConfig, array $globalConfig)
 {
     $dic->alias(TemplateEngine::class, SmartyTemplateEngine::class);
 }
 public function configureDependencyInjection(DependencyInjectionContainer $dic, array $moduleConfig, array $globalConfig)
 {
     $dic->alias(HTTPServerFactory::class, GuzzleHTTPServerFactory::class);
     $dic->alias(ServerRequestInterface::class, ServerRequest::class);
     $dic->alias(ResponseInterface::class, Response::class);
 }
 /**
  * Configures StandardInputProcessor and StandardOutputProcessor as IO handlers and wires up the input processor
  * to use standard PHP superglobals for input.
  *
  * @param DependencyInjectionContainer $dic
  * @param array                        $moduleConfig
  * @param array                        $globalConfig
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  */
 public function configureDependencyInjection(DependencyInjectionContainer $dic, array $moduleConfig, array $globalConfig)
 {
     $dic->alias(InputProcessor::class, StandardInputProcessor::class);
     $dic->alias(OutputProcessor::class, StandardOutputProcessor::class);
     $dic->setClassParameters(InputProcessor::class, ['server' => $_SERVER, 'get' => $_GET, 'post' => $_POST, 'cookie' => $_COOKIE]);
 }
 protected function make()
 {
     return $this->dic->make($this->class);
 }