Display all the mapping information for a single Entity.

@param string $entityName Full or partial entity class name
429204
private function displayEntity($entityName, EntityManagerInterface $entityManager, SymfonyStyle $ui)
    {
        $metadata    = $this->getClassMetadata($entityName, $entityManager);
        $parentValue = $metadata->getParent() === null ? '<comment>None</comment>' : '';

        $ui->table(
            ['Field', 'Value'],
            array_merge(
                [
                    $this->formatField('Name', $metadata->getClassName()),
                    $this->formatField('Root entity name', $metadata->getRootClassName()),
                    $this->formatField('Custom repository class', $metadata->getCustomRepositoryClassName()),
                    $this->formatField('Mapped super class?', $metadata->isMappedSuperclass),
                    $this->formatField('Embedded class?', $metadata->isEmbeddedClass),
                    $this->formatField('Parent classes', $parentValue),
                ],
                $this->formatParentClasses($metadata),
                [
                    $this->formatField('Sub classes', $metadata->getSubClasses()),
                    $this->formatField('Embedded classes', $metadata->getSubClasses()),
                    $this->formatField('Identifier', $metadata->getIdentifier()),
                    $this->formatField('Inheritance type', $metadata->inheritanceType),
                    $this->formatField('Discriminator column', ''),
                ],
                $this->formatColumn($metadata->discriminatorColumn),
                [
                    $this->formatField('Discriminator value', $metadata->discriminatorValue),
                    $this->formatField('Discriminator map', $metadata->discriminatorMap),
                    $this->formatField('Table', ''),
                ],
                $this->formatTable($metadata->table),
                [
                    $this->formatField('Composite identifier?', $metadata->isIdentifierComposite()),
                    $this->formatField('Change tracking policy', $metadata->changeTrackingPolicy),
                    $this->formatField('Versioned?', $metadata->isVersioned()),
                    $this->formatField('Version field', ($metadata->isVersioned() ? $metadata->versionProperty->getName() : '')),
                    $this->formatField('Read only?', $metadata->isReadOnly()),

                    $this->formatEntityListeners($metadata->entityListeners),
                ],
                [$this->formatField('Property mappings:', '')],
                $this->formatPropertyMappings($metadata->getDeclaredPropertiesIterator())
            )
        );
    }
