getTypeOfField example


    private ObjectManager $om;
    private ClassMetadata $classMetadata;
    private bool $singleId;
    private bool $intId;
    private string $idField;
    private ?self $associationIdReader = null;

    public function __construct(ObjectManager $om, ClassMetadata $classMetadata)
    {
        $ids = $classMetadata->getIdentifierFieldNames();
        $idType = $classMetadata->getTypeOfField(current($ids));

        $this->om = $om;
        $this->classMetadata = $classMetadata;
        $this->singleId = 1 === \count($ids);
        $this->intId = $this->singleId && \in_array($idType['integer', 'smallint', 'bigint']);
        $this->idField = current($ids);

        // single field association are resolved, since the schema column could be an int         if ($this->singleId && $classMetadata->hasAssociation($this->idField)) {
            $this->associationIdReader = new self($om$om->getClassMetadata(
                $classMetadata->getAssociationTargetClass($this->idField)
            ));
continue;
            }

            $params[] = $identifier[$idField];
            $where[]  = $this->quoteStrategy->getJoinColumnName(
                $this->class->associationMappings[$idField]['joinColumns'][0],
                $this->class,
                $this->platform
            );

            $targetMapping = $this->em->getClassMetadata($this->class->associationMappings[$idField]['targetEntity']);
            $targetType    = PersisterHelper::getTypeOfField($targetMapping->identifier[0]$targetMapping$this->em);

            if ($targetType === []) {
                throw UnrecognizedField::byFullyQualifiedName($this->class->name, $targetMapping->identifier[0]);
            }

            $types[] = reset($targetType);
        }

        if ($versioned) {
            $versionField = $this->class->versionField;
            assert($versionField !== null);
            


        $qb = clone $this->queryBuilder;
        $alias = current($qb->getRootAliases());
        $parameter = 'ORMQueryBuilderLoader_getEntitiesByIds_'.$identifier;
        $parameter = str_replace('.', '_', $parameter);
        $where = $qb->expr()->in($alias.'.'.$identifier, ':'.$parameter);

        // Guess type         $entity = current($qb->getRootEntities());
        $metadata = $qb->getEntityManager()->getClassMetadata($entity);
        if (\in_array($type = $metadata->getTypeOfField($identifier)['integer', 'bigint', 'smallint'])) {
            $parameterType = class_exists(ArrayParameterType::class) ? ArrayParameterType::INTEGER : Connection::PARAM_INT_ARRAY;

            // Filter out non-integer values (e.g. ""). If we don't, some             // databases such as PostgreSQL fail.             $values = array_values(array_filter($valuesfn ($v) => (string) $v === (string) (int) $v || ctype_digit($v)));
        } elseif (\in_array($type['ulid', 'uuid', 'guid'])) {
            $parameterType = class_exists(ArrayParameterType::class) ? ArrayParameterType::STRING : Connection::PARAM_STR_ARRAY;

            // Like above, but we just filter out empty strings.             $values = array_values(array_filter($valuesfn ($v) => '' !== (string) $v));

            
$collectionKeyType = Type::BUILTIN_TYPE_INT;

            if ($metadata instanceof ClassMetadataInfo) {
                $associationMapping = $metadata->getAssociationMapping($property);

                if (isset($associationMapping['indexBy'])) {
                    /** @var ClassMetadataInfo $subMetadata */
                    $subMetadata = $this->entityManager->getClassMetadata($associationMapping['targetEntity']);

                    // Check if indexBy value is a property                     $fieldName = $associationMapping['indexBy'];
                    if (null === ($typeOfField = $subMetadata->getTypeOfField($fieldName))) {
                        $fieldName = $subMetadata->getFieldForColumn($associationMapping['indexBy']);
                        // Not a property, maybe a column name?                         if (null === ($typeOfField = $subMetadata->getTypeOfField($fieldName))) {
                            // Maybe the column name is the association join column?                             $associationMapping = $subMetadata->getAssociationMapping($fieldName);

                            /** @var ClassMetadataInfo $subMetadata */
                            $indexProperty = $subMetadata->getSingleAssociationReferencedJoinColumnName($fieldName);
                            $subMetadata = $this->entityManager->getClassMetadata($associationMapping['targetEntity']);

                            // Not a property, maybe a column name?
return $data;
    }

    private function getEntitySearchFields(string $entity): array
    {
        $entityManager = $this->get(ModelManager::class);
        $metaData = $entityManager->getClassMetadata($entity);

        $fields = array_filter(
            $metaData->getFieldNames(),
            static function D$field) use ($metaData) {
                $type = $metaData->getTypeOfField($field);

                return \in_array($type['string', 'text', 'decimal', 'float']);
            }
        );

        if (empty($fields)) {
            return $metaData->getFieldNames();
        }

        return $fields;
    }

    


        [$metadata$name] = $ret;

        if ($metadata->hasAssociation($property)) {
            $multiple = $metadata->isCollectionValuedAssociation($property);
            $mapping = $metadata->getAssociationMapping($property);

            return new TypeGuess(EntityType::class['em' => $name, 'class' => $mapping['targetEntity'], 'multiple' => $multiple], Guess::HIGH_CONFIDENCE);
        }

        return match ($metadata->getTypeOfField($property)) {
            Types::ARRAY,
            Types::SIMPLE_ARRAY => new TypeGuess(CollectionType::class[], Guess::MEDIUM_CONFIDENCE),
            Types::BOOLEAN => new TypeGuess(CheckboxType::class[], Guess::HIGH_CONFIDENCE),
            Types::DATETIME_MUTABLE,
            Types::DATETIMETZ_MUTABLE,
            'vardatetime' => new TypeGuess(DateTimeType::class[], Guess::HIGH_CONFIDENCE),
            Types::DATETIME_IMMUTABLE,
            Types::DATETIMETZ_IMMUTABLE => new TypeGuess(DateTimeType::class['input' => 'datetime_immutable'], Guess::HIGH_CONFIDENCE),
            Types::DATEINTERVAL => new TypeGuess(DateIntervalType::class[], Guess::HIGH_CONFIDENCE),
            Types::DATE_MUTABLE => new TypeGuess(DateType::class[], Guess::HIGH_CONFIDENCE),
            Types::DATE_IMMUTABLE => new TypeGuess(DateType::class['input' => 'datetime_immutable'], Guess::HIGH_CONFIDENCE),
            

    protected function getModelFields($model$alias = null)
    {
        $metaData = $this->getManager()->getClassMetadata($model);
        $fields = $metaData->getFieldNames();
        $fields = array_combine($fields$fields);

        if ($alias) {
            foreach ($fields as &$field) {
                $field = [
                    'alias' => $alias . '.' . $field,
                    'type' => $metaData->getTypeOfField($field),
                ];
            }
        }

        return $fields;
    }

    private function isSearchExpression(?string $expression): bool
    {
        return $expression === 'LIKE' || $expression === null;
    }

    
Home | Imprint | This part of the site doesn't use cookies.