本文整理匯總了PHP中Phalcon\DiInterface::getAnnotations方法的典型用法代碼示例。如果您正苦於以下問題:PHP DiInterface::getAnnotations方法的具體用法?PHP DiInterface::getAnnotations怎麽用?PHP DiInterface::getAnnotations使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Phalcon\DiInterface
的用法示例。
在下文中一共展示了DiInterface::getAnnotations方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getMetaData
/**
* Initializes models meta-data
*
* @param Phalcon\Mvc\ModelInterface $model
* @param Phalcon\DiInterface $di
* @return array
*/
public function getMetaData(ModelInterface $model, DiInterface $di)
{
$reflection = $di->getAnnotations()->get($model);
$properties = $reflection->getPropertiesAnnotations();
if (!$properties) {
throw new \Exception("There are no properties with annotations defined in the class");
}
$attributes = array();
$nullables = array();
$dataTypes = array();
$dataTypesBind = array();
$numericTypes = array();
$primaryKeys = array();
$nonPrimaryKeys = array();
$identity = false;
foreach ($properties as $name => $collection) {
if ($collection->has('Column')) {
$arguments = $collection->get('Column')->getArguments();
/**
* Get the column's name
*/
if (isset($arguments['column'])) {
$columnName = $arguments['column'];
} else {
$columnName = $name;
}
/**
* Check for the 'type' parameter in the 'Column' annotation
*/
if (isset($arguments['type'])) {
switch ($arguments['type']) {
case 'integer':
$dataTypes[$columnName] = Column::TYPE_INTEGER;
$dataTypesBind[$columnName] = Column::BIND_PARAM_INT;
$numericTypes[$columnName] = true;
break;
case 'decimal':
$dataTypes[$columnName] = Column::TYPE_DECIMAL;
$dataTypesBind[$columnName] = Column::BIND_SKIP;
$numericTypes[$columnName] = true;
break;
case 'string':
$dataTypes[$columnName] = Column::TYPE_VARCHAR;
$dataTypesBind[$columnName] = Column::BIND_PARAM_STR;
break;
default:
throw new Exception("Invalid type: " . $arguments['type']);
}
} else {
$dataTypes[$columnName] = Column::TYPE_VARCHAR;
$dataTypesBind[$columnName] = Column::BIND_PARAM_STR;
}
/**
* Check for the 'nullable' parameter in the 'Column' annotation
*/
if (!$collection->has('Identity')) {
if (isset($arguments['nullable'])) {
if (!$arguments['nullable']) {
$nullables[] = $columnName;
}
}
}
$attributes[] = $columnName;
/**
* Check if the attribute is marked as primary
*/
if ($collection->has('Primary')) {
$primaryKeys[] = $columnName;
} else {
$nonPrimaryKeys[] = $columnName;
}
/**
* Check if the attribute is marked as identity
*/
if ($collection->has('Identity')) {
if ($identity !== false) {
throw new \Exception("More than one field has been marked as identity");
}
$identity = $columnName;
}
}
}
return array(MetaData::MODELS_ATTRIBUTES => $attributes, MetaData::MODELS_PRIMARY_KEY => $primaryKeys, MetaData::MODELS_NON_PRIMARY_KEY => $nonPrimaryKeys, MetaData::MODELS_NOT_NULL => $nullables, MetaData::MODELS_DATA_TYPES => $dataTypes, MetaData::MODELS_DATA_TYPES_NUMERIC => $numericTypes, MetaData::MODELS_IDENTITY_COLUMN => $identity, MetaData::MODELS_DATA_TYPES_BIND => $dataTypesBind, MetaData::MODELS_AUTOMATIC_DEFAULT_INSERT => array(), MetaData::MODELS_AUTOMATIC_DEFAULT_UPDATE => array());
}