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


PHP ClassMetadata::hasField方法代码示例

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


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

示例1: 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);
         }
     }
 }
开发者ID:breerly,项目名称:factory-girl-php,代码行数:10,代码来源:EntityDef.php

示例2: guessColumnFormatters

 /**
  * @param \Faker\Generator $generator
  * @return array
  */
 public function guessColumnFormatters(\Faker\Generator $generator)
 {
     $formatters = array();
     $nameGuesser = new \Faker\Guesser\Name($generator);
     $columnTypeGuesser = new ColumnTypeGuesser($generator);
     foreach ($this->class->getFieldNames() as $fieldName) {
         if ($this->class->isIdentifier($fieldName) || !$this->class->hasField($fieldName)) {
             continue;
         }
         $size = isset($this->class->fieldMappings[$fieldName]['length']) ? $this->class->fieldMappings[$fieldName]['length'] : null;
         if ($formatter = $nameGuesser->guessFormat($fieldName, $size)) {
             $formatters[$fieldName] = $formatter;
             continue;
         }
         if ($formatter = $columnTypeGuesser->guessFormat($fieldName, $this->class)) {
             $formatters[$fieldName] = $formatter;
             continue;
         }
     }
     foreach ($this->class->getAssociationNames() as $assocName) {
         if ($this->class->isCollectionValuedAssociation($assocName)) {
             continue;
         }
         $relatedClass = $this->class->getAssociationTargetClass($assocName);
         $unique = $optional = false;
         $mappings = $this->class->getAssociationMappings();
         foreach ($mappings as $mapping) {
             if ($mapping['targetEntity'] == $relatedClass) {
                 if ($mapping['type'] == ClassMetadata::ONE_TO_ONE) {
                     $unique = true;
                     $optional = isset($mapping['joinColumns'][0]['nullable']) ? $mapping['joinColumns'][0]['nullable'] : false;
                     break;
                 }
             }
         }
         $index = 0;
         $formatters[$assocName] = function ($inserted) use($relatedClass, &$index, $unique, $optional) {
             if (isset($inserted[$relatedClass])) {
                 if ($unique) {
                     $related = null;
                     if (isset($inserted[$relatedClass][$index]) || !$optional) {
                         $related = $inserted[$relatedClass][$index];
                     }
                     $index++;
                     return $related;
                 }
                 return $inserted[$relatedClass][mt_rand(0, count($inserted[$relatedClass]) - 1)];
             }
             return null;
         };
     }
     return $formatters;
 }
开发者ID:edwardricardo,项目名称:zenska,代码行数:57,代码来源:EntityPopulator.php

示例3: loadMeta

 /**
  * @param Builder\Metadata $meta
  * @param \Doctrine\ORM\Mapping\ClassMetadata $cm
  */
 private function loadMeta(Builder\Metadata $meta, \Doctrine\ORM\Mapping\ClassMetadata $cm)
 {
     $type = null;
     if ($cm->hasField($meta->name)) {
         $map = $cm->getFieldMapping($meta->name);
         $type = $map['type'];
         switch ($type) {
             case 'smallint':
             case 'bigint':
                 $type = 'integer';
                 break;
             default:
                 break;
         }
         if (!isset($map['nullable']) || $map['nullable'] === false && !isset($meta->conditions['required'])) {
             $meta->conditions['required'] = true;
         }
         if (isset($map['length']) && $map['length'] && !isset($meta->conditions['maxLenght'])) {
             $meta->conditions['maxLength'] = $map['length'];
         }
         if ($type === 'decimal' && isset($map['scale'])) {
             $type = 'float';
             $meta->custom['step'] = pow(10, -$map['scale']);
         }
     } elseif ($cm->hasAssociation($meta->name)) {
         $map = $cm->getAssociationMapping($meta->name);
         $type = $map['targetEntity'];
     }
     if (!$meta->type) {
         $meta->type = $type;
     }
 }
开发者ID:voda,项目名称:formbuilder,代码行数:36,代码来源:DoctrineAnnotationLoader.php

示例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);
 }
开发者ID:paulodacosta,项目名称:LearnFlash,代码行数:42,代码来源:EntityRepository.php

示例5: addFilterConstraint

 /**
  * Gets the SQL query part to add to a query.
  *
  * @param ClassMetaData $targetEntity
  * @param string $targetTableAlias
  *
  * @return string The constraint SQL if there is available, empty string otherwise.
  */
 public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias)
 {
     if ($targetEntity->hasField('deletedAt')) {
         $now = date('Y-m-d H:i:s');
         return "{$targetTableAlias}.deletedAt IS NULL OR {$targetTableAlias}.deletedAt > '{$now}'";
     }
     return '';
 }
开发者ID:uebb,项目名称:hateoas-bundle,代码行数:16,代码来源:SoftDeleteFilter.php

示例6: addFilterConstraint

 public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias)
 {
     if ($targetEntity->hasField('del_flg') && !in_array($targetEntity->getName(), $this->getExcludes())) {
         return $targetTableAlias . '.del_flg = 0';
     } else {
         return "";
     }
 }
开发者ID:hiroyasu55,项目名称:ec-cube,代码行数:8,代码来源:SoftDeleteFilter.php

示例7: getValueFieldFallback

 public static function getValueFieldFallback(ClassMetadata $classMetadata)
 {
     foreach (self::$valueFieldsFallback as $field) {
         if ($classMetadata->hasField($field)) {
             return $field;
         }
     }
     return NULL;
 }
开发者ID:librette,项目名称:doctrine-forms,代码行数:9,代码来源:ChoiceHelpers.php

示例8: 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));
 }
开发者ID:AdactiveSAS,项目名称:doctrine2,代码行数:22,代码来源:EntityRepository.php

