本文整理汇总了PHP中Doctrine\Common\Persistence\Mapping\ClassMetadata::getFieldMapping方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata::getFieldMapping方法的具体用法?PHP ClassMetadata::getFieldMapping怎么用?PHP ClassMetadata::getFieldMapping使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Persistence\Mapping\ClassMetadata
的用法示例。
在下文中一共展示了ClassMetadata::getFieldMapping方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}
}
示例3: 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);
}
}
}
示例4: getDateValue
/**
* {@inheritDoc}
*/
public function getDateValue(ClassMetadata $meta, $field)
{
$mapping = $meta->getFieldMapping($field);
if (isset($mapping['type']) && $mapping['type'] === 'timestamp') {
return time();
}
return new \DateTime();
}
示例5: validateField
public static function validateField(ClassMetadata $meta, $field)
{
if ($meta->isMappedSuperclass) {
return;
}
$fieldMapping = $meta->getFieldMapping($field);
if (!in_array($fieldMapping['type'], self::$validTypes)) {
throw new InvalidMappingException(sprintf('Field "%s" must be of one of the following types: "%s"', $fieldMapping['type'], implode(', ', self::$validTypes)));
}
}
示例6: validateField
public static function validateField(ClassMetadata $meta, $field)
{
if ($meta->isMappedSuperclass) {
return;
}
$fieldMapping = $meta->getFieldMapping($field);
if (!$fieldMapping['type'] == self::$validTypes) {
throw new InvalidMappingException(sprintf('Field "%s" must be of type Client', $fieldMapping['type']));
}
}
示例7: 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);
}
}
示例8: isValidField
/**
* Checks if $field type is valid as Sortable Position field
*
* @param ClassMetadata $meta
* @param string $field
* @return boolean
*/
protected function isValidField($meta, $field)
{
$mapping = $meta->getFieldMapping($field);
return $mapping && in_array($mapping['type'], $this->validTypes);
}
示例9: buildPhoneFields
/**
* @param Common\Persistence\Mapping\ClassMetadata $class
*
* @return array
*
* @throws ORM\Mapping\MappingException
*/
private function buildPhoneFields(Common\Persistence\Mapping\ClassMetadata $class)
{
$phoneFields = [];
foreach ($class->getFieldNames() as $fieldName) {
$mapping = $class->getFieldMapping($fieldName);
if ($mapping['type'] !== Types\Phone::PHONE) {
continue;
}
$classReflection = $class->isInheritedField($fieldName) ? new \ReflectionClass($mapping['declared']) : $class->getReflectionClass();
$phoneFields[$fieldName] = ['phoneFieldClass' => $classReflection->getName()];
}
return $phoneFields;
}