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