示例9: createFieldsFormatters

 public function createFieldsFormatters($columnTypeGuesser, $generator)
 {
     $formatters = array();
     $nameGuesser = new Name($generator);
     foreach ($this->class->getFieldNames() as $fieldName) {
         //echo "pola standardowe: " . $fieldName . "\n";
         if ($this->class->isIdentifier($fieldName) || !$this->class->hasField($fieldName)) {
             //echo "pola standardowe kończę: " . $fieldName . "\n";
             continue;
         }
         //echo "pola standardowe dalej: " . $fieldName . "\n";
         if ($formatter = $nameGuesser->guessFormat($fieldName)) {
             $formatters[$fieldName] = $formatter;
             continue;
         }
         if ($formatter = $columnTypeGuesser->guessFormat($fieldName, $this->class)) {
             $formatters[$fieldName] = $formatter;
             continue;
         }
     }
     return $formatters;
 }
开发者ID:TMSolution,项目名称:GeneratorBundle,代码行数:22,代码来源:EntityPopulator.php

示例10: 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

示例11: 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

示例12: handle

 public function handle($name, array $options, ClassMetadata $classMetadata, Configuration $configuration)
 {
     if (!$classMetadata->hasField($name)) {
         return NULL;
     }
     $mapping = $classMetadata->getFieldMapping($name);
     $controlName = empty($options['control']) ? $this->getControlByType($mapping['type']) : $options['control'];
     $control = ControlFactory::create($controlName, ['\\Nette\\Forms\\Controls\\BaseControl'], ControlFactory::TEXT_INPUT);
     if (empty($options['caption'])) {
         $control->caption = $configuration->getLabelingStrategy()->getControlLabel($name, $classMetadata);
     } else {
         $control->caption = $options['caption'];
     }
     return new ControlBuilder($control);
 }
开发者ID:librette,项目名称:doctrine-forms,代码行数:15,代码来源:FieldHandler.php

示例13: mapTranslation

 /**
  * Add mapping data to a translation entity.
  *
  * @param ClassMetadata $metadata
  */
 private function mapTranslation(ClassMetadata $metadata)
 {
     // In the case A -> B -> TranslationInterface, B might not have mapping defined as it
     // is probably defined in A, so in that case, we just return.
     if (!isset($this->configs[$metadata->name])) {
         return;
     }
     $metadata->mapManyToOne(array('fieldName' => 'translatable', 'targetEntity' => $this->configs[$metadata->name]['model'], 'inversedBy' => 'translations', 'joinColumns' => array(array('name' => 'translatable_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE', 'nullable' => false))));
     if (!$metadata->hasField('locale')) {
         $metadata->mapField(array('fieldName' => 'locale', 'type' => 'string', 'nullable' => false));
     }
     // Map unique index.
     $columns = array($metadata->getSingleAssociationJoinColumnName('translatable'), 'locale');
     if (!$this->hasUniqueConstraint($metadata, $columns)) {
         $constraints = isset($metadata->table['uniqueConstraints']) ? $metadata->table['uniqueConstraints'] : array();
         $constraints[$metadata->getTableName() . '_uniq_trans'] = array('columns' => $columns);
         $metadata->setPrimaryTable(array('uniqueConstraints' => $constraints));
     }
 }
开发者ID:aleherse,项目名称:Sylius,代码行数:24,代码来源:ORMTranslatableListener.php

示例14: load

 /**
  * @param \Doctrine\ORM\Mapping\ClassMetadata $meta
  * @param \Nette\ComponentModel\Component $component
  * @param mixed $entity
  * @return boolean
  */
 public function load(ClassMetadata $meta, Component $component, $entity)
 {
     if (!$component instanceof BaseControl) {
         return false;
     }
     $name = $component->getOption(self::FIELD_NAME, $component->getName());
     if ($meta->hasField($name)) {
         $component->setValue($this->accessor->getValue($entity, $name));
         return true;
     }
     if (!$meta->hasAssociation($name)) {
         return false;
     }
     /** @var SelectBox|RadioList $component */
     if (($component instanceof SelectBox || $component instanceof RadioList || $component instanceof \Nette\Forms\Controls\MultiChoiceControl) && !count($component->getItems())) {
         if (!($nameKey = $component->getOption(self::ITEMS_TITLE, false))) {
             $path = $component->lookupPath('Nette\\Application\\UI\\Form');
             throw new \Kdyby\DoctrineForms\InvalidStateException('Either specify items for ' . $path . ' yourself, or set the option Kdyby\\DoctrineForms\\IComponentMapper::ITEMS_TITLE ' . 'to choose field that will be used as title');
         }
         $criteria = $component->getOption(self::ITEMS_FILTER, array());
         $orderBy = $component->getOption(self::ITEMS_ORDER, array());
         $related = $this->relatedMetadata($entity, $name);
         $items = $this->findPairs($related, $criteria, $orderBy, $nameKey);
         $component->setItems($items);
     }
     if ($meta->isCollectionValuedAssociation($name)) {
         $collection = $meta->getFieldValue($entity, $name);
         if ($collection instanceof PersistentCollection) {
             $values = array();
             foreach ($collection as $value) {
                 $values[] = $value->getId();
             }
             $component->setDefaultValue($values);
         }
     } elseif ($relation = $this->accessor->getValue($entity, $name)) {
         $UoW = $this->entityManager->getUnitOfWork();
         $component->setValue($UoW->getSingleIdentifierValue($relation));
     }
     return true;
 }
开发者ID:venne,项目名称:venne,代码行数:46,代码来源:TextControl.php

示例15: __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);
     }
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:32,代码来源:EntityRepository.php


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