Load doctrine class map

@param Finder $finder Mapping finder
@return array
168146
private function loadDoctrineClassMap(Finder $finder)
    {
        $classMap = [];
        foreach ($finder as $file) {
            $classMap = array_merge(
                $classMap,
                Yaml::parseFile($file)
            );
        }

        // filter out superclasses
        $classMap = array_filter(
            $classMap,
            function ($classEntry) {
                return (!isset($classEntry['type']) || $classEntry['type'] != 'mappedSuperclass');
            }
        );

        return $classMap;
    }
662649
public function loadResourceNamespaceMap($rootDir, array $resources)
    {
        return array_map(function($resource) use ($rootDir) {
            return $rootDir . '/' . trim($resource, '/') . '/';
        }, $resources);
    }
1308656
public function loadClassMetadata(LoadClassMetadataEventArgs $args) {
		/**
		 * @var \Doctrine\ORM\Mapping\ClassMetadataInfo $classMetadata
		 */
		$classMetadata = $args->getClassMetadata();
		
		// Do not re-apply the prefix in an inheritance hierarchy.
		if($classMetadata->isInheritanceTypeSingleTable() && !$classMetadata->isRootEntity()) {
			return;
		}
		
		$prefix = $classMetadata->namespace;
		if(!preg_match('/([^\\\\]+)Bundle/i', $classMetadata->namespace, $prefix)) {
			return;
		}

		$prefix = strtolower($prefix[1]) . '_';
		
		$classMetadata->setPrimaryTable(array(
			'name' => $prefix . $classMetadata->getTableName() 
		));

		if($args->getEntityManager()->getConnection()->getDatabasePlatform() instanceof SqlitePlatform && array_key_exists('indexes', $classMetadata->table)) {
			$indexes = array();
			foreach($classMetadata->table['indexes'] as $name => $params) {
				$indexes[$prefix . $classMetadata->getTableName() . '_' . $name] = $params;
			}
			$classMetadata->table['indexes'] = $indexes;
		}
		
		foreach($classMetadata->getAssociationMappings() as $fieldName => $mapping) {
			if($mapping['type'] == \Doctrine\ORM\Mapping\ClassMetadataInfo::MANY_TO_MANY && isset($classMetadata->associationMappings[$fieldName]['joinTable']['name'])) {
				if(isset($classMetadata->associationMappings[$fieldName]['joinTable']['prefixed']) && $classMetadata->associationMappings[$fieldName]['joinTable']['prefixed']) {
					continue;
				}
				
				$mappedTableName = $classMetadata->associationMappings[$fieldName]['joinTable']['name'];
				$classMetadata->associationMappings[$fieldName]['joinTable']['name'] = $prefix . $mappedTableName;
				$classMetadata->associationMappings[$fieldName]['joinTable']['prefixed'] = true;
			}
		}
	}
1299413
public function parseFiles(
        Finder $finder,
        Reader $reader,
        WorkerCollection $workerCollection
    )
    {

        /**
         * Every file found is parsed
         */
        foreach ($finder as $file) {

            /**
             * File is accepted to be parsed
             */
            $classNamespace = $this->getFileClassNamespace($file->getRealpath());
            $reflectionClass = new ReflectionClass($classNamespace);
            $classAnnotations = $reader->getClassAnnotations($reflectionClass);

            /**
             * Every annotation found is parsed
             */
            foreach ($classAnnotations as $annotation) {

                /**
                 * Annotation is only laoded if is typeof WorkAnnotation
                 */
                if ($annotation instanceof WorkAnnotation) {

                    /**
                     * Creates new Worker element with all its Job data
                     */
                    $worker = new Worker($annotation, $reflectionClass, $reader, $this->servers, $this->defaultSettings);
                    $workerCollection->add($worker);
                }
            }
        }

        return $this;
    }
139438
private function loadEntityMapping(): array
	{
		$mapping = [];

		$builder = $this->getContainerBuilder();
		$repositories = $builder->findByType(IRepository::class);

		foreach ($repositories as $repository) {
			/** @var string $repositoryClass */
			$repositoryClass = $repository->getEntity();

			// Skip invalid repositoryClass name
			if (!class_exists($repositoryClass)) {
				throw new ServiceCreationException(sprintf("Repository class '%s' not found", $repositoryClass));
			}

			// Skip invalid subtype ob IRepository
			if (!method_exists($repositoryClass, 'getEntityClassNames')) continue;

			// Append mapping [repository => [entity1, entity2, entityN]
			foreach ($repositoryClass::getEntityClassNames() as $entity) {
				$mapping[$entity] = $repositoryClass;
			}
		}

		return $mapping;
	}
