本文整理汇总了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);
}