private function configure(InputInterface $input) { preg_match_all('/(\\-\\-skip\\-[a-zA-Z0-9\\.\\-\\/=\\"\']+)/', (string) $input, $matches); $stringInput = new StringInput(implode(' ', $matches[0])); $stringInput->bind($this->getDefinition()); extract(Environment::getVars($stringInput)); $app = new Generic($app_path, $lib_path, $env, $user, 'console', $this->cacheConfig); $config = $app->getConfig(); // add helper sets if (isset($config['console']['helpers']) && is_array($config['console']['helpers'])) { $set_array = array(); foreach ($config['console']['helpers'] as $name => $helper) { $helper = new $helper(); $set_array[$name] = $helper->getHelper($app, $this); } $helperSet = new \Symfony\Component\Console\Helper\HelperSet($set_array); $this->setHelperSet($helperSet); } // add commands if (isset($config['console']['commands']) && is_array($config['console']['commands'])) { foreach ($config['console']['commands'] as $command) { $sets = array(); if (!is_string($command)) { if (!isset($command['class'])) { throw new \Exception('Commands with extra configuration needs a `class` parameter. No class parameter found.'); } $sets = isset($command['set']) ? $command['set'] : $sets; if (!is_array($sets)) { throw new \Exception('Commands with a `sets` parameter must be a hash array of paramerter => service, where parameter is the un-camelised key paramerter and service is the key identifier of the dependant service.'); } $command = $command['class']; } $command = new $command(); Utils::setParametersOn($command, $sets, $app); if ($command instanceof \Skip\ServiceContainerInterface) { $command->setContainer($app); } $this->add($command); } } $this->app = $app; }
/** * {@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); } }
public static function setConfigCache($hash, $config) { Generic::clearConfigCache(); return apc_store(Generic::CACHE_KEY, array($hash, $config)); }
public function testApplicationConfigCacheIsFaster() { if (!extension_loaded('apc') || !ini_get('apc.enable_cli')) { $this->markTestSkipped('The ' . __CLASS__ . ' requires apc extension with apc.enable_cli=1.'); } $libPath = dirname(dirname(dirname(dirname(dirname(__DIR__))))); $appPath = $libPath . "/tests/fixtures/app"; Generic::clearConfigCache(); $this->assertFalse(apc_exists(Generic::CACHE_KEY)); $stopwatch = new Stopwatch(); $stopwatch->start('noCache'); $app = new Generic($appPath, $libPath, '', '', ''); $noCache = $stopwatch->stop('noCache'); $app = null; $app = new Generic($appPath, $libPath, '', '', '', true); $app = null; $stopwatch->start('cache'); $app = new Generic($appPath, $libPath, '', '', '', true); $cache = $stopwatch->stop('cache'); $this->assertLessThan($noCache->getDuration(), $cache->getDuration()); $this->assertInstanceOf('Pimple', $app->getApp()); }