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


PHP ClassMetadata::getTypeOfField方法代码示例

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


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

示例1: prepareSet

 /**
  * @param $entity
  * @return array
  */
 protected function prepareSet($entity)
 {
     $data = [];
     foreach ($this->metaData->getFieldNames() as $fieldName) {
         $columnName = $this->metaData->getColumnName($fieldName);
         $type = $this->metaData->getTypeOfField($fieldName);
         $fieldValue = $entity->{$fieldName};
         $type = \Doctrine\DBAL\Types\Type::getType($type);
         $value = $type->convertToDatabaseValue($fieldValue, $this->em->getConnection()->getDatabasePlatform());
         $data[$columnName] = $value;
     }
     return $data;
 }
开发者ID:lynx,项目名称:lynx,代码行数:17,代码来源:DBAL.php

示例2: convertMetadata

 /**
  * @param ClassMetadata $metadata
  * @return JavaScript\Metadata
  */
 private function convertMetadata(ClassMetadata $metadata)
 {
     $meta = new JavaScript\Metadata();
     $meta->originalName = $metadata->getName();
     $meta->namespace = str_replace('\\', '_', $metadata->getReflectionClass()->getNamespaceName());
     $meta->functionName = $metadata->getReflectionClass()->getShortName();
     $parent = $metadata->getReflectionClass()->getParentClass();
     $meta->superFunctionName = $parent ? $parent->getShortName() : 'DBEntity';
     // Convert fields.
     foreach ($metadata->getFieldNames() as $fieldName) {
         $field = new JavaScript\Field();
         $field->name = $fieldName;
         $field->methodName = ucfirst($fieldName);
         $field->type = $this->convertDoctrineType($metadata->getTypeOfField($fieldName));
         $field->isIdentifier = $metadata->isIdentifier($fieldName);
         $meta->fields[] = $field;
     }
     // Convert associations.
     foreach ($metadata->getAssociationNames() as $assocName) {
         $assoc = new JavaScript\Association();
         $assoc->name = $assocName;
         $assoc->methodName = ucfirst($assocName);
         $assoc->isCollection = $metadata->isCollectionValuedAssociation($assocName);
         $assoc->isSingle = $metadata->isSingleValuedAssociation($assocName);
         $assoc->singleName = Inflector::singularize($assoc->methodName);
         $assoc->invertedField = $metadata->getAssociationMappedByTargetField($assocName);
         $targetClass = new \ReflectionClass($metadata->getAssociationTargetClass($assocName));
         $assoc->singleType = $targetClass->getShortName();
         $assoc->type = $assoc->singleType . ($assoc->isCollection ? '[]' : '');
         $meta->associations[] = $assoc;
     }
     return $meta;
 }
开发者ID:CornyPhoenix,项目名称:JsEntitiesBundle,代码行数:37,代码来源:JsEntityConverter.php

示例3: createFieldMetadata

 /**
  * @param ClassMetadata $classMetadata
  * @param string        $fieldName
  *
  * @return FieldMetadata
  */
 public function createFieldMetadata(ClassMetadata $classMetadata, $fieldName)
 {
     $fieldMetadata = new FieldMetadata();
     $fieldMetadata->setName($fieldName);
     $fieldMetadata->setDataType($classMetadata->getTypeOfField($fieldName));
     return $fieldMetadata;
 }
开发者ID:Maksold,项目名称:platform,代码行数:13,代码来源:EntityMetadataFactory.php