853424
private function initFieldDescriptors($entityName, $id)
    {
        $mediaEntityName = $this->getParameter('sulu.model.media.class');

        $entityJoin = new DoctrineJoinDescriptor(
            $mediaEntityName,
            $entityName . '.medias',
            $entityName . '.id = ' . $id,
            DoctrineJoinDescriptor::JOIN_METHOD_INNER
        );

        $this->fieldDescriptors = [];

        $this->fieldDescriptors['entity'] = new DoctrineFieldDescriptor(
            'id',
            'entity',
            $entityName,
            null,
            [],
            FieldDescriptorInterface::VISIBILITY_NO,
            FieldDescriptorInterface::SEARCHABILITY_NO
        );

        $this->fieldDescriptors['id'] = new DoctrineFieldDescriptor(
            'id',
            'id',
            $mediaEntityName,
            'public.id',
            [
                $mediaEntityName => $entityJoin,
            ],
            FieldDescriptorInterface::VISIBILITY_NO,
            FieldDescriptorInterface::SEARCHABILITY_NO
        );

        $this->fieldDescriptors['thumbnails'] = new DoctrineFieldDescriptor(
            'id',
            'thumbnails',
            $mediaEntityName,
            'media.media.thumbnails',
            [
                $mediaEntityName => $entityJoin,
            ],
            FieldDescriptorInterface::VISIBILITY_YES,
            FieldDescriptorInterface::SEARCHABILITY_NEVER,
            'thumbnails',
            false
        );

        $this->fieldDescriptors['name'] = new DoctrineFieldDescriptor(
            'name',
            'name',
            self::$fileVersionEntityName,
            'public.name',
            [
                $mediaEntityName => $entityJoin,
                self::$fileEntityName => new DoctrineJoinDescriptor(
                    self::$fileEntityName,
                    $mediaEntityName . '.files'
                ),
                self::$fileVersionEntityName => new DoctrineJoinDescriptor(
                    self::$fileVersionEntityName,
                    self::$fileEntityName . '.fileVersions',
                    self::$fileVersionEntityName . '.version = ' . self::$fileEntityName . '.version'
                ),
            ]
        );
        $this->fieldDescriptors['size'] = new DoctrineFieldDescriptor(
            'size',
            'size',
            self::$fileVersionEntityName,
            'media.media.size',
            [
                $mediaEntityName => $entityJoin,
                self::$fileEntityName => new DoctrineJoinDescriptor(
                    self::$fileEntityName,
                    $mediaEntityName . '.files'
                ),
                self::$fileVersionEntityName => new DoctrineJoinDescriptor(
                    self::$fileVersionEntityName,
                    self::$fileEntityName . '.fileVersions',
                    self::$fileVersionEntityName . '.version = ' . self::$fileEntityName . '.version'
                ),
            ],
            FieldDescriptorInterface::VISIBILITY_NO,
            FieldDescriptorInterface::SEARCHABILITY_NEVER,
            'bytes'
        );

        $this->fieldDescriptors['changed'] = new DoctrineFieldDescriptor(
            'changed',
            'changed',
            self::$fileVersionEntityName,
            'public.changed',
            [
                $mediaEntityName => $entityJoin,
                self::$fileEntityName => new DoctrineJoinDescriptor(
                    self::$fileEntityName,
                    $mediaEntityName . '.files'
                ),
                self::$fileVersionEntityName => new DoctrineJoinDescriptor(
                    self::$fileVersionEntityName,
                    self::$fileEntityName . '.fileVersions',
                    self::$fileVersionEntityName . '.version = ' . self::$fileEntityName . '.version'
                ),
            ],
            FieldDescriptorInterface::VISIBILITY_NO,
            FieldDescriptorInterface::SEARCHABILITY_NEVER,
            'date'
        );

        $this->fieldDescriptors['created'] = new DoctrineFieldDescriptor(
            'created',
            'created',
            self::$fileVersionEntityName,
            'public.created',
            [
                $mediaEntityName => $entityJoin,
                self::$fileEntityName => new DoctrineJoinDescriptor(
                    self::$fileEntityName,
                    $mediaEntityName . '.files'
                ),
                self::$fileVersionEntityName => new DoctrineJoinDescriptor(
                    self::$fileVersionEntityName,
                    self::$fileEntityName . '.fileVersions',
                    self::$fileVersionEntityName . '.version = ' . self::$fileEntityName . '.version'
                ),
            ],
            FieldDescriptorInterface::VISIBILITY_NO,
            FieldDescriptorInterface::SEARCHABILITY_NEVER,
            'date'
        );

        $this->fieldDescriptors['title'] = new DoctrineFieldDescriptor(
            'title',
            'title',
            self::$fileVersionMetaEntityName,
            'public.title',
            [
                $mediaEntityName => $entityJoin,
                self::$fileEntityName => new DoctrineJoinDescriptor(
                    self::$fileEntityName,
                    $mediaEntityName . '.files'
                ),
                self::$fileVersionEntityName => new DoctrineJoinDescriptor(
                    self::$fileVersionEntityName,
                    self::$fileEntityName . '.fileVersions',
                    self::$fileVersionEntityName . '.version = ' . self::$fileEntityName . '.version'
                ),
                self::$fileVersionMetaEntityName => new DoctrineJoinDescriptor(
                    self::$fileVersionMetaEntityName,
                    self::$fileVersionEntityName . '.meta'
                ),
            ],
            FieldDescriptorInterface::VISIBILITY_NO,
            FieldDescriptorInterface::SEARCHABILITY_YES,
            'title'
        );

        $this->fieldDescriptors['description'] = new DoctrineFieldDescriptor(
            'description',
            'description',
            self::$fileVersionMetaEntityName,
            'media.media.description',
            [
                $mediaEntityName => $entityJoin,
                self::$fileEntityName => new DoctrineJoinDescriptor(
                    self::$fileEntityName,
                    $mediaEntityName . '.files'
                ),
                self::$fileVersionEntityName => new DoctrineJoinDescriptor(
                    self::$fileVersionEntityName,
                    self::$fileEntityName . '.fileVersions',
                    self::$fileVersionEntityName . '.version = ' . self::$fileEntityName . '.version'
                ),
                self::$fileVersionMetaEntityName => new DoctrineJoinDescriptor(
                    self::$fileVersionMetaEntityName,
                    self::$fileVersionEntityName . '.meta'
                ),
            ],
            FieldDescriptorInterface::VISIBILITY_YES,
            FieldDescriptorInterface::SEARCHABILITY_YES
        );
    }
