protected function __construct(array $params) { $this->cache = SquirtUtil::validateParamClassWithDefault('cache', 'Doctrine\\Common\\Cache\\Cache', $params, function () { return new ArrayCache(); }); $this->cacheLifetimeSeconds = SquirtUtil::validateNumericParamWithDefault('cacheLifetimeSeconds', $params, 0); }
protected function __construct(array $params) { $this->squirtServiceConfigLoader = SquirtUtil::validateParamClassWithDefault('squirtServiceConfigLoader', 'Squirt\\ServiceBuilder\\SquirtServiceConfigLoader', $params, function () use($params) { /* * Pass through parameters as these two classes are tightly * coupled and can use each other's configurations */ return SquirtServiceConfigLoader::factory($params); }); /* * Load any file based configuration */ if (array_key_exists('fileName', $params)) { $serviceConfig = $this->squirtServiceConfigLoader->loadFile($params['fileName']); $this->serviceConfig = ServiceBuilderUtil::mergeConfig($this->serviceConfig, $serviceConfig); } /* * Load any literal configuration passed */ if (array_key_exists('config', $params)) { $serviceConfig = $this->squirtServiceConfigLoader->loadConfig($params['config']); $this->serviceConfig = ServiceBuilderUtil::mergeConfig($this->serviceConfig, $serviceConfig); } }
public function testValidateParamClassWithDefaultClosure() { /* * When one is concerned about excessive instantiation * one can pass a closure as the default that then returns * a default value itself */ $result = SquirtUtil::validateParamClassWithDefault('container', 'Squirt\\Common\\Container', array(), function () { return Container::factory(array('color' => 'blue')); }); $this->assertInstanceOf('Squirt\\Common\\Container', $result); }