示例4: _doUpdate

 /**
  * Perform UPDATE statement for an entity. This function has support for
  * optimistic locking if the entities ClassMetadata has versioning enabled.
  *
  * @param object $entity        The entity object being updated
  * @param string $tableName     The name of the table being updated
  * @param array $data           The array of data to set
  * @param array $where          The condition used to update
  * @return void
  */
 protected function _doUpdate($entity, $tableName, $data, $where)
 {
     // Note: $tableName and column names in $data are already quoted for SQL.
     $set = array();
     foreach ($data as $columnName => $value) {
         $set[] = $columnName . ' = ?';
     }
     if ($isVersioned = $this->_class->isVersioned) {
         $versionField = $this->_class->versionField;
         $versionFieldType = $this->_class->getTypeOfField($versionField);
         $where[$versionField] = Type::getType($versionFieldType)->convertToDatabaseValue($this->_class->reflFields[$versionField]->getValue($entity), $this->_platform);
         $versionFieldColumnName = $this->_class->getQuotedColumnName($versionField, $this->_platform);
         if ($versionFieldType == 'integer') {
             $set[] = $versionFieldColumnName . ' = ' . $versionFieldColumnName . ' + 1';
         } else {
             if ($versionFieldType == 'datetime') {
                 $set[] = $versionFieldColumnName . ' = CURRENT_TIMESTAMP';
             }
         }
     }
     $params = array_merge(array_values($data), array_values($where));
     $sql = 'UPDATE ' . $tableName . ' SET ' . implode(', ', $set) . ' WHERE ' . implode(' = ? AND ', array_keys($where)) . ' = ?';
     $result = $this->_conn->executeUpdate($sql, $params);
     if ($isVersioned && !$result) {
         throw \Doctrine\ORM\OptimisticLockException::lockFailed();
     }
 }
开发者ID:andreia,项目名称:doctrine,代码行数:37,代码来源:StandardEntityPersister.php

示例5: _getSelectConditionSQL

 /**
  * Gets the conditional SQL fragment used in the WHERE clause when selecting
  * entities in this persister.
  *
  * Subclasses are supposed to override this method if they intend to change
  * or alter the criteria by which entities are selected.
  *
  * @param array $criteria
  * @param AssociationMapping $assoc
  * @return string
  */
 protected function _getSelectConditionSQL(array $criteria, $assoc = null)
 {
     $conditionSql = '';
     foreach ($criteria as $field => $value) {
         $conditionSql .= $conditionSql ? ' AND ' : '';
         $placeholder = '?';
         if (isset($this->_class->columnNames[$field])) {
             $className = isset($this->_class->fieldMappings[$field]['inherited']) ? $this->_class->fieldMappings[$field]['inherited'] : $this->_class->name;
             $conditionSql .= $this->_getSQLTableAlias($className) . '.' . $this->_class->getQuotedColumnName($field, $this->_platform);
             if (isset($this->_class->fieldMappings[$field]['requireSQLConversion'])) {
                 $type = Type::getType($this->_class->getTypeOfField($field));
                 $placeholder = $type->convertToDatabaseValueSQL($placeholder, $this->_platform);
             }
         } else {
             if (isset($this->_class->associationMappings[$field])) {
                 if (!$this->_class->associationMappings[$field]['isOwningSide']) {
                     throw ORMException::invalidFindByInverseAssociation($this->_class->name, $field);
                 }
                 $className = isset($this->_class->associationMappings[$field]['inherited']) ? $this->_class->associationMappings[$field]['inherited'] : $this->_class->name;
                 $conditionSql .= $this->_getSQLTableAlias($className) . '.' . $this->_class->associationMappings[$field]['joinColumns'][0]['name'];
             } else {
                 if ($assoc !== null && strpos($field, " ") === false && strpos($field, "(") === false) {
                     // very careless developers could potentially open up this normally hidden api for userland attacks,
                     // therefore checking for spaces and function calls which are not allowed.
                     // found a join column condition, not really a "field"
                     $conditionSql .= $field;
                 } else {
                     throw ORMException::unrecognizedField($field);
                 }
             }
         }
         $conditionSql .= is_array($value) ? ' IN (?)' : ($value === null ? ' IS NULL' : ' = ' . $placeholder);
     }
     return $conditionSql;
 }
开发者ID:ncking,项目名称:doctrine2,代码行数:46,代码来源:BasicEntityPersister.php

示例6: _getSelectColumnSQL

 /**
  * {@inheritdoc}
  */
 protected function _getSelectColumnSQL($field, ClassMetadata $class, $alias = 'r')
 {
     $columnName = $class->columnNames[$field];
     $sql = $this->_getSQLTableAlias($class->name, $alias == 'r' ? '' : $alias) . '.' . $class->getQuotedColumnName($field, $this->_platform);
     $columnAlias = $this->getSQLColumnAlias($columnName);
     $this->_rsm->addFieldResult($alias, $columnAlias, $field, $class->name);
     if (isset($class->fieldMappings[$field]['requireSQLConversion'])) {
         $type = Type::getType($class->getTypeOfField($field));
         $sql = $type->convertToPHPValueSQL($sql, $this->_platform);
     }
     return $sql . ' AS ' . $columnAlias;
 }
