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


PHP DiInterface::getAnnotations方法代码示例

本文整理汇总了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());
 }
开发者ID:riquedesimone,项目名称:biko,代码行数:91,代码来源:AnnotationsMetaDataInitializer.php


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