Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 protected function configure($appPath, $user, $env, $cache)
 {
     $libPath = Environment::getLibPath();
     $sapi = 'public';
     $rawConfig = Generic::configure($this, $appPath, $libPath, $env, $user, 'web', $cache);
     $sapiConfig = $rawConfig['web'];
     $hooks = null;
     // procedural configure after
     if (isset($sapiConfig['middleware'])) {
         $hooks = $sapiConfig['middleware'];
     }
     if (isset($hooks['setup_before'])) {
         try {
             $method = Utils::getClosure($hooks['setup_before']);
         } catch (\Exception $e) {
             throw new InvalidConfigurationException(sprintf('Your hooks configuration for \'setup_before\' is invalid. %s', $e->getMessage()));
         }
         $method($this);
     }
     // configure providers
     if (isset($sapiConfig['provider']) && is_array($sapiConfig['provider'])) {
         foreach ($sapiConfig['provider'] as $provider_name => $provider) {
             if (!isset($provider['types'])) {
                 throw new InvalidRouteConfigurationException(sprintf('Your provider configuration for %s is invalid. You need to provide a \'types\' key to specify the types for the provider', $provider_name));
             }
             if (!is_array($provider['types'])) {
                 $provider['types'] = array($provider['types']);
             }
             if (in_array('service', $provider['types'])) {
                 if (!isset($provider['class'])) {
                     throw new InvalidRouteConfigurationException(sprintf('Your provider configuration for %s is invalid. You need to provide a \'class\' key to specify the class for the provider', $provider_name));
                 }
                 $params = array();
                 if (isset($provider['params']) && is_array($provider['params']) && count($provider['params']) > 0) {
                     $params = $provider['params'];
                 }
                 $this->register(new $provider['class'](), $params);
             }
             if (in_array('controller', $provider['types'])) {
                 if (!isset($provider['class'])) {
                     throw new InvalidRouteConfigurationException(sprintf('Your provider configuration for %s is invalid. You need to provide a \'class\' key to specify the class for the provider', $provider_name));
                 }
                 if (!isset($provider['path'])) {
                     $provider['path'] = '';
                 }
                 $this->mount($provider['path'], new $provider['class'](), $params);
             }
         }
     }
     // configure Application middleware
     if (isset($hooks['webapp'])) {
         if (!is_array($hooks['webapp'])) {
             throw new InvalidConfigurationException('Your webapp hooks configuration is invalid. Please provide an array of functions to call.');
         }
         foreach ($hooks['webapp'] as $hook) {
             $this->{$hook}['type'](Utils::getClosure($hook['method']), isset($hook['priority']) ? intval($hook['priority']) : null);
         }
     }
     if (isset($sapiConfig['controllers']) && count($controllers = $sapiConfig['controllers']) > 0) {
         // configure Application controllers
         $this->registerControllers($controllers);
     }
     // catches all exception
     if (isset($sapiConfig['error_controllers'])) {
         $app = $this;
         $error_configure_callback = function ($object) use($app) {
             if ($object instanceof \Skip\ServiceContainerInterface) {
                 $object->setContainer($app);
             }
         };
         foreach ($sapiConfig['error_controllers'] as $error_controller) {
             try {
                 // create closure of controller class function
                 $method = Utils::getClosure($error_controller, $error_configure_callback);
                 $this->error($method);
             } catch (\Exception $e) {
                 print_r($e->getMessage());
                 throw new InvalidRouteConfigurationException(sprintf('Your defined error controller class is invalid. %s', $error_controller));
             }
         }
     }
     if (isset($hooks['setup_after'])) {
         try {
             $method = Utils::getClosure($hooks['setup_after']);
         } catch (\Exception $e) {
             throw new InvalidConfigurationException(sprintf('Your hooks configuration for \'setup_after\' is invalid. %s', $e->getMessage()));
         }
         $method($this);
     }
 }
 /**
  * test getLibPath Method
  */
 public function testGetLibPath()
 {
     $path = Environment::getLibPath();
     $this->assertEquals($this->rootPath, $path);
 }