795657
private function loadTranslatableMetadata(\ReflectionClass $class) {
        $classMetadata = new TranslatableMetadata($class->name);

        foreach ($class->getProperties() as $property) {
            if ($property->class !== $class->name) {
                continue;
            }

            $propertyMetadata = new PropertyMetadata($class->name, $property->getName());

            if ($this->reader->getPropertyAnnotation($property, 'Prezent\\Doctrine\\Translatable\\Annotation\\CurrentLocale')) {
                $classMetadata->currentLocale = $propertyMetadata;
                $classMetadata->addPropertyMetadata($propertyMetadata);
            }
            
            if ($this->reader->getPropertyAnnotation($property, 'Prezent\\Doctrine\\Translatable\\Annotation\\FallbackLocale')) {
                $classMetadata->fallbackLocale = $propertyMetadata;
                $classMetadata->addPropertyMetadata($propertyMetadata);
            }
            
            if ($annot = $this->reader->getPropertyAnnotation($property, 'Prezent\\Doctrine\\Translatable\\Annotation\\Translations')) {
                $classMetadata->targetEntity = $annot->targetEntity;
                $classMetadata->translations = $propertyMetadata;
                $classMetadata->addPropertyMetadata($propertyMetadata);
            }
        }

        return $classMetadata;
    }
602248
protected function parseRoutes(Mapper $mapper)
    {
        foreach ($mapper->getClassMap() as &$mapping) {
            $mappingClass = new \ReflectionClass($mapping);

            $this->setUrlWithReflection($mapping, $mappingClass, 'resourceUrlPattern');
            $this->setUrlWithReflection($mapping, $mappingClass, 'selfUrl');
            $mappingProperty = $mappingClass->getProperty('otherUrls');
            $mappingProperty->setAccessible(true);

            $otherUrls = (array) $mappingProperty->getValue($mapping);
            if (!empty($otherUrls)) {
                foreach ($otherUrls as &$url) {
                    if (!empty($url['name'])) {
                        $url = $this->calculateRoute($url);
                    }
                }
            }
            $mappingProperty->setValue($mapping, $otherUrls);

            $this->setJsonApiRelationships($mappingClass, $mapping);
        }

        return $mapper;
    }
1033931
public static function load()
    {
        if (!extension_loaded('opencensus')) {
            trigger_error('opencensus extension required to load Doctrine integrations.', E_USER_WARNING);
            return;
        }

        PDO::load();

        $persisterClass = (Version::compare('2.5.0') < 0)
            ? 'Doctrine\ORM\Persisters\Entity\BasicEntityPersister'    // Doctrine 2.5 or greater
            : 'Doctrine\ORM\Persisters\BasicEntityPersister';          // Doctrine 2.4 or earlier

        // public function load(array $criteria, $entity = null, $assoc = null, array $hints = array(),
        //      $lockMode = null, $limit = null, array $orderBy = null)
        opencensus_trace_method($persisterClass, 'load', function ($bep) {
            return [
                'name' => 'doctrine/load',
                'attributes' => ['entity' => $bep->getClassMetadata()->name],
                'kind' => Span::KIND_CLIENT
            ];
        });

        // public function loadAll(array $criteria = array(), array $orderBy = null, $limit = null, $offset = null)
        opencensus_trace_method($persisterClass, 'loadAll', function ($bep) {
            return [
                'name' => 'doctrine/loadAll',
                'attributes' => ['entity' => $bep->getClassMetadata()->name],
                'kind' => Span::KIND_CLIENT
            ];
        });

        // public int PDOConnection::exec(string $query)
        opencensus_trace_method(PDOConnection::class, 'exec', function ($scope, $query) {
            return [
                'name' => 'doctrine/exec',
                'attributes' => ['query' => $query],
                'kind' => Span::KIND_CLIENT
            ];
        });
    }
1215934
protected function loadEntities($entityManager) {
		foreach(glob($this->getPath().'/Entity/*.php') as $file) {
			$class = \Asgard\Common\Tools::loadClassFile($file);
			if(is_subclass_of($class, 'Asgard\Entity\Entity'))
				$entityManager->get($class);
		}
	}
