當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ClassMetadata::setFieldValue方法代碼示例

本文整理匯總了PHP中Doctrine\ORM\Mapping\ClassMetadata::setFieldValue方法的典型用法代碼示例。如果您正苦於以下問題:PHP ClassMetadata::setFieldValue方法的具體用法?PHP ClassMetadata::setFieldValue怎麽用?PHP ClassMetadata::setFieldValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Doctrine\ORM\Mapping\ClassMetadata的用法示例。


在下文中一共展示了ClassMetadata::setFieldValue方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: _assignDefaultVersionValue

 /**
  * Retrieves the default version value which was created
  * by the preceding INSERT statement and assigns it back in to the 
  * entities version field.
  *
  * @param Doctrine\ORM\Mapping\ClassMetadata $class
  * @param object $entity
  * @param mixed $id
  */
 protected function _assignDefaultVersionValue($class, $entity, $id)
 {
     $versionField = $this->_class->versionField;
     $identifier = $this->_class->getIdentifierColumnNames();
     $versionFieldColumnName = $this->_class->getColumnName($versionField);
     //FIXME: Order with composite keys might not be correct
     $sql = "SELECT " . $versionFieldColumnName . " FROM " . $class->getQuotedTableName($this->_platform) . " WHERE " . implode(' = ? AND ', $identifier) . " = ?";
     $value = $this->_conn->fetchColumn($sql, array_values((array) $id));
     $this->_class->setFieldValue($entity, $versionField, $value);
 }
開發者ID:jeffreiffers,項目名稱:doctrine2,代碼行數:19,代碼來源:BasicEntityPersister.php

示例2: getCollectionFromAssociation

 /**
  * @param string $association
  * @return Collection
  * @throws UnexpectedValueException
  */
 protected function getCollectionFromAssociation($association)
 {
     $collection = $this->metadata->getFieldValue($this->entity, $association);
     if ($collection === NULL) {
         $this->metadata->setFieldValue($this->entity, $association, $collection = new ArrayCollection());
     } elseif (!$collection instanceof Collection) {
         throw UnexpectedValueException::notACollection($this->entity, $association);
     }
     return $collection;
 }
開發者ID:librette,項目名稱:doctrine,代碼行數:15,代碼來源:WrappedEntity.php

示例3: clearProperties

 /**
  * @param ClassMetadata $metadata
  * @param object|array  $entity
  * @param array         $properties
  */
 protected function clearProperties(ClassMetadata $metadata, &$entity, array $properties)
 {
     if (is_array($entity)) {
         foreach ($properties as $property) {
             $entity[$property] = null;
         }
     } else {
         foreach ($properties as $property) {
             if ($metadata->hasField($property) || $metadata->hasAssociation($property)) {
                 $metadata->setFieldValue($entity, $property, null);
             }
         }
     }
 }
開發者ID:vend,項目名稱:doxport,代碼行數:19,代碼來源:QueryAction.php

示例4: getCollection

 /**
  * @param $object
  * @param $fieldName
  * @return ArrayCollection|mixed
  * @throws \NForms\Exceptions\MetadataException
  */
 protected function getCollection($object, $fieldName)
 {
     if ($this->isSingleValuedAssociation($fieldName)) {
         throw new MetadataException("Can't get collection from association toOne.");
     }
     $collection = $this->classMetadata->getFieldValue($object, $fieldName);
     if ($collection === NULL) {
         $collection = new ArrayCollection();
         $this->classMetadata->setFieldValue($object, $fieldName, $collection);
     }
     if (!$collection instanceof Collection) {
         throw new MetadataException('Expected Doctrine\\Common\\Collections\\Collection, given ' . (is_object($collection) ? get_class($collection) : gettype($collection)));
     }
     return $collection;
 }
開發者ID:mike227,項目名稱:n-forms,代碼行數:21,代碼來源:BaseClassMetadata.php

示例5: getRelation

 /**
  * @param ClassMetadata $meta
  * @param object $entity
  * @param string $field
  * @return bool|object
  */
 private function getRelation(ClassMetadata $meta, $entity, $field)
 {
     if (!$meta->hasAssociation($field) || !$meta->isSingleValuedAssociation($field)) {
         return FALSE;
     }
     // todo: allow access using property or method
     $relation = $meta->getFieldValue($entity, $field);
     if ($relation instanceof Collection) {
         return FALSE;
     }
     if ($relation === NULL) {
         $class = $meta->getAssociationTargetClass($field);
         $relationMeta = $this->mapper->getEntityManager()->getClassMetadata($class);
         $relation = $relationMeta->newInstance();
         $meta->setFieldValue($entity, $field, $relation);
     }
     return $relation;
 }