开发者ID:pabloasc,项目名称:test_social,代码行数:15,代码来源:AbstractEntityInheritancePersister.php

示例7: hydrate

 /**
  * @param object $entity
  * @param array $queryResult
  * @return object
  * @throws \Doctrine\DBAL\DBALException
  * @throws \Doctrine\ORM\Mapping\MappingException
  */
 public function hydrate($entity, $queryResult)
 {
     $platform = $this->em->getConnection()->getDatabasePlatform();
     foreach ($queryResult as $columnName => $value) {
         $fieldName = $this->metaData->getFieldForColumn($columnName);
         $typeForField = $this->metaData->getTypeOfField($fieldName);
         if ($typeForField) {
             $type = Type::getType($typeForField);
             $entity->{$fieldName} = $type->convertToPHPValue($value, $platform);
         } else {
             throw new RuntimeException('Unknown type for field ' . $fieldName);
         }
     }
     return $entity;
 }
开发者ID:lynx,项目名称:lynx,代码行数:22,代码来源:Repository.php

示例8: load

 /**
  * Loads an entity by a list of field criteria.
  *
  * @param array $criteria The criteria by which to load the entity.
  * @param object $entity The entity to load the data into. If not specified,
  *                       a new entity is created.
  */
 public function load(array $criteria, $entity = null)
 {
     $stmt = $this->_conn->prepare($this->_getSelectSingleEntitySql($criteria));
     $stmt->execute(array_values($criteria));
     $data = array();
     foreach ($stmt->fetch(\PDO::FETCH_ASSOC) as $column => $value) {
         $fieldName = $this->_class->fieldNames[$column];
         $data[$fieldName] = Type::getType($this->_class->getTypeOfField($fieldName))->convertToPHPValue($value);
     }
     $stmt->closeCursor();
     if ($entity === null) {
         $entity = $this->_em->getUnitOfWork()->createEntity($this->_entityName, $data);
     } else {
         foreach ($data as $field => $value) {
             $this->_class->reflFields[$field]->setValue($entity, $value);
         }
         $id = array();
         if ($this->_class->isIdentifierComposite) {
             foreach ($this->_class->identifier as $fieldName) {
                 $id[] = $data[$fieldName];
             }
         } else {
             $id = array($data[$this->_class->getSingleIdentifierFieldName()]);
         }
         $this->_em->getUnitOfWork()->registerManaged($entity, $id, $data);
     }
     if (!$this->_em->getConfiguration()->getAllowPartialObjects()) {
         foreach ($this->_class->associationMappings as $field => $assoc) {
             if ($assoc->isOneToOne()) {
                 if ($assoc->isLazilyFetched()) {
                     // Inject proxy
                     $proxy = $this->_em->getProxyGenerator()->getAssociationProxy($entity, $assoc);
                     $this->_class->reflFields[$field]->setValue($entity, $proxy);
                 } else {
                     //TODO: Eager fetch?
                 }
             } else {
                 // Inject collection
                 $this->_class->reflFields[$field]->setValue($entity, new PersistentCollection($this->_em, $this->_em->getClassMetadata($assoc->targetEntityName)));
             }
         }
     }
     return $entity;
 }
开发者ID:jackbravo,项目名称:doctrine,代码行数:51,代码来源:StandardEntityPersister.php

