当前位置: 首页>>代码示例>>PHP>>正文


PHP DiInterface::getStrategy方法代码示例

本文整理汇总了PHP中Phalcon\DiInterface::getStrategy方法的典型用法代码示例。如果您正苦于以下问题:PHP DiInterface::getStrategy方法的具体用法?PHP DiInterface::getStrategy怎么用?PHP DiInterface::getStrategy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Phalcon\DiInterface的用法示例。


在下文中一共展示了DiInterface::getStrategy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _initialize

 /**
  * Initialize the metadata for certain table
  *
  * @param \Phalcon\Mvc\ModelInterface $model
  * @param string|null $key
  * @param string $table
  * @param string $schema
  * @throws Exception
  */
 protected function _initialize(ModelInterface $model, $key = null, $table, $schema)
 {
     if (is_string($table) === false && is_null($table) === false || is_string($schema) === false && is_null($schema) === false || is_string($key) === false && is_null($key) === false) {
         throw new Exception('Invalid parameter type.');
     }
     $strategy = null;
     $className = get_class($model);
     if (is_null($key) === false) {
         //Check for $key in local metadata db
         $metaData = $this->_metaData;
         if (isset($metaData[$key]) === false) {
             //The meta-data is read from the adapter always
             $prefixKey = 'meta-' . $key;
             $data = $this->read($prefixKey);
             if (is_null($data) === false) {
                 //Store the adapters metadata locally
                 if (is_array($metaData) === false) {
                     $metaData = array();
                 }
                 $metaData[$key] = $data;
                 $this->_metaData = $metaData;
             } else {
                 //Check if there is a method 'metaData' in the model to retrieve meta-data form it
                 if (method_exists($model, 'metaData') === true) {
                     $modelMetadata = $model->metaData();
                     if (is_array($modelMetadata) === false) {
                         throw new Exception('Invalid meta-data for model ' . $className);
                     }
                 } else {
                     //Get the meta-data extraction strategy
                     $strategy = $this->getStrategy();
                     //Get the meta-data
                     $modelMetadata = $strategy->getMetaData($model, $this->_dependencyInjector);
                 }
                 //Store the meta-data locally
                 $this->_metaData[$key] = $modelMetadata;
                 //Store the meta-data in the adapter
                 $this->write($prefixKey, $modelMetadata);
             }
         }
     }
     //Check for a column map, store in _columnMap in order and reversed order
     if (isset($GLOBALS['_PHALCON_ORM_COLUMN_RENAMING']) === false || $GLOBALS['_PHALCON_ORM_COLUMN_RENAMING'] === false) {
         return;
     }
     $keyName = strtolower($className);
     if (isset($this->_columnMap[$keyName]) === true) {
         return;
     }
     if (is_array($this->_columnMap) === false) {
         $this->_columnMap = array();
     }
     //Create the map key name
     $prefixKey = 'map-' . $keyName;
     //Check if the meta-data is already in the adapter
     $data = $this->read($prefixKey);
     if (is_null($data) === false) {
         $this->_columnMap[$keyName] = $data;
         return;
     }
     //Get the meta-data extraction strategy
     if (is_object($strategy) === false) {
         $strategy = $this->_dependencyInjector->getStrategy();
     }
     //Get the meta-data
     $modelColumnMap = $strategy->getColumnMaps($model, $this->_dependencyInjector);
     //Update the column map locally
     $this->_columnMap[$keyName] = $modelColumnMap;
     //Write the data to the adapter
     $this->write($prefixKey, $modelColumnMap);
 }
开发者ID:aisuhua,项目名称:phalcon-php,代码行数:80,代码来源:MetaData.php


注:本文中的Phalcon\DiInterface::getStrategy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。