858788
private static function mapDataToEntity($entityName, \stdClass $data)
    {
        $entity = new $entityName();

        if (!($entity instanceof Entity)) {
            throw new \RuntimeException(
                sprintf(
                    'Object "%s" must extend Entity',
                    $entityName
                )
            );
        }

        $foreignKeyEntityMap = $entity->foreignKeyEntityMap();

        $properties = array_keys(get_object_vars($data));

        foreach ($properties as $propertyName) {
            if (!property_exists($entity, $propertyName)) {
                throw new \UnexpectedValueException(
                    sprintf(
                        'Property %s->%s does not exist',
                        get_class($entity),
                        $propertyName
                    )
                );
            }

            if (isset($foreignKeyEntityMap[$propertyName])) {
                $entity->$propertyName = self::mapDataToEntity(
                    $foreignKeyEntityMap[$propertyName],
                    $data->$propertyName
                );
            } elseif (is_string($data->$propertyName) && preg_match('/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/', $data->$propertyName)) {
                $entity->$propertyName = new \DateTime($data->$propertyName);
            } else {
                $entity->$propertyName = json_decode(json_encode($data->$propertyName), true);
            }
        }

        return $entity;
    }
1238948
public function process($itemName, $entityName)
    {
        $inputs = array(
            'itemName' => $itemName,
            'entityName' => $entityName,
        );
        $this->setMethods($inputs);

        $convertedDefs = $this->load($itemName, $entityName);

        $inputs = $this->setArrayValue(null, $inputs);
        $this->setMethods($inputs);

        return $convertedDefs;
    }
690764
public function showStatusCommand($clientName = null)
    {
        $entityMappingCollection = $this->entityMappingBuilder->buildMappingInformation();
        $entityMappingCollection = $this->buildArrayFromMappingCollection($entityMappingCollection);

        $client = $this->clientFactory->create($clientName);
        $this->backendMappingBuilder->setClient($client);
        $backendMappingCollection = $this->backendMappingBuilder->buildMappingInformation();
        $backendMappingCollection = $this->buildArrayFromMappingCollection($backendMappingCollection);

        $this->printLegend();
        $this->outputFormatted('<b>Mapping status:</b>');
        $this->outputFormatted('<b>---------------</b>');

        $mergedMappingCollection = array_merge_recursive($entityMappingCollection, $backendMappingCollection);
        foreach ($mergedMappingCollection as $indexName => $typeSet) {
            $this->outputFormatted('index %s:', [$this->markupDiffValue(isset($entityMappingCollection[$indexName]) ? $indexName : null, isset($backendMappingCollection[$indexName]) ? $indexName : null)]);
            foreach ($typeSet as $typeName => $mappingSet) {
                $propertiesSet = $mappingSet['properties'];
                $this->outputFormatted('type %s:', [$this->markupDiffValue(isset($entityMappingCollection[$indexName][$typeName]) ? $typeName : null, isset($backendMappingCollection[$indexName][$typeName]) ? $typeName : null)], 4);
                foreach ($propertiesSet as $propertyName => $properties) {
                    $entityProperties = Arrays::getValueByPath($entityMappingCollection, [
                        $indexName,
                        $typeName,
                        'properties',
                        $propertyName,
                    ]);
                    $backendProperties = Arrays::getValueByPath($backendMappingCollection, [
                        $indexName,
                        $typeName,
                        'properties',
                        $propertyName,
                    ]);

                    $this->outputFormatted('property %s:', [$this->markupDiffValue($entityProperties ? $propertyName : null, $backendProperties ? $propertyName : null)], 8);
                    foreach ($properties as $key => $value) {
                        $keyMarkup = $this->markupDiffValue(isset($entityProperties[$key]) ? $key : null, isset($backendProperties[$key]) ? $key : null);
                        $valueMarkup = $this->markupDiffValue(isset($entityProperties[$key]) ? $entityProperties[$key] : null, isset($backendProperties[$key]) ? $backendProperties[$key] : null);
                        $this->outputFormatted("%s : %s", [$keyMarkup, $valueMarkup], 12);
                    }
                }
                $this->outputLine();
            }
            $this->outputLine();
        }

        if (count($indicesWithoutTypeInformation = $this->backendMappingBuilder->getIndicesWithoutTypeInformation())) {
            $this->outputFormatted("\x1b[43mNotice:\x1b[0m The following indices are present in the backend's mapping but having no type configuration, can hence be regarded as garbage:");
            foreach ($indicesWithoutTypeInformation as $indexName) {
                $this->outputFormatted('* %s', [$indexName], 4);
            }
        }
    }