示例9: _updateTable

 /**
  * Performs an UPDATE statement for an entity on a specific table.
  * The UPDATE can optionally be versioned, which requires the entity to have a version field.
  *
  * @param object $entity The entity object being updated.
  * @param string $tableName The name of the table to apply the UPDATE on.
  * @param array $updateData The map of columns to update (column => value).
  * @param boolean $versioned Whether the UPDATE should be versioned.
  */
 protected final function _updateTable($entity, $tableName, array $updateData, $versioned = false)
 {
     $set = $params = $types = array();
     foreach ($updateData as $columnName => $value) {
         if (isset($this->_class->fieldNames[$columnName])) {
             $set[] = $this->_class->getQuotedColumnName($this->_class->fieldNames[$columnName], $this->_platform) . ' = ?';
         } else {
             $set[] = $columnName . ' = ?';
         }
         $params[] = $value;
         $types[] = $this->_columnTypes[$columnName];
     }
     $where = array();
     $id = $this->_em->getUnitOfWork()->getEntityIdentifier($entity);
     foreach ($this->_class->identifier as $idField) {
         $where[] = $this->_class->getQuotedColumnName($idField, $this->_platform);
         $params[] = $id[$idField];
         $types[] = $this->_class->fieldMappings[$idField]['type'];
     }
     if ($versioned) {
         $versionField = $this->_class->versionField;
         $versionFieldType = $this->_class->getTypeOfField($versionField);
         $versionColumn = $this->_class->getQuotedColumnName($versionField, $this->_platform);
         if ($versionFieldType == Type::INTEGER) {
             $set[] = $versionColumn . ' = ' . $versionColumn . ' + 1';
         } else {
             if ($versionFieldType == Type::DATETIME) {
                 $set[] = $versionColumn . ' = CURRENT_TIMESTAMP';
             }
         }
         $where[] = $versionColumn;
         $params[] = $this->_class->reflFields[$versionField]->getValue($entity);
         $types[] = $this->_class->fieldMappings[$versionField]['type'];
     }
     $sql = "UPDATE {$tableName} SET " . implode(', ', $set) . ' WHERE ' . implode(' = ? AND ', $where) . ' = ?';
     $result = $this->_conn->executeUpdate($sql, $params, $types);
     if ($this->_class->isVersioned && !$result) {
         throw OptimisticLockException::lockFailed($entity);
     }
 }
开发者ID:jeffreiffers,项目名称:doctrine2,代码行数:49,代码来源:BasicEntityPersister.php

示例10: reverseTransformCombinedEntityId

 /**
  * @param string        $entityId
  * @param string[]      $idFields
  * @param ClassMetadata $metadata
  *
  * @return array
  *
  * @throws \UnexpectedValueException if the given entity id cannot be normalized
  */
 protected function reverseTransformCombinedEntityId($entityId, $idFields, ClassMetadata $metadata)
 {
     $fieldMap = array_flip($idFields);
     $normalized = [];
     foreach (explode(RestRequest::ARRAY_DELIMITER, $entityId) as $item) {
         $val = explode('=', $item);
         if (count($val) !== 2) {
             throw new \UnexpectedValueException(sprintf('Unexpected identifier value "%s" for composite primary key of the entity "%s".', $entityId, $metadata->getName()));
         }
         $key = $val[0];
         $val = $val[1];
         if (!isset($fieldMap[$key])) {
             throw new \UnexpectedValueException(sprintf('The entity identifier contains the key "%s" ' . 'which is not defined in composite primary key of the entity "%s".', $key, $metadata->getName()));
         }
         $dataType = $metadata->getTypeOfField($key);
         $normalized[$key] = $dataType !== DataType::STRING ? $this->valueNormalizer->normalizeValue($val, $dataType, [RequestType::REST]) : $val;
         unset($fieldMap[$key]);
     }
     if (!empty($fieldMap)) {
         throw new \UnexpectedValueException(sprintf('The entity identifier does not contain all keys ' . 'defined in composite primary key of the entity "%s".', $metadata->getName()));
     }
     return $normalized;
 }
开发者ID:Maksold,项目名称:platform,代码行数:32,代码来源:EntityIdTransformer.php

示例11: guessLabelField

 /**
  * @param ClassMetadata $metadata
  * @param string        $columnName
  *
  * @return string
  *
  * @throws \Exception
  */
 protected function guessLabelField($metadata, $columnName)
 {
     $labelField = '';
     if ($metadata->hasField('label')) {
         $labelField = 'label';
     } elseif ($metadata->hasField('name')) {
         $labelField = 'name';
     } else {
         //get first field with type "string"
         $isStringFieldPresent = false;
         foreach ($metadata->getFieldNames() as $fieldName) {
             if ($metadata->getTypeOfField($fieldName) === "string") {
                 $labelField = $fieldName;
                 $isStringFieldPresent = true;
                 break;
             }
         }
         if (!$isStringFieldPresent) {
             throw new \Exception("Could not find any field for using as label for 'choices' of '{$columnName}' column.");
         }
     }
     return $labelField;
 }
开发者ID:kstupak,项目名称:platform,代码行数:31,代码来源:ChoicesGuesser.php

