/** * {@inheritdoc} */ public static function configure(\Pimple $app, $appPath, $libPath, $env = '', $user = '', $sapi = '', $cache = false) { $configCacheHash = $cache ? implode('.', array($appPath, $libPath, $env, $user, $sapi)) : ''; $config = $cache ? Generic::getConfigCache($configCacheHash) : false; if (!$config) { //@TODO: allow not just json to be loaded $configPath = realpath(sprintf('%s/config/user/%s.json', $appPath, $user)); if (!$configPath) { $configPath = realpath(sprintf('%s/config/env/%s.json', $appPath, $env)); if (!$configPath) { $configPath = realpath(sprintf('%s/config/app.json', $appPath, $sapi)); } } $config = array('core' => array('user' => $user, 'env' => $env, 'sapi' => $sapi, 'appPath' => $appPath, 'libPath' => $libPath, 'configPath' => $configPath)); if (file_exists($configPath)) { $loadedConfig = Config::load($configPath, $config['core']); $loadedConfig['core'] = array_merge($loadedConfig['core'], $config['core']); $config = $loadedConfig; } if ($cache) { Generic::setConfigCache($configCacheHash, $config); } else { Generic::clearConfigCache(); } } Config::configurePimple($app, $config); return $config; }
public function configure() { $configuration = $this->loader->load(); $config = new Config($this, $this->console); if (isset($configuration['providers'])) { foreach ($configuration['providers'] as $provider) { $config->configureProvider($provider); } } if (isset($configuration['settings'])) { $config->configureSettings($configuration['settings']); } if (isset($configuration['routes'])) { foreach ($configuration['routes'] as $routeName => $route) { $config->configureRoute($route, $routeName); } } if (isset($configuration['services'])) { foreach ($configuration['services'] as $serviceName => $service) { $config->configureService($serviceName, $service); } } if ($this->console != null && isset($configuration['console'])) { $consoleSettings = $configuration['console']; if (isset($consoleSettings['commands']) && is_array($consoleSettings['commands'])) { foreach ($consoleSettings['commands'] as $commandSetting) { $config->configureCommand($commandSetting); } } } }
public static function configurePimple(\Pimple $app, array $config) { $skip = array(); $skip['settings'] = isset($config['settings']) ? $config['settings'] : array(); $skip['core'] = $config['core']; if (!isset($skip['core']['debug'])) { $skip['core']['debug'] = false; } $app['debug'] = $skip['core']['debug']; // so lazy developers can do what they want #notElegant #butIEmpathise $skip['di'] = $app; // namespaced configuration $app['skip'] = $skip; // handy bits for the frame work to know about itself! if (isset($config['framework']) && is_array($config['framework'])) { $app['framework'] = $config['framework']; } // configure services if (isset($config['services']) && is_array($config['services'])) { Config::configureServices($app, $config['services']); } }
/** * test configureService with no deps */ public function testConfigureServiceWithNoDeps() { $serviceName = 'test.service'; $serviceSetting = array('class' => 'Skip\\Test\\Helper\\GenericTestClass'); $mockApplication = new Application(); $config = new Config($mockApplication); $config->configureService($serviceName, $serviceSetting); $service = $mockApplication[$serviceName]; }
public function testServiceSetParameter() { $pimple = new \Pimple(); Config::configureServices($pimple, array("test_service1" => array("class" => "Skip\\Tests\\Dummy\\TestModel", "set" => array("dummy_service" => "test_service2")))); // configure dependee service $dep_service = Phake::mock('Skip\\Tests\\Dummy\\TestModel'); $pimple['test_service2'] = $dep_service; // request service $pimple['test_service1']; Phake::verify($dep_service, Phake::times(1))->getData(); }