666921
protected function getEntityInfo($sortableEntities, $entityName)
    {
        $relation = false;

        $entityConfig = $entityName ? array_get($sortableEntities, $entityName, false) : false;

        if (is_array($entityConfig)) {
            $entityClass = $entityConfig['entity'];
            $relation = !empty($entityConfig['relation']) ? $entityConfig['relation'] : false;
        } else {
            $entityClass = $entityConfig;
        }

        return [$entityClass, $relation];
    }
1165062
public function buildEntityMapByObjectManagerName($objectManagerName)
    {
        $entityClassNames = $this->getEntityClassNamesByObjectManagerName($objectManagerName);

        $listEntityInterfaces = $this->buildListEntityInterfaces($entityClassNames);

        $map = [];

        $entityManager = $this->getEntityManager();
        foreach ($listEntityInterfaces as $currentInterface) {
            if ($entityManager->hasEntityClassByInterface($currentInterface)) {
                $map[$currentInterface] = $entityManager->getEntityClassByInterface($currentInterface);
            }
        }

        return $map;
    }
1187948
public function getFieldValue($entity, $fieldName)
    {
        if ($this->fieldMappings[$fieldName]['direct']) {
            return $this->reflFields[$fieldName]->getValue($entity);
        } else {
            if (!array_key_exists('getMethod', $this->fieldMappings[$fieldName])) {
                $this->fieldMappings[$fieldName]['getMethod'] = $this->inferGetter($fieldName);
            }
            $getter = $this->fieldMappings[$fieldName]['getMethod'];

            if ($this->reflClass->hasMethod($getter)) {
                return call_user_func(array($entity, $getter));
            } else {
                throw MappingException::fieldGetMethodDoesNotExist($this->name, $fieldName, $getter);
            }
        }
    }
586314
private function index($entity)
    {
        //Get meta info
        $meta = $this->getMeta($entity);

        //Get class name
        $class = $meta->getName();

        //Get the index from the repository
        $index = $this->getRepository($class)->getIndex();

        //Get the loaded node if it's a node
        if($meta instanceof NodeMeta)
        {
            $en = $this->getEverymanNode($entity);
        }

        //Otherwise, get the loaded relation
        else
        {
            $en = $this->getEverymanRelation($entity);
        }

        //Add all indexed properties
        foreach ($meta->getIndexedProperties() as $property)
        {
            $index->add($en, $property->getName(), $property->getValue($entity));
        }

        //Get the primary key
        $pk = $meta->getPrimaryKey();
        $name = $pk->getName();
        $id = $pk->getValue($entity);

        //Add the primary key to the index
        $index->add($en, $name, $id);
    }
554151
private function mapFieldName($fieldName)
    {
        if (isset($this->fieldNameMapping[$fieldName])) {
            $fieldName = $this->fieldNameMapping[$fieldName];
        }

        return $fieldName;
    }
1299093
public function getRepository($entityName)
    {
        $entityName = ltrim($entityName, '\\');
        if (isset($this->repositories[$entityName])) {
            return $this->repositories[$entityName];
        }

        $metadata = $this->getClassMetadata($entityName);
        $customRepositoryClassName = $metadata->customRepositoryClassName;

        if ($customRepositoryClassName !== null) {
            $repository = new $customRepositoryClassName($this, $metadata);
        } else {
            $repository = new XmlEntityRepository($this, $metadata);
        }

        $this->repositories[$entityName] = $repository;

        return $repository;
    }