示例12: determineFromColumns

 private function determineFromColumns(ClassMetadata $classMetadata)
 {
     $out = [];
     /** @var Column $column */
     foreach ($classMetadata->getFieldNames() as $fieldName) {
         $fieldMapping = [];
         try {
             $fieldMapping = $classMetadata->getFieldMapping($fieldName);
         } catch (MappingException $e) {
             $fieldMapping['type'] = 'undefined';
         }
         $columnName = $classMetadata->getColumnName($fieldName);
         $type = $classMetadata->getTypeOfField($fieldName);
         $isNullable = $classMetadata->isNullable($fieldName);
         if (strtolower($type) === 'enum') {
             $out[$columnName] = ['type' => IColumnStructure::ENUM];
             $enum = $fieldMapping['columnDefinition'];
             $options = str_getcsv(str_replace('enum(', '', substr($enum, 0, strlen($enum) - 1)), ',', "'");
             $out[$columnName]['values'] = [];
             foreach ($options as $option) {
                 $out[$columnName]['values'][] = $option;
             }
         } else {
             switch ($type) {
                 case Type::STRING:
                 case Type::TEXT:
                     $out[$columnName] = ['type' => IColumnStructure::TEXT];
                     break;
                 case Type::INTEGER:
                 case Type::FLOAT:
                 case Type::SMALLINT:
                 case Type::BIGINT:
                 case Type::DECIMAL:
                     $out[$columnName] = ['type' => IColumnStructure::NUMBER];
                     break;
                 case Type::DATETIME:
                 case Type::DATETIMETZ:
                 case Type::DATE:
                 case Type::TIME:
                     $out[$columnName] = ['type' => IColumnStructure::DATE];
                     break;
                 case Type::BOOLEAN:
                     $out[$columnName] = ['type' => IColumnStructure::BOOL];
                     break;
             }
         }
         if (isset($out[$columnName])) {
             $out[$columnName]['nullable'] = $isNullable;
         }
     }
     return $out;
 }
开发者ID:mesour,项目名称:sources,代码行数:52,代码来源:DoctrineSource.php

示例13: sanitizeValue

 /**
  * @param \Doctrine\ORM\Mapping\ClassMetadata $class
  * @param string $field
  * @param mixed $value
  */
 protected function sanitizeValue(ClassMetadata $class, $field, $value)
 {
     switch ($class->getTypeOfField($field)) {
         case 'integer':
             $value = (int) $value ?: NULL;
             break;
     }
     return $value;
 }
开发者ID:svobodni,项目名称:web,代码行数:14,代码来源:EntityMapper.php

示例14: _isValidField

 /**
  * Checks if $field type is valid
  * 
  * @param ClassMetadata $meta
  * @param string $field
  * @return boolean
  */
 protected function _isValidField(ClassMetadata $meta, $field)
 {
     return in_array($meta->getTypeOfField($field), $this->_validTypes);
 }
开发者ID:jgat2012,项目名称:hp_oms,代码行数:11,代码来源:TreeListener.php

示例15: getSelectConditionStatementSQL

    /**
     * Gets the SQL WHERE condition for matching a field with a given value.
     *
     * @param string      $field
     * @param mixed       $value
     * @param array|null  $assoc
     * @param string|null $comparison
     *
     * @return string
     */
    public function getSelectConditionStatementSQL($field, $value, $assoc = null, $comparison = null)
    {
        $placeholder  = '?';
        $condition    = $this->getSelectConditionStatementColumnSQL($field, $assoc);

        if (isset($this->class->fieldMappings[$field]['requireSQLConversion'])) {
            $placeholder = Type::getType($this->class->getTypeOfField($field))->convertToDatabaseValueSQL($placeholder, $this->platform);
        }

        if ($comparison !== null) {
            return $condition . ' ' . sprintf(self::$comparisonMap[$comparison], $placeholder);
        }

        if (is_array($value)) {
            return sprintf('%s IN (%s)' , $condition, $placeholder);
        }

        if ($value === null) {
            return sprintf('%s IS NULL' , $condition);
        }

        return sprintf('%s = %s' , $condition, $placeholder);
    }
开发者ID:nattaphat,项目名称:hgis,代码行数:33,代码来源:BasicEntityPersister.php


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