Returns the last registered entity code generator service id for a given entity class and field.

@param string $entityClass
@param string $entityField

@return CodeGeneratorInterface

@throws \Exception
541690
public static function getCodeGenerator($entityClass, $entityField = 'code')
    {
        if (!isset(self::$generators[$entityClass][$entityField])) {
            throw new \Exception("There is no registered entity code generator for class $entityClass and field $entityField");
        }

        return self::$generators[$entityClass][$entityField];
    }
458523
protected function askForEntity($field, $class)
    {
        if (!$class) {
            $question = "Entity class for $field: ";
            $class = $this->ask($question);
            $class = $this->namespaceResolver->resolveNamespaceForClass($class);

            while (!(\is_string($class) && \class_exists($class) && \is_subclass_of($class, EntityInterface::class))) {
                $this->out->writeln('<error>Invalid entity class.</error>');
                $class = $this->ask($question);
            }
        }

        $context = new SerializationContext();
        $context->setVersion($this->version);
        $versionExclusion = new VersionExclusionStrategy($this->version);

        $group = $this->ask('Group for this entity(none): ', null);
        if ($group) {
            $groupExclusion = new GroupsExclusionStrategy([$group]);
            $context->setGroups([$group]);
        }

        /** @var EntityInterface $entity */
        $entity = new $class();
        $entity->setAPIVersion($this->version);
        $entity->setEntityGroup($group);

        $propertyAccessor = new PropertyAccessor();
        $metadata = $this->getEntityMetadata($class);

        foreach ($metadata->propertyMetadata as $property => $propertyMetadata) {
            if (!\in_array($property, ['_group', '_apiVersion', '_type'])
                && $propertyAccessor->isWritable($entity, $property)
                && (!$group || !$groupExclusion->shouldSkipProperty($propertyMetadata, $context))
                && !$versionExclusion->shouldSkipProperty($propertyMetadata, $context)
            ) {
                $typeName = @$propertyMetadata->type['name'];
                $typeParams = @$propertyMetadata->type['params'];

                if (empty($typeName)) {
                    continue;
                }

                if ('array' != $typeName) {
                    $result = $this->askForField('Value for '.$property, $typeName);
                } else {
                    $numParams = \count($typeParams);

                    if (2 === $numParams) {
                        $keyType = @$typeParams[0]['name'];
                        $valueType = $typeParams[1]['name'];
                    } elseif (1 === $numParams) {
                        $keyType = null;
                        $valueType = $typeParams[0]['name'];
                    } else {
                        throw new \RuntimeException('Missing jms type params');
                    }

                    $question = "Do you want to add a new entry to $property? (yes): ";

                    $result = [];

                    while ('yes' === $this->ask($question, 'yes')) {
                        $key = null;

                        if ($keyType) {
                            $key = $this->askForField($property.'[] Key', $keyType);
                        }

                        $value = $this->askForField($property.'[] Value', $valueType);

                        if ($key) {
                            $result[$key] = $value;
                        } else {
                            $result[] = $value;
                        }
                    }
                }

                $propertyAccessor->setValue($entity, $property, $result);
            }
        }

        return $entity;
    }
646839
public function createBatchDeleteForm($entityClass, array $entities = null)
    {
        if (null !== $entities && empty($entities)) {
            throw new FormException(
                sprintf('Unable to create batch delete form for entity class "%s": entity array is empty.', $entityClass)
            );
        }

        $options = [
            'entity_class' => $entityClass,
        ];

        if (!empty($entities)) {
            $options = array_merge($options, [
                'action'   => $this->adminRouter->generate(reset($entities), $entityClass, AdminRouter::TYPE_BATCH_DELETE),
                'entities' => $entities,
            ]);
        }

        return $this->genericFormFactory->create(BatchDeleteType::class, null, $options);
    }
179571
private function generateMethods(): EntityGenerator
    {
        $this->entityClass
            ->addMethod('getId')
            ->setVisibility('public')
            ->addComment('Returns ' . strtolower($this->entityData['class']) . ' ID' . PHP_EOL)
            ->addComment('@return int')
            ->addBody('return $this->id;')
            ->setReturnType('int');

        foreach ($this->entityData['properties'] as $name => $type) {
            $this
                ->generateGetter($name, $type)
                ->generateSetter($name, $type);
        }

        return $this;
    }
131631
public function getEntityClassName()
    {
        if (null == $this->entityClass) {
            $this->setEntityClass(get_class($this->getEntity()));
        }
        return $this->entityClass;
    }
236406
public function entity(string $entityClass) : EntityMapperDefiner
    {
        return new EntityMapperDefiner($this->iocContainer, function (callable $entityMapperFactory) use ($entityClass) {
            $this->entityMapperFactories[] = $entityMapperFactory;
        });
    }
16622
public String[] getEntityClass(Object obj, String name, Siren4JEntity entityAnno) {
        Class<?> clazz = obj.getClass();
        String[] compClass = entityAnno == null ? null : entityAnno.entityClass();
        //If entity class specified then use it.
        if (compClass != null && !ArrayUtils.isEmpty(compClass)) {
            return compClass;
        }
        //Else use name or class.
        List<String> entityClass = new ArrayList<String>();
        entityClass.add(StringUtils.defaultString(name, clazz.getName()));
        if (obj instanceof CollectionResource) {
            String tag = getCollectionClassTag();
            if (StringUtils.isNotBlank(tag)) {
                entityClass.add(tag);
            }
        }
        return entityClass.toArray(new String[]{});
    }
