本文整理汇总了PHP中Doctrine\Common\Persistence\Mapping\ClassMetadata::hasAssociation方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata::hasAssociation方法的具体用法?PHP ClassMetadata::hasAssociation怎么用?PHP ClassMetadata::hasAssociation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Persistence\Mapping\ClassMetadata
的用法示例。
在下文中一共展示了ClassMetadata::hasAssociation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: applyFilter
/**
* @param Request $request
* @param FilterInterface $filter
* @param Criteria $criteria
* @param ClassMetadata $embedClassMeta
*
* @return null
*/
protected function applyFilter(Request $request, FilterInterface $filter, Criteria $criteria, ClassMetadata $embedClassMeta)
{
$properties = $filter->getRequestProperties($request);
if ($filter instanceof OrderFilter && !empty($properties)) {
$criteria->orderBy($properties);
return null;
}
if ($filter instanceof SearchFilter) {
foreach ($properties as $name => $propertie) {
if (in_array($name, $embedClassMeta->getIdentifier())) {
continue;
}
$expCriterial = Criteria::expr();
if ($embedClassMeta->hasAssociation($name)) {
$associationTargetClass = $embedClassMeta->getAssociationTargetClass($name);
$propertyResource = $this->resourceResolver->getResourceForEntity($associationTargetClass);
$propertyObj = $this->dataProviderChain->getItem($propertyResource, (int) $propertie['value'], true);
if ($propertyObj && $propertyResource instanceof ResourceInterface) {
$whereCriteria = $expCriterial->in($name, [$propertyObj]);
$criteria->where($whereCriteria);
}
} else {
if ($embedClassMeta->hasField($name)) {
$fieldMapping = $embedClassMeta->getFieldMapping($name);
$type = isset($fieldMapping['type']) ? $fieldMapping['type'] : null;
$value = isset($this->mappingFilterVar[$type]) ? filter_var($propertie['value'], $this->mappingFilterVar[$type]) : $propertie['value'];
$whereCriteria = isset($propertie['precision']) && $propertie['precision'] === 'exact' ? $expCriterial->eq($name, $value) : $expCriterial->contains($name, $propertie['value']);
$criteria->where($whereCriteria);
}
}
}
}
}
示例2: buildWhereClause
/**
* @param QueryBuilder $qb
* @param Criteria $criteria
*/
protected function buildWhereClause(Builder $qb, Criteria $criteria)
{
foreach ($criteria as $key => $value) {
if ($this->metadata->hasField($key) || $this->metadata->hasAssociation($key)) {
$qb->field($key)->equals($value);
}
}
}
示例3: buildWhereClause
/**
* @param QueryBuilder $qb
* @param Criteria $criteria
*/
protected function buildWhereClause(QueryBuilder $qb, Criteria $criteria)
{
$values = array();
foreach ($criteria as $key => $value) {
if ($this->metadata->hasField($key) || $this->metadata->hasAssociation($key)) {
$qb->andWhere('e.' . $key . ' = :' . $key);
$values[$key] = $value;
}
}
$qb->setParameters($values);
}
示例4: mapHierarchy
/**
* {@inheritDoc}
*/
public function mapHierarchy(ClassMetadata $meta)
{
if ($meta->isMappedSuperclass || !$meta->isRootEntity()) {
return;
}
$rc = $meta->getReflectionClass();
if ($rc->hasProperty('parent') && !$meta->hasAssociation('parent')) {
$meta->mapManyToOne(['targetEntity' => $meta->getName(), 'fieldName' => 'parent', 'inversedBy' => 'children', 'cascade' => ['persist']]);
}
if ($rc->hasProperty('children') && !$meta->hasAssociation('children')) {
$meta->mapOneToMany(['targetEntity' => $meta->getName(), 'fieldName' => 'children', 'mappedBy' => 'parent', 'cascade' => ['persist', 'remove'], 'fetch' => 'EXTRA_LAZY']);
}
}
示例5: hydrate
/**
* Hydrate $object with the provided $data.
*
* @param array $data
* @param object $object
* @throws \Exception
* @return object
*/
public function hydrate(array $data, $object)
{
$this->metadata = $this->objectManager->getClassMetadata(get_class($object));
foreach ($data as $field => &$value) {
if ($this->metadata->hasAssociation($field)) {
$target = $this->metadata->getAssociationTargetClass($field);
if ($this->metadata->isSingleValuedAssociation($field)) {
$value = $this->toOne($value, $target);
} elseif ($this->metadata->isCollectionValuedAssociation($field)) {
$value = $this->toMany($value, $target);
}
}
}
return $this->hydrator->hydrate($data, $object);
}
示例6: setPropertyType
protected function setPropertyType(DoctrineClassMetadata $doctrineMetadata, PropertyMetadata $propertyMetadata)
{
/** @var \Doctrine\ODM\PHPCR\Mapping\ClassMetadata $doctrineMetadata */
$propertyName = $propertyMetadata->name;
if ($doctrineMetadata->hasField($propertyName) && ($fieldType = $this->normalizeFieldType($doctrineMetadata->getTypeOfField($propertyName)))) {
$field = $doctrineMetadata->getFieldMapping($propertyName);
if (!empty($field['multivalue'])) {
$fieldType = 'array';
}
$propertyMetadata->setType($fieldType);
} elseif ($doctrineMetadata->hasAssociation($propertyName)) {
try {
$targetEntity = $doctrineMetadata->getAssociationTargetClass($propertyName);
} catch (\Exception $e) {
return;
}
if (null === $this->tryLoadingDoctrineMetadata($targetEntity)) {
return;
}
if (!$doctrineMetadata->isSingleValuedAssociation($propertyName)) {
$targetEntity = "ArrayCollection<{$targetEntity}>";
}
$propertyMetadata->setType($targetEntity);
}
}
示例7: hydrate
/**
* Hydrate $object with the provided $data.
*
* @param array $data
* @param object $object
* @throws \Exception
* @return object
*/
public function hydrate(array $data, $object)
{
$this->metadata = $this->objectManager->getClassMetadata(get_class($object));
$object = $this->tryConvertArrayToObject($data, $object);
foreach ($data as $field => &$value) {
$value = $this->hydrateValue($field, $value);
if ($value === null) {
continue;
}
// @todo DateTime (and other types) conversion should be handled by doctrine itself in future
if (in_array($this->metadata->getTypeOfField($field), array('datetime', 'time', 'date'))) {
if (is_int($value)) {
$dt = new DateTime();
$dt->setTimestamp($value);
$value = $dt;
} elseif (is_string($value)) {
$value = new DateTime($value);
}
}
if ($this->metadata->hasAssociation($field)) {
$target = $this->metadata->getAssociationTargetClass($field);
if ($this->metadata->isSingleValuedAssociation($field)) {
$value = $this->toOne($value, $target);
} elseif ($this->metadata->isCollectionValuedAssociation($field)) {
$value = $this->toMany($value, $target);
// Automatically merge collections using helper utility
$propertyRefl = $this->metadata->getReflectionClass()->getProperty($field);
$propertyRefl->setAccessible(true);
$previousValue = $propertyRefl->getValue($object);
$value = CollectionUtils::intersectUnion($previousValue, $value);
}
}
}
return $this->hydrator->hydrate($data, $object);
}
示例8: getTransformerInfo
/**
* {@inheritdoc}
*/
public function getTransformerInfo(ColumnInfoInterface $columnInfo, ClassMetadata $metadata)
{
if (!$columnInfo->getLocale() && !count($columnInfo->getSuffixes()) || !$metadata->hasAssociation('translations')) {
return;
}
return array($this->transformer, array());
}
示例9: getTransformerInfo
/**
* {@inheritdoc}
*/
public function getTransformerInfo(ColumnInfoInterface $columnInfo, ClassMetadata $metadata)
{
$mapping = $this->getMapping();
if (!$metadata->hasAssociation('translations') || !isset($mapping[$columnInfo->getName()])) {
return null;
}
return array($this->transformer, array('propertyPath' => $mapping[$columnInfo->getName()]));
}
示例10: mapTranslation
/**
* {@inheritDoc}
*/
public function mapTranslation(ClassMetadata $meta, $translatableClassName)
{
$rc = $meta->getReflectionClass();
if (!$rc->hasProperty('object') || $meta->hasAssociation('object') || !$rc->isSubclassOf($this->personalTranslation)) {
return;
}
$namingStrategy = $this->getObjectManager()->getConfiguration()->getNamingStrategy();
$meta->mapManyToOne(['targetEntity' => $translatableClassName, 'fieldName' => 'object', 'inversedBy' => 'translations', 'isOwningSide' => true, 'joinColumns' => [['name' => $namingStrategy->joinColumnName('object'), 'referencedColumnName' => $namingStrategy->referenceColumnName(), 'onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']]]);
}
示例11: testLoadClassMetadata
public function testLoadClassMetadata()
{
$this->loadClassMetadataEvent->getClassMetadata()->willReturn($this->classMetadata->reveal());
$this->classMetadata->getReflectionClass()->willReturn($this->refl->reveal());
$this->refl->implementsInterface('Sulu\\Component\\Persistence\\Model\\UserBlameInterface')->willReturn(true);
$this->classMetadata->hasAssociation('creator')->shouldBeCalled();
$this->classMetadata->hasAssociation('changer')->shouldBeCalled();
$this->classMetadata->mapManyToOne(Argument::any())->shouldBeCalled();
$this->subscriber->loadClassMetadata($this->loadClassMetadataEvent->reveal());
}
示例12: addStrategy
/**
* {@inheritDoc}
* @throws InvalidArgumentException If a strategy added to a collection does not extend AbstractCollectionStrategy
*/
public function addStrategy($name, StrategyInterface $strategy)
{
if ($this->metadata->hasAssociation($name)) {
if (!$strategy instanceof Strategy\AbstractCollectionStrategy) {
throw new InvalidArgumentException(sprintf('Strategies used for collections valued associations must inherit from ' . 'Strategy\\AbstractCollectionStrategy, %s given', get_class($strategy)));
}
$strategy->setCollectionName($name)->setClassMetadata($this->metadata);
}
return parent::addStrategy($name, $strategy);
}
示例13: validateExtendedMetadata
/**
* {@inheritDoc}
*/
protected function validateExtendedMetadata(ClassMetadata $baseClassMetadata, ClassMetadataInterface $extendedClassMetadata)
{
if ($extendedClassMetadata->hasTranslatableProperties()) {
if (!isset($extendedClassMetadata->localeProperty)) {
throw new Exception\MappingException('Entity \'' . $baseClassMetadata->name . '\' has translatable properties so it must have property marked with @Translatable\\Language annotation');
}
$translatableProperties = $extendedClassMetadata->getTranslatableProperties();
foreach ($translatableProperties as $translation => $properties) {
if (!$baseClassMetadata->hasAssociation($translation) || !$baseClassMetadata->isCollectionValuedAssociation($translation)) {
throw new Exception\MappingException('Field \'' . $translation . '\' in entity \'' . $baseClassMetadata->name . '\' has to be a OneToMany association');
}
}
}
if (isset($extendedClassMetadata->localeProperty)) {
if ($extendedClassMetadata->hasTranslatableProperties() && ($baseClassMetadata->hasField($extendedClassMetadata->localeProperty) || $baseClassMetadata->hasAssociation($extendedClassMetadata->localeProperty))) {
throw new Exception\MappingException('Entity \'' . $baseClassMetadata->name . '\' seems to be a translatable entity so its \'' . $extendedClassMetadata->localeProperty . '\' field must not be persistent');
} else {
if (!$extendedClassMetadata->hasTranslatableProperties() && !$baseClassMetadata->hasField($extendedClassMetadata->localeProperty) && !$baseClassMetadata->hasAssociation($extendedClassMetadata->localeProperty)) {
throw new Exception\MappingException('Entity \'' . $baseClassMetadata->name . '\' seems to be a translation entity so its \'' . $extendedClassMetadata->localeProperty . '\' field must be persistent');
}
}
}
}
示例14: __construct
public function __construct(ObjectManager $om, ClassMetadata $classMetadata)
{
$ids = $classMetadata->getIdentifierFieldNames();
$idType = $classMetadata->getTypeOfField(current($ids));
$this->om = $om;
$this->classMetadata = $classMetadata;
$this->singleId = 1 === count($ids);
$this->intId = $this->singleId && in_array($idType, array('integer', 'smallint', 'bigint'));
$this->idField = current($ids);
// single field association are resolved, since the schema column could be an int
if ($this->singleId && $classMetadata->hasAssociation($this->idField)) {
$this->associationIdReader = new self($om, $om->getClassMetadata($classMetadata->getAssociationTargetClass($this->idField)));
$this->singleId = $this->associationIdReader->isSingleId();
$this->intId = $this->associationIdReader->isIntId();
}
}
示例15: add
/**
* Adds an object to a collection.
*
* @param string $field
* @param array $args
*
* @return void
*
* @throws \BadMethodCallException
* @throws \InvalidArgumentException
*/
private function add($field, $args)
{
$this->initializeDoctrine();
if ($this->cm->hasAssociation($field) && $this->cm->isCollectionValuedAssociation($field)) {
$targetClass = $this->cm->getAssociationTargetClass($field);
if (!$args[0] instanceof $targetClass) {
throw new \InvalidArgumentException("Expected persistent object of type '" . $targetClass . "'");
}
if (!$this->{$field} instanceof Collection) {
$this->{$field} = new ArrayCollection($this->{$field} ?: []);
}
$this->{$field}->add($args[0]);
$this->completeOwningSide($field, $targetClass, $args[0]);
} else {
throw new \BadMethodCallException("There is no method add" . $field . "() on " . $this->cm->getName());
}
}