831844
public function finderToArrayOfPaths(Finder $finder) : array
    {
        $result = array_map(
            function ($value) {
                /** @var SplFileInfo $value */
                return $value->getRelativePathname();
            },
            iterator_to_array($finder)
        );

        return array_values($result);
    }
228157
public function loadClassMetadata(LoadClassMetadataEventArgs $args)
    {
        $cm = $args->getClassMetadata();

        if (isset($this->classes[$cm->name])) {
            $mapping = [
                'targetEntity'  => $this->classes[$cm->name],
                'fieldName'     => 'data',
                'mappedBy'      => 'entity',
                'cascade'       => ['persist', 'remove'],
                'orphanRemoval' => true,
            ];

            $cm->mapOneToMany($mapping);
        } elseif (in_array($cm->name, $this->classes)) {
            $mapping = [
                'targetEntity' => array_search($cm->name, $this->classes),
                'fieldName'    => 'entity',
                'inversedBy'   => 'data',
            ];

            $cm->mapManyToOne($mapping);

            $cm->table['uniqueConstraints']['eav_data_idx'] = [
                'columns' => ['entity_id', 'key'],
            ];
        }
    }
362280
protected function getItemsOfDeletedFiles(Storage $storage, Finder $finder)
    {
        $items = [];
        // check of delete file for item
        foreach ($storage->getItems() as $item) {
            foreach ($finder as $file) {
                if (pathinfo($item->getPath(), PATHINFO_BASENAME) == $file->getFilename()) {
                    continue 2;
                }
            }
            $items[] = $item;
        }

        return $items;
    }
1278265
public function getMapperFor($className)
    {
        if (!$this->hasMapperFor($className)) {
            throw new MappingException(sprintf(
                'Class [%s] does not have a mapping configuration. '.
                'Make sure you create a Mapping class that extends either %s, %s or %s. '.
                'If you are using inheritance mapping, remember to create mappings '.
                'for every child of the inheritance tree.',
                $className,
                EntityMapping::class,
                EmbeddableMapping::class,
                MappedSuperClassMapping::class
            ));
        }

        return $this->mappers[$className];
    }
66095
private function parseNodes(Finder $finder): array
    {
        $this->eventDispatcher->dispatch(Events::PRE_NODES_PARSED, new PreNodesParsedEvent($finder));

        $nodes = array();
        foreach ($finder as $file) {
            $parser = $this->nodeParserResolver->resolve($file);
            if (null !== $parser) {
                try {
                    $node = $parser->parse($file);
                    $nodes[] = $node;
                    $this->eventDispatcher->dispatch(Events::NODE_PARSED, new NodeParsedEvent($node));
                } catch (ExtractionException $e) {
                    // at the moment, let's just ignore invalid node
                    // need to fix that with a better design
                }
            }
        }

        $this->eventDispatcher->dispatch(Events::POST_NODES_PARSED, new PostNodesParsedEvent($nodes));

        return $nodes;
    }
120188
public function analysePaths(Finder $finder)
    {
        $classes = [];
        foreach ($finder as $file) {
            $this->analyse($file, $classes);
        }

        return $classes;
    }
918176
public static function configureCache($cacheDriver)
    {
        $cache = null;

        switch (strtolower($cacheDriver['type'])) {
            case 'apc':
                $cache = new \Doctrine\Common\Cache\ApcCache();
                break;

            case 'xcache':
                $cache = new \Doctrine\Common\Cache\XcacheCache();
                break;

            case 'memcache':
                $cache = self::configureMemcacheCache($cacheDriver['host'], $cacheDriver['port']);
                break;

            case 'redis':
                $cache = self::configureRedisCache($cacheDriver['host'], $cacheDriver['port']);
                break;

            case 'array':
                $cache = new \Doctrine\Common\Cache\ArrayCache();
                break;
        }

        return $cache;
    }
844154
public function getMapper($mapperClass = null, array $options = [])
    {
        $mapperClass = $mapperClass ?? $this->mapper ?? $this->serviceAlias;

        if (!array_key_exists($mapperClass, $this->mappers)) {
            $this->setMapper($mapperClass, $options);
        }

        return $this->mappers[$mapperClass];
    }