374201
protected function getListingService()
    {
        if (null == $this->listingService) {
            $this->listingService = new EntityListingService(
                $this->getEntityClassName()
            );
        }
        return $this->listingService;
    }
599490
private function getCustomObjectMeta($entityClass)
    {
        if (!array_key_exists($entityClass, $this->customObjectMeta)) {
            $meta = $this->extendedMetadataFactory->getExtendedMetadata($entityClass);

            $this->customObjectMeta[$entityClass] = isset($meta['customObjects']) && !empty($meta['customObjects'])
                ? $meta['customObjects']
                : null;
        }

        return $this->customObjectMeta[$entityClass];
    }
104230
protected function getEntityGenerator($classToExtend = null)
    {
        $entityGenerator = new EntityGenerator();
        if (!is_null($classToExtend)) {
            $entityGenerator->setClassToExtend($classToExtend);
        }
        $entityGenerator->setGenerateAnnotations(true);
        $entityGenerator->setGenerateStubMethods(true);
        $entityGenerator->setRegenerateEntityIfExists(false);
        $entityGenerator->setUpdateEntityIfExists(true);
        $entityGenerator->setNumSpaces(4);
        $entityGenerator->setAnnotationPrefix('ORM\\');

        return $entityGenerator;
    }
653997
public EntityType getEntityType(Class<?> entityClass) {
    String className = entityClass.getName();
    EntityType type = entityTypes.get(className);
    if (null != type) { return type; }

    type = classEntityTypes.get(className);
    if (null == type) {
      List<EntityType> matched = CollectUtils.newArrayList();
      for (EntityType entityType : entityTypes.values()) {
        if (className.equals(entityType.getEntityName())
            || className.equals(entityType.getEntityClass().getName())) {
          matched.add(entityType);
        }
      }
      if (matched.size() > 1) { throw new RuntimeException("multi-entityName for class:" + className); }
      if (matched.isEmpty()) {
        EntityType tmp = new EntityType(entityClass);
        classEntityTypes.put(className, tmp);
        return tmp;
      } else {
        classEntityTypes.put(className, matched.get(0));
        type = (EntityType) matched.get(0);
      }
    }
    return type;
  }
769103
public function getEntityClass()
    {
        if (!$this->_entityClass) {
            $default = Entity::class;
            $self = get_called_class();
            $parts = explode('\\', $self);

            if ($self === __CLASS__ || count($parts) < 3) {
                return $this->_entityClass = $default;
            }

            $alias = Inflector::classify(Inflector::underscore(substr(array_pop($parts), 0, -5)));
            $name = implode('\\', array_slice($parts, 0, -1)) . '\\Entity\\' . $alias;
            if (!class_exists($name)) {
                return $this->_entityClass = $default;
            }

            $class = App::className($name, 'Model/Entity');
            if (!$class) {
                throw new MissingEntityException([$name]);
            }

            $this->_entityClass = $class;
        }

        return $this->_entityClass;
    }
1242909
protected function getFieldGetter(\ReflectionClass $reflectionClass, $fieldName)
    {
        foreach (array('get', 'is', 'has') as $prefix) {
            $getter = $prefix.ucfirst($fieldName);
            $reflectionMethod = $reflectionClass->getMethod($getter);

            if ($reflectionMethod && $reflectionMethod->isPublic()) {
                return $reflectionMethod;
            }
        }

        throw new EntityListException("The field $fieldName does not exist or is not accessible.");
    }
1017781
protected function onUpdate(callable $callback, $entityClass = null)
    {
        $this->checkIfInitialized();

        return $this->processEntities($this->uow->getScheduledEntityUpdates(), self::OPERATION_UPDATE, $callback, $entityClass);
    }
289416
public function getEntityStructure($entityClassName)
    {
        if ($entityClassName instanceof Entity) {
            $reflection = new \ReflectionClass($entityClassName);
            $entityClassName = $reflection->getName();
        }

        if (! $this->isRegistered($entityClassName)) {
            $this->registerEntity($entityClassName);
        }
        return $this->entities[$entityClassName];
    }
321359
public function make($entityClass, EntityMap $entityMap)
    {
        $driver = $entityMap->getDriver();

        $connection = $entityMap->getConnection();

        $adapter = $this->drivers->getAdapter($driver, $connection);

        $entityMap->setDateFormat($adapter->getDateFormat());

        $mapper = new Mapper($entityMap, $adapter, $this->dispatcher, $this->manager);

        // Fire Initializing Event
        $mapper->fireEvent('initializing', $mapper);

        // Proceed necessary parsing on the EntityMap object
        if (!$entityMap->isBooted()) {
            $entityMap->initialize();
        }

        // Apply Inheritance scope, if necessary
        if ($entityMap->getInheritanceType() == 'single_table') {
            $scope = new SingleTableInheritanceScope($entityMap);
            $mapper->addGlobalScope($scope);
        }

        // Fire Initialized Event
        $mapper->fireEvent('initialized', $mapper);

        return $mapper;
    }
966389
private function createDescriptor($entityClass)
    {
        $descriptor = new EntityDescriptor($entityClass);
        $this->descriptors->set($entityClass, $descriptor);
        return $descriptor;
    }