本文整理汇总了PHP中Doctrine\ORM\Mapping\ClassMetadata::hasAssociation方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata::hasAssociation方法的具体用法?PHP ClassMetadata::hasAssociation怎么用?PHP ClassMetadata::hasAssociation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Mapping\ClassMetadata
的用法示例。
在下文中一共展示了ClassMetadata::hasAssociation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getAssociationMapping
/** {@inheritdoc} */
public function getAssociationMapping($name)
{
if (!$this->classMetadata->hasAssociation($name)) {
throw new MetadataException("Association '{$name}' not found in class '{$this->getClass()}'.");
}
return $this->classMetadata->getAssociationMapping($name);
}
示例2: readFieldDefs
private function readFieldDefs(array $params)
{
foreach ($params as $key => $def) {
if ($this->metadata->hasField($key) || $this->metadata->hasAssociation($key)) {
$this->fieldDefs[$key] = $this->normalizeFieldDef($def);
} else {
throw new Exception('No such field in ' . $this->entityType . ': ' . $key);
}
}
}
示例3: updateTranslationMetadata
protected function updateTranslationMetadata(ClassMetadata $metadata)
{
if (!$metadata->hasAssociation('translatable')) {
$metadata->mapManyToOne(['fieldName' => 'translatable', 'inversedBy' => 'translations', 'fetch' => $this->translationFetchMode, 'joinColumns' => [['name' => 'translatable_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE']], 'targetEntity' => substr($metadata->name, 0, -strlen('Translation'))]);
$metadata->table['uniqueConstraints'][] = ['name' => 'unique_translation', 'columns' => ['translatable_id', 'locale']];
}
}
示例4: __call
/**
* Adds support for magic finders.
*
* @return array|object The found entity/entities.
* @throws BadMethodCallException If the method called is an invalid find* method
* or no find* method at all and therefore an invalid
* method call.
*/
public function __call($method, $arguments)
{
switch (true) {
case 0 === strpos($method, 'findBy'):
$by = substr($method, 6);
$method = 'findBy';
break;
case 0 === strpos($method, 'findOneBy'):
$by = substr($method, 9);
$method = 'findOneBy';
break;
default:
throw new \BadMethodCallException("Undefined method '{$method}'. The method name must start with " . "either findBy or findOneBy!");
}
if (empty($arguments)) {
throw ORMException::findByRequiresParameter($method . $by);
}
$fieldName = lcfirst(\Doctrine\Common\Util\Inflector::classify($by));
if ($this->_class->hasField($fieldName) || $this->_class->hasAssociation($fieldName)) {
switch (count($arguments)) {
case 1:
return $this->{$method}(array($fieldName => $arguments[0]));
case 2:
return $this->{$method}(array($fieldName => $arguments[0]), $arguments[1]);
case 3:
return $this->{$method}(array($fieldName => $arguments[0]), $arguments[1], $arguments[2]);
case 4:
return $this->{$method}(array($fieldName => $arguments[0]), $arguments[1], $arguments[2], $arguments[3]);
default:
// Do nothing
}
}
throw ORMException::invalidFindByCall($this->_entityName, $fieldName, $method . $by);
}
示例5: setFieldLimit
/**
* @param array $fieldConfig
* @param ClassMetadata $metadata
* @param string $fieldName
* @param int $limit
*/
protected function setFieldLimit(array &$fieldConfig, ClassMetadata $metadata, $fieldName, $limit)
{
if ($metadata->hasAssociation($fieldName)) {
if (!array_key_exists(ConfigUtil::MAX_RESULTS, $fieldConfig) && $metadata->isCollectionValuedAssociation($fieldName)) {
$fieldConfig[ConfigUtil::MAX_RESULTS] = $limit;
}
$this->setLimits($fieldConfig, $metadata->name, $limit);
}
}
示例6: mapTranslation
private function mapTranslation(ClassMetadata $classMetadata)
{
if (!$classMetadata->hasAssociation('translatable')) {
$classMetadata->mapManyToOne(['fieldName' => 'translatable', 'inversedBy' => 'translations', 'joinColumns' => [['name' => 'translatable_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE']], 'targetEntity' => substr($classMetadata->name, 0, -11)]);
}
$name = $classMetadata->getTableName() . '_unique_translation';
if (!$this->hasUniqueTranslationConstraint($classMetadata, $name)) {
$classMetadata->setPrimaryTable(['uniqueConstraints' => [['name' => $name, 'columns' => ['translatable_id', 'locale']]]]);
}
}
示例7: resolveMagicCall
/**
* Resolves a magic method call to the proper existent method at `EntityRepository`.
*
* @param string $method The method to call
* @param string $by The property name used as condition
* @param array $arguments The arguments to pass at method call
*
* @throws ORMException If the method called is invalid or the requested field/association does not exist
*
* @return mixed
*/
private function resolveMagicCall($method, $by, array $arguments)
{
if (!$arguments) {
throw ORMException::findByRequiresParameter($method . $by);
}
$fieldName = lcfirst(Inflector::classify($by));
if (!($this->_class->hasField($fieldName) || $this->_class->hasAssociation($fieldName))) {
throw ORMException::invalidMagicCall($this->_entityName, $fieldName, $method . $by);
}
return $this->{$method}([$fieldName => $arguments[0]], ...array_slice($arguments, 1));
}
示例8: getAssociationMapping
public static function getAssociationMapping(ClassMetadata $classMetadata, $name, $type = NULL)
{
if (!$classMetadata->hasAssociation($name)) {
return NULL;
}
$mapping = $classMetadata->getAssociationMapping($name);
$type = $type ? (array) $type : NULL;
if ($type === NULL || in_array($mapping['type'], $type, TRUE)) {
return $mapping;
}
return NULL;
}
示例9: mapTranslation
/**
* @param ClassMetadata $classMetadata
* @throws \Doctrine\ORM\Mapping\MappingException
*/
private function mapTranslation(ClassMetadata $classMetadata)
{
if (!$classMetadata->hasAssociation('translatable')) {
$classMetadata->mapManyToOne(array('fieldName' => 'translatable', 'inversedBy' => 'translations', 'fetch' => $this->translationFetchMode, 'joinColumns' => array(array('name' => 'translatable_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE', 'nullable' => false)), 'targetEntity' => $this->getClassName($classMetadata)));
}
if (!$classMetadata->hasField('locale')) {
$classMetadata->mapField(array('fieldName' => 'locale', 'type' => 'string', 'length' => 10));
}
$name = $classMetadata->getTableName() . '_unique_translation';
if (!$this->hasUniqueTranslationConstraint($classMetadata, $name)) {
$classMetadata->setPrimaryTable(array('uniqueConstraints' => array(array('name' => $name, 'columns' => array('translatable_id', 'locale')))));
}
}
示例10: 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);
}
}
}
}
示例11: 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;
}
示例12: __call
/**
* Adds support for magic finders.
*
* @return array|object The found entity/entities.
* @throws BadMethodCallException If the method called is an invalid find* method
* or no find* method at all and therefore an invalid
* method call.
*/
public function __call($method, $arguments)
{
if (substr($method, 0, 6) == 'findBy') {
$by = substr($method, 6, strlen($method));
$method = 'findBy';
} else {
if (substr($method, 0, 9) == 'findOneBy') {
$by = substr($method, 9, strlen($method));
$method = 'findOneBy';
} else {
throw new \BadMethodCallException("Undefined method '{$method}'. The method name must start with " . "either findBy or findOneBy!");
}
}
if (!isset($arguments[0])) {
// we dont even want to allow null at this point, because we cannot (yet) transform it into IS NULL.
throw ORMException::findByRequiresParameter($method . $by);
}
$fieldName = lcfirst(\Doctrine\Common\Util\Inflector::classify($by));
if ($this->_class->hasField($fieldName) || $this->_class->hasAssociation($fieldName)) {
return $this->{$method}(array($fieldName => $arguments[0]));
} else {
throw ORMException::invalidFindByCall($this->_entityName, $fieldName, $method . $by);
}
}
示例13: mapTranslation
/**
* Add mapping data to a translation entity
*
* @param ClassMetadata $mapping
* @return void
*/
private function mapTranslation(ClassMetadata $mapping)
{
$metadata = $this->getTranslatableMetadata($mapping->name);
// Map translatable relation
if (!$mapping->hasAssociation($metadata->translatable->name)) {
$targetMetadata = $this->getTranslatableMetadata($metadata->targetEntity);
$mapping->mapManyToOne(array('fieldName' => $metadata->translatable->name, 'targetEntity' => $metadata->targetEntity, 'inversedBy' => $targetMetadata->translations->name, 'joinColumns' => array(array('name' => 'translatable_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE', 'nullable' => false))));
}
// Map locale field
if (!$mapping->hasField($metadata->locale->name)) {
$mapping->mapField(array('fieldName' => $metadata->locale->name, 'type' => 'string'));
}
// Map unique index
$columns = array($mapping->getSingleAssociationJoinColumnName($metadata->translatable->name), $metadata->locale->name);
if (!$this->hasUniqueConstraint($mapping, $columns)) {
$constraints = isset($mapping->table['uniqueConstraints']) ? $mapping->table['uniqueConstraints'] : array();
$constraints[$mapping->getTableName() . '_uniq_trans'] = array('columns' => $columns);
$mapping->setPrimaryTable(array('uniqueConstraints' => $constraints));
}
}
示例14: setFieldCustomizationHandler
/**
* @param ConfigContext $context
* @param array $fieldConfig
* @param ClassMetadata $metadata
* @param string $fieldName
* @param string $rootEntityClass
* @param string $fieldPath
*/
protected function setFieldCustomizationHandler(ConfigContext $context, array &$fieldConfig, ClassMetadata $metadata, $fieldName, $rootEntityClass, $fieldPath)
{
if (isset($fieldConfig[ConfigUtil::FIELDS]) && is_array($fieldConfig[ConfigUtil::FIELDS]) && $metadata->hasAssociation($fieldName)) {
if (!isset($definition[ConfigUtil::POST_SERIALIZE])) {
$fieldConfig[ConfigUtil::POST_SERIALIZE] = $this->getCustomizationHandler($context, $rootEntityClass, $fieldPath, $metadata->getAssociationTargetClass($fieldName));
}
$this->processFields($context, $fieldConfig[ConfigUtil::FIELDS], $rootEntityClass, $metadata, $fieldPath);
}
}
示例15: isAssociation
/**
* Checks if the given field is a mapped association
*
* @param string $fieldName
*
* @return boolean
*/
public function isAssociation($fieldName)
{
return $this->metadata->hasAssociation($fieldName);
}