695864
private function getEntityByClass($className)
    {
        if (!isset($this->entities[ $className ])) {
            $entity                       = new Entity($this, $className);
            $this->entities[ $className ] = $entity;

            $this->metadataDriver->readEntityMetadata($entity);
        }

        return $this->entities[ $className ];
    }
1323777
public function vaidateEntityConfig($entityName, $entity)
  {

    if (empty($entity->requests))
    {
      $this->printMessage(
        "Entity: {$entityName} doesn't have any requests set up for it."
        . " Controllers, exceptions, requests will be skipped."
      );
    }
    else
    {
      foreach ($entity->requests as $requestMethod => $actions)
      {
        foreach ($actions as $actionName => $action)
        {
          if (empty($action->url))
          {
            $this->printMessage(
              "Entity: {$entityName}::{$actionName} doesn't have a url set."
              . " This action will be skipped."
            );
            $entity->requests->$requestMethod->$actionName = false;
          }

          if (!empty($action->throws))
          {
            if (!empty($action->throws->extends))
            {
              if (!class_exists("Phrest\\API\\Exceptions\\" . $action->throws->extends))
              {
                $this->printMessage(
                  "Entity: {$entityName}::{$actionName} Unknown exception: "
                  . "Phrest\\API\\Exceptions\\" . $action->throws->extends
                  . ". This extension will be removed."
                );
                $action->throws->extends = false;
              }
            }
          }
        }
      }
    }

    if (empty($entity->model))
    {
      $this->printMessage(
        "Entity: {$entityName} doesn't have a model definition. Models and "
        . "responses will be skipped."
      );
    }

    return $entity;
  }
524223
public function getFieldMappingByDbFieldName(string $dbFieldName) : array
    {
        foreach ($this->fieldMappings as $mapping) {
            if ($mapping['name'] === $dbFieldName) {
                return $mapping;
            }
        }

        throw MappingException::mappingNotFoundByDbName($this->name, $dbFieldName);
    }
617401
protected function loadCollaction($name, $entityName, $fields)
    {
        $em = $this->getContainer()->get('doctrine')->getManager();
        $entityRepository = $em->getRepository($entityName);

        $meta = $em->getClassMetadata($entityName);
        $identifier = $meta->getSingleIdentifierFieldName();
        $identifierMethodName = 'get'.ucfirst($identifier);

        $collection = $entityRepository->findAll();

        $result = array();

        foreach ($collection as $item) {
            $element = array();

            foreach ($fields as $fieldName => $attributes) {
                $methodName = 'get'.ucfirst($fieldName);
                $fieldValue = $item->$methodName();

                $value = null;

                if (is_object($fieldValue)) {
                    if (get_class($fieldValue) === 'DateTime') {
                        $value = array('type' => 'DateTime', 'name' => $fieldValue->format('r'));
                    } elseif (array_key_exists('targetEntity', $attributes)) {
                        $targetClassName = $meta->associationMappings[$fieldName]['targetEntity'];
                        $targetEntityProvider = new EntityProvider($targetClassName);

                        $targetMethodName = 'get'.ucfirst($em->getClassMetadata($targetClassName)->identifier[0]);
                        $value = array(
                            'type' => 'reference',
                            'name' => $targetEntityProvider->getName().'_'.$fieldValue->$targetMethodName(),
                        );
                    } else {
                        throw new \Exception('aaa');
                    }
                } else {
                    $value = $fieldValue;
                }

                $element[$fieldName] = $value;
            }

            $result[$name.'_'.$item->$identifierMethodName()] = $element;
        }

        return $result;
    }
267941
public function validate($entity, $entityName = null)
    {
        $entityName = $entityName ?: 'root';

        // Validate root type
        $this->validateType($entity, $this->schema, $entityName);

        return $this;
    }
621632
public function fulltextIndexExists($tableName)
    {
        // Special case for no full text index support
        if (!$this->database->fullTextEnabled()) {
            return null;
        }

        return (bool) $this->preparedQuery("
			SELECT 1 FROM sys.fulltext_indexes i
			JOIN sys.objects o ON i.object_id = o.object_id
			WHERE o.name = ?",
            array($tableName)
        )->value();
    }