本文整理汇总了PHP中Doctrine\Common\Persistence\Mapping\ClassMetadata::hasField方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata::hasField方法的具体用法?PHP ClassMetadata::hasField怎么用?PHP ClassMetadata::hasField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Persistence\Mapping\ClassMetadata
的用法示例。
在下文中一共展示了ClassMetadata::hasField方法的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: guessColumnFormatters
public function guessColumnFormatters(\Faker\Generator $generator)
{
$formatters = array();
$class = $this->class;
$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;
}
if ($formatter = $nameGuesser->guessFormat($fieldName)) {
$formatters[$fieldName] = $formatter;
continue;
}
if ($formatter = $columnTypeGuesser->guessFormat($fieldName, $this->class)) {
$formatters[$fieldName] = $formatter;
continue;
}
}
foreach ($this->class->getAssociationNames() as $assocName) {
if (!$this->class->isIdentifier($assocName) || !$this->class->isCollectionValuedAssociation($assocName)) {
continue;
}
$relatedClass = $this->class->getAssociationTargetClass($assocName);
$formatters[$assocName] = function ($inserted) use($relatedClass) {
return isset($inserted[$relatedClass]) ? $inserted[$relatedClass][mt_rand(0, count($inserted[$relatedClass]) - 1)] : null;
};
}
return $formatters;
}
示例3: 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);
}
}
}
示例4: mapStringUser
private function mapStringUser(ClassMetadata $classMetadata)
{
if (!$classMetadata->hasField('createdBy')) {
$classMetadata->mapField(['fieldName' => 'createdBy', 'type' => 'string', 'nullable' => true]);
}
if (!$classMetadata->hasField('updatedBy')) {
$classMetadata->mapField(['fieldName' => 'updatedBy', 'type' => 'string', 'nullable' => true]);
}
}
示例5: 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);
}
示例6: getTransformerInfo
/**
* {@inheritdoc}
*/
public function getTransformerInfo(ColumnInfoInterface $columnInfo, ClassMetadata $metadata)
{
if (!$metadata->hasField($columnInfo->getPropertyPath())) {
return;
}
return [$this->transformer, []];
}
示例7: readExtendedMetadata
public function readExtendedMetadata(ClassMetadata $meta, array &$config)
{
// load our available annotations
require_once __DIR__ . '/../Annotations.php';
$reader = new AnnotationReader();
// set annotation namespace and alias
//$reader->setAnnotationNamespaceAlias('Gedmo\Mapping\Mock\Extension\Encoder\Mapping\\', 'ext');
$class = $meta->getReflectionClass();
// check only property annotations
foreach ($class->getProperties() as $property) {
// skip inherited properties
if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
continue;
}
// now lets check if property has our annotation
if ($encode = $reader->getPropertyAnnotation($property, 'Gedmo\\Mapping\\Mock\\Extension\\Encoder\\Mapping\\Encode')) {
$field = $property->getName();
// check if field is mapped
if (!$meta->hasField($field)) {
throw new \Exception("Field is not mapped as object property");
}
// allow encoding only strings
if (!in_array($encode->type, array('sha1', 'md5'))) {
throw new \Exception("Invalid encoding type supplied");
}
// validate encoding type
$mapping = $meta->getFieldMapping($field);
if ($mapping['type'] != 'string') {
throw new \Exception("Only strings can be encoded");
}
// store the metadata
$config['encode'][$field] = array('type' => $encode->type, 'secret' => $encode->secret);
}
}
}
示例8: readExtendedMetadata
/**
* {@inheritDoc}
*/
public function readExtendedMetadata(ClassMetadata $meta, array &$config)
{
$class = $meta->getReflectionClass();
// property annotations
foreach ($class->getProperties() as $property) {
if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
continue;
}
if ($timestampable = $this->reader->getPropertyAnnotation($property, self::TIMESTAMPABLE)) {
$field = $property->getName();
if (!$meta->hasField($field)) {
throw new InvalidMappingException("Unable to find timestampable [{$field}] as mapped property in entity - {$meta->name}");
}
if (!$this->isValidField($meta, $field)) {
throw new InvalidMappingException("Field - [{$field}] type is not valid and must be 'date', 'datetime' or 'time' in class - {$meta->name}");
}
if (!in_array($timestampable->on, array('update', 'create', 'change'))) {
throw new InvalidMappingException("Field - [{$field}] trigger 'on' is not one of [update, create, change] in class - {$meta->name}");
}
if ($timestampable->on == 'change') {
if (!isset($timestampable->field) || !isset($timestampable->value)) {
throw new InvalidMappingException("Missing parameters on property - {$field}, field and value must be set on [change] trigger in class - {$meta->name}");
}
$field = array('field' => $field, 'trackedField' => $timestampable->field, 'value' => $timestampable->value);
}
// properties are unique and mapper checks that, no risk here
$config[$timestampable->on][] = $field;
}
}
}
示例9: readExtendedMetadata
/**
* {@inheritDoc}
*/
public function readExtendedMetadata(ClassMetadata $meta, array &$config)
{
$class = $meta->getReflectionClass();
// property annotations
foreach ($class->getProperties() as $property) {
if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
continue;
}
// position
if ($position = $this->reader->getPropertyAnnotation($property, self::POSITION)) {
$field = $property->getName();
if (!$meta->hasField($field)) {
throw new InvalidMappingException("Unable to find 'position' - [{$field}] as mapped property in entity - {$meta->name}");
}
if (!$this->isValidField($meta, $field)) {
throw new InvalidMappingException("Sortable position field - [{$field}] type is not valid and must be 'integer' in class - {$meta->name}");
}
$config['position'] = $field;
}
// group
if ($group = $this->reader->getPropertyAnnotation($property, self::GROUP)) {
$field = $property->getName();
if (!$meta->hasField($field) && !$meta->hasAssociation($field)) {
throw new InvalidMappingException("Unable to find 'group' - [{$field}] as mapped property in entity - {$meta->name}");
}
if (!isset($config['groups'])) {
$config['groups'] = array();
}
$config['groups'][] = $field;
}
}
}
示例10: 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);
}
}
示例11: readExtendedMetadata
/**
* {@inheritDoc}
*/
public function readExtendedMetadata(ClassMetadata $meta, array &$config)
{
$class = $meta->getReflectionClass();
// property annotations
$config['fields'] = array();
$config['fields_delete'] = array();
foreach ($class->getProperties() as $property) {
if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
continue;
}
$field = null;
if ($file = $this->reader->getPropertyAnnotation($property, self::FILE)) {
$field['name'] = $property->getName();
$field['dir'] = CMSCore::init()->getUploadsDir() . '/' . $file->dir;
if (!$meta->hasField($field['name'])) {
throw new InvalidMappingException("Unable to find timestampable [{$field}] as mapped property in entity - {$meta->name}");
}
}
// if ($fileDelete = $this->reader->getPropertyAnnotation($property, self::FILE_DELETE)) {
//
// $config['fields_delete'][] = $property->getName();
//
// }
if ($field) {
$config['fields'][] = $field;
}
}
}
示例12: getTransformerInfo
/**
* {@inheritdoc}
*/
public function getTransformerInfo(ColumnInfoInterface $columnInfo, ClassMetadata $metadata)
{
if (!$metadata->hasField($columnInfo->getPropertyPath()) || $this->type != $metadata->getTypeOfField($columnInfo->getPropertyPath())) {
return;
}
return array($this->transformer, array());
}
示例13: readExtendedMetadata
/**
* {@inheritDoc}
*/
public function readExtendedMetadata(ClassMetadata $meta, array &$config)
{
$class = $meta->getReflectionClass();
// property annotations
foreach ($class->getProperties() as $property) {
if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
continue;
}
// slug property
if ($slug = $this->reader->getPropertyAnnotation($property, self::SLUG)) {
$field = $property->getName();
if (!$meta->hasField($field)) {
throw new InvalidMappingException("Unable to find slug [{$field}] as mapped property in entity - {$meta->name}");
}
if (!$this->isValidField($meta, $field)) {
throw new InvalidMappingException("Cannot use field - [{$field}] for slug storage, type is not valid and must be 'string' or 'text' in class - {$meta->name}");
}
// process slug handlers
$handlers = array();
if (is_array($slug->handlers) && $slug->handlers) {
foreach ($slug->handlers as $handler) {
if (!$handler instanceof SlugHandler) {
throw new InvalidMappingException("SlugHandler: {$handler} should be instance of SlugHandler annotation in entity - {$meta->name}");
}
if (!strlen($handler->class)) {
throw new InvalidMappingException("SlugHandler class: {$handler->class} should be a valid class name in entity - {$meta->name}");
}
$class = $handler->class;
$handlers[$class] = array();
foreach ((array) $handler->options as $option) {
if (!$option instanceof SlugHandlerOption) {
throw new InvalidMappingException("SlugHandlerOption: {$option} should be instance of SlugHandlerOption annotation in entity - {$meta->name}");
}
if (!strlen($option->name)) {
throw new InvalidMappingException("SlugHandlerOption name: {$option->name} should be valid name in entity - {$meta->name}");
}
$handlers[$class][$option->name] = $option->value;
}
$class::validate($handlers[$class], $meta);
}
}
// process slug fields
if (empty($slug->fields) || !is_array($slug->fields)) {
throw new InvalidMappingException("Slug must contain at least one field for slug generation in class - {$meta->name}");
}
foreach ($slug->fields as $slugField) {
if (!$meta->hasField($slugField)) {
throw new InvalidMappingException("Unable to find slug [{$slugField}] as mapped property in entity - {$meta->name}");
}
if (!$this->isValidField($meta, $slugField)) {
throw new InvalidMappingException("Cannot use field - [{$slugField}] for slug storage, type is not valid and must be 'string' or 'text' in class - {$meta->name}");
}
}
// set all options
$config['slugs'][$field] = array('fields' => $slug->fields, 'slug' => $field, 'style' => $slug->style, 'updatable' => $slug->updatable, 'unique' => $slug->unique, 'separator' => $slug->separator, 'handlers' => $handlers);
}
}
}
示例14: get
/**
* Gets a persistent field value.
*
* @param string $field
*
* @return mixed
*
* @throws \BadMethodCallException When no persistent field exists by that name.
*/
private function get($field)
{
$this->initializeDoctrine();
if ($this->cm->hasField($field) || $this->cm->hasAssociation($field)) {
return $this->{$field};
} else {
throw new \BadMethodCallException("no field with name '" . $field . "' exists on '" . $this->cm->getName() . "'");
}
}
示例15: 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');
}
}
}
}