開發者ID:kuba1999,項目名稱:DoctrineForms,代碼行數:24,代碼來源:ToOne.php

示例6: assignDefaultVersionValue

 /**
  * Retrieves the default version value which was created
  * by the preceding INSERT statement and assigns it back in to the
  * entities version field.
  *
  * @param object $entity
  * @param mixed $id
  */
 protected function assignDefaultVersionValue($entity, $id)
 {
     $value = $this->fetchVersionValue($this->_class, $id);
     $this->_class->setFieldValue($entity, $this->_class->versionField, $value);
 }
開發者ID:jfkz,項目名稱:aquarel-cms,代碼行數:13,代碼來源:BasicEntityPersister.php

示例7: setProperty

 /**
  * Set entity property value according to meta.
  *
  * @param ClassMetadata $meta
  * @param Entity        $entity
  * @param string        $name
  * @param string        $value
  *
  * @return Entity
  */
 private function setProperty(ClassMetadata $meta, Entity &$entity, $name, $value)
 {
     if ($meta->hasField($name) && !$meta->isIdentifier($name)) {
         $meta->setFieldValue($entity, $name, $value);
     } elseif ($meta->hasAssociation($name)) {
         // We have a single value and there is only one column in association
         if (!is_array($value) && !is_object($value) && $meta->isAssociationWithSingleJoinColumn($name)) {
             $id = [$meta->associationMappings[$name]['joinColumns'][0]['referencedColumnName'] => $value];
             $di = Di::getInstance();
             $linkedEntity = $di->em->find($meta->getAssociationTargetClass($name), $id);
             if (is_null($linkedEntity)) {
                 throw new ClientException('Entity not found for nested entity ' . json_encode(['name' => $name]), ClientException::CODE_NOT_FOUND);
             } else {
                 $meta->setFieldValue($entity, $name, $linkedEntity);
             }
         } else {
             throw new ServerException('Unhandled association type for field ' . $name . ' on ' . $meta->name, ServerException::CODE_NOT_IMPLEMENTED);
         }
     }
 }
開發者ID:petitchevalroux,項目名稱:newswatcher-api,代碼行數:30,代碼來源:JsonApiController.php

示例8: save

 /**
  * {@inheritdoc}
  */
 public function save(ClassMetadata $meta, Component $component, $entity)
 {
     if (!$component instanceof BaseControl) {
         return FALSE;
     }
     if ($meta->hasField($name = $component->getOption(self::FIELD_NAME, $component->getName()))) {
         if (!$component->getOption(self::FIELD_NOT_SAVE, false)) {
             $this->accessor->setValue($entity, $name, $component->getValue());
         }
         return TRUE;
     }
     if (!$meta->hasAssociation($name)) {
         return FALSE;
     }
     if (!($identifier = $component->getValue())) {
         return FALSE;
     }
     $repository = $this->em->getRepository($this->relatedMetadata($entity, $name)->getName());
     if ($relation = $repository->find($identifier)) {
         $meta->setFieldValue($entity, $name, $relation);
     }
     return TRUE;
 }
開發者ID:kuba1999,項目名稱:DoctrineForms,代碼行數:26,代碼來源:TextControl.php

示例9: getCollection

 /**
  * @param ClassMetadata $meta
  * @param object $entity
  * @param string $field
  * @return Collection
  */
 private function getCollection(ClassMetadata $meta, $entity, $field)
 {
     if (!$meta->hasAssociation($field) || $meta->isSingleValuedAssociation($field)) {
         return FALSE;
     }
     $collection = $meta->getFieldValue($entity, $field);
     if ($collection === NULL) {
         $collection = new ArrayCollection();
         $meta->setFieldValue($entity, $field, $collection);
     }
     return $collection;
 }
開發者ID:kuba1999,項目名稱:DoctrineForms,代碼行數:18,代碼來源:ToMany.php


注:本文中的Doctrine\ORM\Mapping\ClassMetadata::setFieldValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。