本文整理汇总了PHP中Doctrine\Common\Persistence\Mapping\ClassMetadata::mapField方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata::mapField方法的具体用法?PHP ClassMetadata::mapField怎么用?PHP ClassMetadata::mapField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Persistence\Mapping\ClassMetadata
的用法示例。
在下文中一共展示了ClassMetadata::mapField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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]);
}
}
示例2: loadMetadataForClass
/**
* Loads the metadata for the specified class into the provided container.
*
* @param string $className
* @param ClassMetadata $metadata
*
* @throws \Exception
* @return void
*/
public function loadMetadataForClass($className, ClassMetadata $metadata)
{
if (!$metadata instanceof \Doctrine\ORM\Mapping\ClassMetadata) {
throw new \Exception('Error: class metadata object is the wrong type');
}
$refClass = new \ReflectionClass($className);
$classDocBlock = $refClass->getDocComment();
if (!$classDocBlock || strpos($classDocBlock, '@Table') === false) {
$metadata->setPrimaryTable(['name' => $this->_getTableName($className)]);
}
$needAutoGenerator = false;
foreach ($refClass->getProperties(\ReflectionProperty::IS_PUBLIC) as $prop) {
$propName = $prop->getName();
try {
$mapping = $metadata->getFieldMapping($propName);
} catch (MappingException $e) {
$mapping = null;
}
if (!$mapping) {
if ($propName == 'createdAt') {
if (!$this->isTransient($className) && !$refClass->isAbstract() && call_user_func($className . '::useAutoTimestamp')) {
$metadata->mapField(['fieldName' => 'createdAt', 'columnName' => call_user_func($className . '::getCreatedAtColumn'), 'type' => 'datetime']);
}
} else {
if ($propName == 'updatedAt') {
if (!$this->isTransient($className) && !$refClass->isAbstract() && call_user_func($className . '::useAutoTimestamp')) {
$metadata->mapField(['fieldName' => 'updatedAt', 'columnName' => call_user_func($className . '::getUpdatedAtColumn'), 'type' => 'datetime']);
}
} else {
$columnName = Inflector::tableize($propName);
$fieldMap = ['fieldName' => $propName, 'columnName' => $columnName, 'type' => $this->_getDefaultDataType($columnName)];
if ($columnName == 'id') {
$fieldMap['id'] = true;
$fieldMap['autoincrement'] = true;
$fieldMap['unsigned'] = true;
$needAutoGenerator = true;
} else {
if (in_array($columnName, ['price', 'tax', 'amount', 'cost', 'total'])) {
// DECIMAL(10,2)
$fieldMap['precision'] = 10;
$fieldMap['scale'] = 2;
}
}
$metadata->mapField($fieldMap);
}
}
}
}
if ($needAutoGenerator && !$metadata->usesIdGenerator()) {
$metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_AUTO);
}
}
示例3: loadMetadataForClass
/**
* Loads the metadata for the specified class into the provided container.
*
* @param string $className
* @param ClassMetadata $metadata
*/
public function loadMetadataForClass($className, ClassMetadata $metadata)
{
$class = $metadata->getReflectionClass();
if (!$class) {
// this happens when running annotation driver in combination with
// static reflection services. This is not the nicest fix
$class = new \ReflectionClass($metadata->name);
}
$entityAnnot = $this->reader->getClassAnnotation($class, 'Doctrine\\KeyValueStore\\Mapping\\Annotations\\Entity');
if (!$entityAnnot) {
throw new \InvalidArgumentException($metadata->name . ' is not a valid key-value-store entity.');
}
$metadata->storageName = $entityAnnot->storageName;
// Evaluate annotations on properties/fields
foreach ($class->getProperties() as $property) {
$idAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\KeyValueStore\\Mapping\\Annotations\\Id');
$transientAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\KeyValueStore\\Mapping\\Annotations\\Transient');
if ($idAnnot) {
$metadata->mapIdentifier($property->getName());
} elseif ($transientAnnot) {
$metadata->skipTransientField($property->getName());
} else {
$metadata->mapField(['fieldName' => $property->getName()]);
}
}
}
示例4: loadMetadataForClass
/**
* {@inheritdoc}
*/
public function loadMetadataForClass($className, ClassMetadata $metadata)
{
/** @var $class ClassMetadataInfo */
$reflClass = $metadata->getReflectionClass();
if ($entityAnnot = $this->reader->getClassAnnotation($reflClass, 'Pasinter\\OHM\\Mapping\\Annotations\\Entity')) {
$metadata->database = $entityAnnot->database;
}
// Evaluate annotations on properties/fields
foreach ($reflClass->getProperties() as $property) {
if ($fieldAnnot = $this->reader->getPropertyAnnotation($property, 'Pasinter\\OHM\\Mapping\\Annotations\\Field')) {
$mapping = $this->fieldToArray($property->getName(), $fieldAnnot);
if ($this->reader->getPropertyAnnotation($property, 'Pasinter\\OHM\\Mapping\\Annotations\\Id')) {
$mapping['id'] = true;
}
$metadata->mapField($mapping);
} elseif ($referenceOneAnnot = $this->reader->getPropertyAnnotation($property, 'Pasinter\\OHM\\Mapping\\Annotations\\ReferenceOne')) {
$mapping = $this->referenceOneToArray($property->getName(), $referenceOneAnnot);
$metadata->mapOneReference($mapping);
} elseif ($referenceManyAnnot = $this->reader->getPropertyAnnotation($property, 'Pasinter\\OHM\\Mapping\\Annotations\\ReferenceMany')) {
$mapping = $this->referenceManyToArray($property->getName(), $referenceManyAnnot);
$metadata->mapManyReference($mapping);
} elseif ($embedOneAnnot = $this->reader->getPropertyAnnotation($property, 'Pasinter\\OHM\\Mapping\\Annotations\\EmbedOne')) {
$mapping = $this->embedOneToArray($property->getName(), $embedOneAnnot);
$metadata->mapOneEmbed($mapping);
} elseif ($embedManyAnnot = $this->reader->getPropertyAnnotation($property, 'Pasinter\\OHM\\Mapping\\Annotations\\EmbedMany')) {
$mapping = $this->embedManyToArray($property->getName(), $embedManyAnnot);
$metadata->mapManyEmbed($mapping);
}
}
}
示例5: loadMetadataForClass
/**
* Loads the metadata for the specified class into the provided container.
*
* @param string $className
* @param CommonClassMetadata $metadata
*
* @return void
*/
public function loadMetadataForClass($className, CommonClassMetadata $metadata)
{
/** @var \Doctrine\KeyValueStore\Mapping\ClassMetadata $metadata */
try {
$element = $this->getElement($className);
} catch (MappingException $exception) {
throw new \InvalidArgumentException($metadata->name . ' is not a valid key-value-store entity.');
}
$class = new \ReflectionClass($className);
if (isset($element['storageName'])) {
$metadata->storageName = $element['storageName'];
}
$ids = [];
if (isset($element['id'])) {
$ids = $element['id'];
}
$transients = [];
if (isset($element['transient'])) {
$transients = $element['transient'];
}
foreach ($class->getProperties() as $property) {
if (in_array($property->getName(), $ids)) {
$metadata->mapIdentifier($property->getName());
continue;
}
if (in_array($property->getName(), $transients)) {
$metadata->skipTransientField($property->getName());
continue;
}
$metadata->mapField(array('fieldName' => $property->getName()));
}
}
示例6: initializeReflection
protected function initializeReflection(ClassMetadata $class, ReflectionService $reflService)
{
$class->reflClass = $reflService->getClass($class->name);
if ($class->reflClass) {
foreach ($class->reflClass->getProperties() as $property) {
$class->mapField(['fieldName' => $property->getName()]);
}
}
}
示例7: loadMetadataForClass
public function loadMetadataForClass($className, ClassMetadata $metadata)
{
if ($className === 'Mapping\\Fixture\\Unmapped\\Timestampable') {
$id = array();
$id['fieldName'] = 'id';
$id['type'] = 'integer';
$id['nullable'] = false;
$id['columnName'] = 'id';
$id['id'] = true;
$metadata->setIdGeneratorType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::GENERATOR_TYPE_AUTO'));
$metadata->mapField($id);
$created = array();
$created['fieldName'] = 'created';
$created['type'] = 'datetime';
$created['nullable'] = false;
$created['columnName'] = 'created';
$metadata->mapField($created);
}
}
示例8: loadMetadataForClass
/**
* Loads the metadata for the specified class into the provided container.
*
* @param string $className
* @param ClassMetadata $metadata
*
* @return void
*/
public function loadMetadataForClass($className, ClassMetadata $metadata)
{
if (!$this->isTransient($className)) {
throw new MappingException('Class ' . $className . 'has no appropriate ModelConfiguration');
}
$modelConfig = $className::getConfiguration();
$table = $modelConfig->getTable();
$table['name'] = SQL_TABLE_PREFIX . $table['name'];
$metadata->setPrimaryTable($table);
foreach ($modelConfig->getFields() as $fieldName => $config) {
self::mapTypes($config);
if (!$config['doctrineIgnore']) {
$metadata->mapField($config);
}
}
}
开发者ID:ingoratsdorf,项目名称:Tine-2.0-Open-Source-Groupware-and-CRM,代码行数:24,代码来源:DoctrineMappingDriver.php
示例9: loadMetadataForClass
/**
* Loads the metadata for the specified class into the provided container.
*
* @param string $className
* @param ClassMetadata $metadata
*
* @return void
*/
public function loadMetadataForClass($className, ClassMetadata $metadata)
{
$originClassName = $className;
$originMetadata = $this->em->getClassMetadata('Opifer\\ContentBundle\\Entity\\ListBlock');
//
// $metadata->name = self::REVISION_ENTITY; //. '' . str_replace('\\', '', $class->name);
// $class->rootEntityName = $class->name;
// $class->namespace = 'Opifer\\Revisions\\Entity';
//
// $class->discriminatorMap = null;
// $class->discriminatorColumn = null;
$metadata->setPrimaryTable(['name' => $originMetadata->getTableName() . '_revisions']);
foreach ($originMetadata->fieldMappings as $key => $fieldMapping) {
$fieldMapping['inherited'] = self::REVISION_ENTITY;
$fieldMapping['declared'] = self::REVISION_ENTITY;
if ($this->annotationReader->isPropertyRevised($originClassName, $fieldMapping['fieldName'])) {
$metadata->mapField($fieldMapping);
}
}
foreach ($originMetadata->associationMappings as $key => $associationMapping) {
$associationMapping['inherited'] = self::REVISION_ENTITY;
$associationMapping['declared'] = self::REVISION_ENTITY;
if ($this->annotationReader->isPropertyRevised($originClassName, $associationMapping['fieldName'])) {
if ($associationMapping['type'] == ClassMetadataInfo::ONE_TO_ONE) {
$metadata->mapOneToOne($associationMapping);
} else {
if ($associationMapping['type'] == ClassMetadataInfo::MANY_TO_ONE) {
$metadata->mapManyToOne($associationMapping);
} else {
if ($associationMapping['type'] == ClassMetadataInfo::ONE_TO_MANY) {
$metadata->mapOneToMany($associationMapping);
} else {
if ($associationMapping['type'] == ClassMetadataInfo::MANY_TO_MANY) {
$metadata->mapManyToMany($associationMapping);
}
}
}
}
}
}
}
示例10: loadMetadataForClass
/**
* Loads the metadata for the specified class into the provided container.
*
* @param string $className
* @param EntityMetadata|ClassMetadata $metadata
*
* @return void
* @throws MappingException
*/
public function loadMetadataForClass($className, ClassMetadata $metadata)
{
$element = $this->getElement($className);
switch ($element['type']) {
case 'entity':
if (array_key_exists('repositoryClass', $element)) {
$metadata->setCustomRepositoryClass($element['repositoryClass']);
}
break;
case 'mappedSuperclass':
$metadata->isMappedSuperclass = true;
$metadata->setCustomRepositoryClass(array_key_exists('repositoryClass', $element) ? $element['repositoryClass'] : null);
break;
}
if (null === $metadata->searcher) {
$metadata->searcher = DoctrineApi::class;
}
if (null === $metadata->finder) {
$metadata->finder = DoctrineApi::class;
}
// Configure client
if (array_key_exists('client', $element)) {
if (array_key_exists('name', $element['client'])) {
$metadata->clientName = $element['client']['name'];
}
if (array_key_exists('searcher', $element['client'])) {
$metadata->searcher = $element['client']['searcher'];
}
if (array_key_exists('finder', $element['client'])) {
$metadata->finder = $element['client']['finder'];
}
assert(in_array(Searcher::class, class_implements($metadata->searcher), true), 'Searcher ' . $metadata->searcher . ' should implement ' . Searcher::class);
assert(in_array(Finder::class, class_implements($metadata->finder), true), 'Finder ' . $metadata->finder . ' should implement ' . Finder::class);
$methodProvider = null;
if (array_key_exists('methods', $element['client'])) {
$methodProvider = new MethodProvider($element['client']['methods']);
}
if (array_key_exists('entityPath', $element['client'])) {
$pathSeparator = array_key_exists('entityPathSeparator', $element['client']) ? $element['client']['entityPathSeparator'] : null;
$methodProvider = new EntityMethodProvider($element['client']['entityPath'], $pathSeparator, $methodProvider);
}
if (null === $methodProvider) {
throw MappingException::noMethods();
}
$metadata->methodProvider = $methodProvider;
}
// Configure fields
if (array_key_exists('fields', $element)) {
foreach ($element['fields'] as $field => $mapping) {
$mapping = $this->fieldToArray($field, $mapping);
$metadata->mapField($mapping);
}
}
// Configure identifiers
$associationIds = [];
if (array_key_exists('id', $element)) {
// Evaluate identifier settings
foreach ($element['id'] as $name => $idElement) {
if (isset($idElement['associationKey']) && (bool) $idElement['associationKey'] === true) {
$associationIds[$name] = true;
continue;
}
$mapping = $this->fieldToArray($name, $idElement);
$mapping['id'] = true;
$metadata->mapField($mapping);
}
}
foreach (['oneToOne', 'manyToOne', 'oneToMany'] as $type) {
if (array_key_exists($type, $element)) {
$associations = $element[$type];
foreach ($associations as $name => $association) {
$this->mapAssociation($metadata, $type, $name, $association, $associationIds);
}
}
}
}
示例11: addMappingFromReference
private function addMappingFromReference(ClassMetadata $class, $fieldName, $reference, $type)
{
$class->mapField(array('type' => $type, 'reference' => true, 'targetDocument' => isset($reference['targetDocument']) ? $reference['targetDocument'] : null, 'fieldName' => $fieldName, 'strategy' => isset($reference['strategy']) ? (string) $reference['strategy'] : 'pushPull'));
}
示例12: mapDeletedAt
/**
* Add a "deletedAt" field to a SoftDeletable entity, if necessary
*
* @param ClassMetadata $classMetadata
*/
protected function mapDeletedAt(ClassMetadata $classMetadata)
{
if (!$classMetadata->hasField(self::DELETED_AT_FIELD)) {
$classMetadata->mapField(['fieldName' => self::DELETED_AT_FIELD, 'type' => 'datetime', 'nullable' => true]);
}
}
示例13: loadMetadataForClass
/**
* {@inheritdoc}
*/
public function loadMetadataForClass($className, ClassMetadata $metadata)
{
/** @var $metadata \Doctrine\ODM\PHPCR\Mapping\ClassMetadata */
$reflClass = $metadata->getReflectionClass();
$documentAnnots = array();
foreach ($this->reader->getClassAnnotations($reflClass) as $annot) {
foreach ($this->entityAnnotationClasses as $annotClass => $i) {
if ($annot instanceof $annotClass) {
$documentAnnots[$i] = $annot;
}
}
}
if (!$documentAnnots) {
throw MappingException::classIsNotAValidDocument($className);
}
// find the winning document annotation
ksort($documentAnnots);
$documentAnnot = reset($documentAnnots);
if ($documentAnnot instanceof ODM\MappedSuperclass) {
$metadata->isMappedSuperclass = true;
}
if (null !== $documentAnnot->referenceable) {
$metadata->setReferenceable($documentAnnot->referenceable);
}
if (null !== $documentAnnot->versionable) {
$metadata->setVersioned($documentAnnot->versionable);
}
if (null !== $documentAnnot->mixins) {
$metadata->setMixins($documentAnnot->mixins);
}
if (null !== $documentAnnot->inheritMixins) {
$metadata->setInheritMixins($documentAnnot->inheritMixins);
}
if (null !== $documentAnnot->nodeType) {
$metadata->setNodeType($documentAnnot->nodeType);
}
if (null !== $documentAnnot->repositoryClass) {
$metadata->setCustomRepositoryClassName($documentAnnot->repositoryClass);
}
if (null !== $documentAnnot->translator) {
$metadata->setTranslator($documentAnnot->translator);
}
foreach ($reflClass->getProperties() as $property) {
if ($metadata->isInheritedField($property->name) && $metadata->name !== $property->getDeclaringClass()->getName()) {
continue;
}
$mapping = array();
$mapping['fieldName'] = $property->getName();
foreach ($this->reader->getPropertyAnnotations($property) as $fieldAnnot) {
if ($fieldAnnot instanceof ODM\Property) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$metadata->mapField($mapping);
} elseif ($fieldAnnot instanceof ODM\Id) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$metadata->mapId($mapping);
} elseif ($fieldAnnot instanceof ODM\Node) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$metadata->mapNode($mapping);
} elseif ($fieldAnnot instanceof ODM\Nodename) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$metadata->mapNodename($mapping);
} elseif ($fieldAnnot instanceof ODM\ParentDocument) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
$metadata->mapParentDocument($mapping);
} elseif ($fieldAnnot instanceof ODM\Child) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
$metadata->mapChild($mapping);
} elseif ($fieldAnnot instanceof ODM\Children) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
$metadata->mapChildren($mapping);
} elseif ($fieldAnnot instanceof ODM\ReferenceOne) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
$metadata->mapManyToOne($mapping);
} elseif ($fieldAnnot instanceof ODM\ReferenceMany) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
$metadata->mapManyToMany($mapping);
} elseif ($fieldAnnot instanceof ODM\Referrers) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
$metadata->mapReferrers($mapping);
} elseif ($fieldAnnot instanceof ODM\MixedReferrers) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$metadata->mapMixedReferrers($mapping);
} elseif ($fieldAnnot instanceof ODM\Locale) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$metadata->mapLocale($mapping);
} elseif ($fieldAnnot instanceof ODM\Depth) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$metadata->mapDepth($mapping);
} elseif ($fieldAnnot instanceof ODM\VersionName) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$metadata->mapVersionName($mapping);
//.........这里部分代码省略.........
示例14: mapField
/**
* Adds mapping to single field
*
* @param string $field
*/
protected function mapField($field)
{
if (!$this->classMetadata->hasField($field)) {
$this->classMetadata->mapField(['fieldName' => $field, 'type' => 'datetime', 'nullable' => true]);
}
}
示例15: loadMetadataForClass
/**
* Loads the metadata for the specified class into the provided container.
*
* @param string $className
* @param CommonClassMetadata $metadata
*
* @return void
*/
public function loadMetadataForClass($className, CommonClassMetadata $metadata)
{
try {
$xmlRoot = $this->getElement($className);
} catch (MappingException $exception) {
throw new \InvalidArgumentException($metadata->name . ' is not a valid key-value-store entity.');
}
if ($xmlRoot->getName() != 'entity') {
throw new \InvalidArgumentException($metadata->name . ' is not a valid key-value-store entity.');
}
$class = new \ReflectionClass($className);
if (isset($xmlRoot['storage-name'])) {
$metadata->storageName = $xmlRoot['storage-name'];
}
$ids = [];
if (isset($xmlRoot->id)) {
foreach ($xmlRoot->id as $id) {
$ids[] = (string) $id;
}
}
$transients = [];
if (isset($xmlRoot->transient)) {
foreach ($xmlRoot->transient as $transient) {
$transients[] = (string) $transient;
}
}
foreach ($class->getProperties() as $property) {
if (in_array($property->getName(), $ids)) {
$metadata->mapIdentifier($property->getName());
continue;
}
if (in_array($property->getName(), $transients)) {
$metadata->skipTransientField($property->getName());
continue;
}
$metadata->mapField(array('fieldName' => $property->getName()));
}
}