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);
 }
 /**
  * Create a new instance in a manner compatible
  * with the Squirt dependency injection
  * @param array $params
  */
 public static function factory(array $params = array())
 {
     $instance = new static();
     $namespace = SquirtUtil::validateStringParamWithDefault('namespace', $params, 'squirt');
     if (strlen($namespace) > 0) {
         $instance->setNamespace($namespace);
     }
     return $instance;
 }
예제 #3
0
 /**
  * Create a new instance in a manner compatible
  * with the Squirt dependency injection
  * @param array $params
  */
 public static function factory(array $params = array())
 {
     $dsn = SquirtUtil::validateStringParam('dsn', $params);
     $username = SquirtUtil::validateStringParamWithDefault('username', $params, '');
     $password = SquirtUtil::validateStringParamWithDefault('password', $params, '');
     $options = SquirtUtil::validateArrayParamWithDefault('options', $params, array());
     $instance = new static($dsn, $username, $password, $options);
     return $instance;
 }
예제 #4
0
 /**
  * Create a new instance in a manner compatible
  * with the Squirt dependency injection
  * @param array $params
  */
 public static function factory(array $params = array())
 {
     $collection = SquirtUtil::validateParamClass('collection', '\\MongoCollection', $params);
     $instance = new static($collection);
     $namespace = SquirtUtil::validateStringParamWithDefault('namespace', $params, 'squirt');
     if (strlen($namespace) > 0) {
         $instance->setNamespace($namespace);
     }
     return $instance;
 }
 /**
  * Create a new instance in a manner compatible
  * with the Squirt dependency injection
  * @param array $params
  */
 public static function factory(array $params = array())
 {
     /*
      * Create and configure our instance
      */
     $directory = SquirtUtil::validateStringParam('directory', $params);
     $extension = SquirtUtil::validateStringParamWithDefault('extension', $params, null);
     $instance = new static($directory, $extension);
     $namespace = SquirtUtil::validateStringParamWithDefault('namespace', $params, 'squirt');
     if (strlen($namespace) > 0) {
         $instance->setNamespace($namespace);
     }
     return $instance;
 }
예제 #6
0
 /**
  * Create a new instance in a manner compatible
  * with the Squirt dependency injection
  * @param array $params
  */
 public static function factory(array $params = array())
 {
     $instance = new static();
     /*
      * To make this work, we must have a memcache instance
      */
     $memcache = SquirtUtil::validateParamClass('memcache', '\\Memcache', $params);
     $instance->setMemcache($memcache);
     $namespace = SquirtUtil::validateStringParamWithDefault('namespace', $params, 'squirt');
     if (strlen($namespace) > 0) {
         $instance->setNamespace($namespace);
     }
     return $instance;
 }
 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);
     }
 }
예제 #8
0
 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);
 }