示例#1
0
文件: Loader.php 项目: crapougnax/t41
 /**
  * Load a file into a Configuration Array
  * 
  * @param string $file
  * @param integer $realm
  * @param array $params
  * 
  * @return array|false Configuration Array or false if the file don't exists
  */
 public static function loadConfig($file, $realm = Config::REALM_CONFIGS, array $params = null)
 {
     // try to get cached version if configs caching is enabled
     if (Core::getEnvData('cache_configs') === true) {
         $ckey = self::getCacheKey($file, $realm);
         if (($cached = Core::cacheGet($ckey)) !== false) {
             Core::log(sprintf('[Config] Retrieved %s config file from cache', $file));
             return $cached;
         }
     }
     if (($filePath = self::findFile($file, $realm)) == null) {
         /* no matching file name in paths */
         Core::log(sprintf('[Config] Failed loading %s config file', $file), \Zend_Log::ERR);
         return false;
     }
     $type = substr($file, strrpos($file, '.') + 1);
     /* use existing adapter instance or create it */
     if (!isset(self::$_adapters[$type])) {
         $className = sprintf('\\t41\\Config\\Adapter\\%sAdapter', ucfirst(strtolower($type)));
         try {
             self::$_adapters[$type] = new $className($filePath, $params);
             if (!self::$_adapters[$type] instanceof Adapter\AbstractAdapter) {
                 throw new Exception("{$className} is not implementing AbstractAdapter.");
             }
         } catch (\Exception $e) {
             throw new Exception($e->getMessage());
         }
     } else {
         self::$_adapters[$type]->setPath($filePath);
     }
     $config = self::$_adapters[$type]->load();
     Core::log(sprintf('[Config] Successfully loaded %s config file', $file));
     /* if ckey is set, cache is activated but empty */
     if (isset($ckey)) {
         Core::cacheSet($config, $ckey, true, array('tags' => array('config')));
     }
     return $config;
 }
示例#2
0
文件: Core.php 项目: crapougnax/t41
 public static function cacheGet($key)
 {
     $cache = self::cacheGetAdapter();
     $cached = $cache->load($key);
     Core::log(sprintf('[Cache] Retrieved %s as %s', $key, gettype($cached)));
     if (is_array($cached)) {
         if (isset($cached['_class'])) {
             try {
                 \Zend_Loader::loadClass($cached['_class']);
             } catch (Exception $e) {
                 return null;
             }
             return unserialize($cached['content']);
         } else {
             return $cached;
         }
     } else {
         return $cached;
     }
 }
示例#3
0
 /**
  * Execute a search on given backend with given t41\ObjectModel\Collection parameters
  * and returns an array of results (either t41\ObjectModel\ObjectUri, t41\ObjectModel/DataObject or t41\ObjectModel\BaseObject instances)
  * 
  * @param t41\ObjectModel\Collection $co
  * @param t41\Backend\Adapter\AbstractAdapter $backend
  * @param array|boolean $returnCount 
  * @throws t41\Backend\Exception
  * @return array
  */
 public static function find(ObjectModel\Collection $co, Backend\Adapter\AbstractAdapter $backend = null, $returnCount = false, $subOp = null)
 {
     /*
      * Backend to use in order of preferences
      * 
      * 1. current method backend argument if not null
      * 2. object default backend
      * 3. general default backend
      */
     if (is_null($backend)) {
         $backend = ObjectModel::getObjectBackend($co->getDataObject()->getClass());
         if (is_null($backend)) {
             // get default backend
             $backend = self::getDefaultBackend();
         }
     }
     if (!$backend) {
         throw new Backend\Exception("NO_AVAILABLE_BACKEND");
     }
     Core::log(sprintf('[Backend] executing find() on %s collection', $co->getClass()));
     return $backend->find($co, $returnCount, $subOp);
 }
示例#4
0
 /**
  * Return current ObjecModel\Collection instance handled by current instance
  * instant instanciation is performed if $_value is null or $force is true
  * 
  *  @param boolean $force
  *  @return t41\ObjectModel\Collection
  */
 public function getValue($force = false)
 {
     if (is_null($this->_value) || $force === true) {
         /* set a new Collection based on instanceof parameter value */
         $this->_value = new ObjectModel\Collection($this->getParameter('instanceof'));
         $this->_value->setBoundaryBatch(-1);
         $this->_value->setParent($this->_parent);
         /* inject the condition that allows to find collection members */
         if ($this->getParameter('keyprop')) {
             $this->_value->having($this->getParameter('keyprop'))->equals($this->_parent);
         }
         /* inject any other defined condition */
         if ($this->getParameter('morekeyprop')) {
             foreach ($this->getParameter('morekeyprop') as $value) {
                 if (strstr(trim($value), ' ') !== false) {
                     // if value contains spaces, it's a pattern
                     $parts = explode(' ', $value);
                     if (count($parts) == 3) {
                         if ($parts[2] == 'novalue') {
                             $parts[2] = Condition::NO_VALUE;
                         }
                         if ($parts[2] == ObjectUri::IDENTIFIER) {
                             $parts[2] = $this->_parent->getUri();
                         }
                         if (substr($parts[2], 0, 1) == '%' && substr($parts[2], -1) == '%') {
                             $prop = substr($parts[2], 1, strlen($parts[2]) - 2);
                             if (($prop = $this->_parent->getProperty($prop)) !== false) {
                                 $parts[2] = $prop->getValue();
                             }
                         }
                         if (strstr($parts[2], ',') !== false) {
                             $parts[2] = explode(',', $parts[2]);
                         }
                         $this->_value->having($parts[0])->{$parts}[1]($parts[2]);
                     } else {
                         if ($parts[1] == 'novalue') {
                             $parts[1] = Condition::NO_VALUE;
                         }
                         if (substr($parts[1], 0, 1) == '%' && substr($parts[1], -1) == '%') {
                             $prop = substr($parts[1], 1, strlen($parts[1]) - 2);
                             if (($prop = $this->_parent->getProperty($prop)) !== false) {
                                 $parts[1] = $prop->getValue();
                             }
                         }
                         if (strstr($parts[1], ',') !== false) {
                             $parts[1] = explode(',', $parts[1]);
                         }
                         $this->_value->having($parts[0])->equals($parts[1]);
                     }
                 } else {
                     // default case, we expect the member to hold a property
                     // with the same name and value as the current object
                     if (($property = $this->_parent->getProperty($value)) === false) {
                         throw new Exception(sprintf("keyprop value '%s' doesn't match any property of class '%s'", $value, $this->_parent->getClass()));
                     }
                     $this->_value->having($value)->equals($property->getValue());
                 }
             }
         }
         // set sorting
         if ($this->getParameter('sorting')) {
             foreach ($this->getParameter('sorting') as $key => $val) {
                 if ($this->_value->getDataObject()->getRecursiveProperty($key) !== false) {
                     $this->_value->setSorting(array($key, $val));
                 } else {
                     Core::log(sprintf("Can't sort %s property with unknown property %s", $this->_id, $key), \Zend_Log::WARN);
                 }
             }
         }
         // DON'T POPULATE THERE, IT IS DONE IMPLICITELY IN Collection::getMembers()
         //$this->_value->debug();
     }
     return parent::getValue();
 }