public function getBundleMapping($name, $config = [])
    {
        if (!is_string($name)) {
            throw new \LogicException('getBundleMapping() in the Metadata collector expects a string argument only!');
        }

        $cacheName =  'ongr.metadata.mapping.' . md5($name.serialize($config));

        $this->enableCache && $mappings = $this->cache->fetch($cacheName);

        if (isset($mappings) && false !== $mappings) {
            return $mappings;
        }

        $mappings = [];
        $documentDir = isset($config['document_dir']) ? $config['document_dir'] : $this->finder->getDocumentDir();

        // Handle the case when single document mapping requested
        // Usage od ":" in name is deprecated. This if is only for BC.
        if (strpos($name, ':') !== false) {
            list($bundle, $documentClass) = explode(':', $name);
            $documents = $this->finder->getBundleDocumentClasses($bundle);
            $documents = in_array($documentClass, $documents) ? [$documentClass] : [];
        } else {
            $documents = $this->finder->getBundleDocumentClasses($name, $documentDir);
            $bundle = $name;
        }

        $bundleNamespace = $this->finder->getBundleClass($bundle);
        $bundleNamespace = substr($bundleNamespace, 0, strrpos($bundleNamespace, '\\'));

        if (!count($documents)) {
            return [];
        }

        // Loop through documents found in bundle.
        foreach ($documents as $document) {
            $documentReflection = new \ReflectionClass(
                $bundleNamespace .
                '\\' . str_replace('/', '\\', $documentDir) .
                '\\' . $document
            );

            try {
                $documentMapping = $this->getDocumentReflectionMapping($documentReflection);
                if (!$documentMapping) {
                    continue;
                }
            } catch (MissingDocumentAnnotationException $exception) {
                // Not a document, just ignore
                continue;
            }

            if (!array_key_exists($documentMapping['type'], $mappings)) {
                $documentMapping['bundle'] = $bundle;
                $mappings = array_merge($mappings, [$documentMapping['type'] => $documentMapping]);
            } else {
                throw new \LogicException(
                    $bundle . ' has 2 same type names defined in the documents. ' .
                    'Type names must be unique!'
                );
            }
        }

        $this->enableCache && $this->cache->save($cacheName, $mappings);

        return $mappings;
    }
public function getBundleMapping($name, $config = [])
    {
        if (!is_string($name)) {
            throw new \LogicException('getBundleMapping() in the Metadata collector expects a string argument only!');
        }

        $cacheName =  'ongr.metadata.mapping.' . md5($name.serialize($config));

        $this->enableCache && $mappings = $this->cache->fetch($cacheName);

        if (isset($mappings) && false !== $mappings) {
            return $mappings;
        }

        $mappings = [];
        $documentDir = isset($config['document_dir']) ? $config['document_dir'] : $this->finder->getDocumentDir();

        // Handle the case when single document mapping requested
        // Usage od ":" in name is deprecated. This if is only for BC.
        if (strpos($name, ':') !== false) {
            list($bundle, $documentClass) = explode(':', $name);
            $documents = $this->finder->getBundleDocumentClasses($bundle);
            $documents = in_array($documentClass, $documents) ? [$documentClass] : [];
        } else {
            $documents = $this->finder->getBundleDocumentClasses($name, $documentDir);
            $bundle = $name;
        }

        $bundleNamespace = $this->finder->getBundleClass($bundle);
        $bundleNamespace = substr($bundleNamespace, 0, strrpos($bundleNamespace, '\\'));

        if (!count($documents)) {
            return [];
        }

        // Loop through documents found in bundle.
        foreach ($documents as $document) {
            $documentReflection = new \ReflectionClass(
                $bundleNamespace .
                '\\' . str_replace('/', '\\', $documentDir) .
                '\\' . $document
            );

            try {
                $documentMapping = $this->getDocumentReflectionMapping($documentReflection);
                if (!$documentMapping) {
                    continue;
                }
            } catch (MissingDocumentAnnotationException $exception) {
                // Not a document, just ignore
                continue;
            }

            if (!array_key_exists($documentMapping['type'], $mappings)) {
                $documentMapping['bundle'] = $bundle;
                $mappings = array_merge($mappings, [$documentMapping['type'] => $documentMapping]);
            } else {
                throw new \LogicException(
                    $bundle . ' has 2 same type names defined in the documents. ' .
                    'Type names must be unique!'
                );
            }
        }

        $this->enableCache && $this->cache->save($cacheName, $mappings);

        return $mappings;
    }
public function getBundleMapping ( $ name , $ config = [ ] ) { if ( ! is_string ( $ name ) ) { throw new \ LogicException ( 'getBundleMapping() in the Metadata collector expects a string argument only!' ) ; } $ cacheName = 'ongr.metadata.mapping.' . md5 ( $ name . serialize ( $ config ) ) ; $ this -> enableCache && $ mappings = $ this -> cache -> fetch ( $ cacheName ) ; if ( isset ( $ mappings ) && false !== $ mappings ) { return $ mappings ; } $ mappings = [ ] ; $ documentDir = isset ( $ config [ 'document_dir' ] ) ? $ config [ 'document_dir' ] : $ this -> finder -> getDocumentDir ( ) ; // Handle the case when single document mapping requested // Usage od ":" in name is deprecated. This if is only for BC. if ( strpos ( $ name , ':' ) !== false ) { list ( $ bundle , $ documentClass ) = explode ( ':' , $ name ) ; $ documents = $ this -> finder -> getBundleDocumentClasses ( $ bundle ) ; $ documents = in_array ( $ documentClass , $ documents ) ? [ $ documentClass ] : [ ] ; } else { $ documents = $ this -> finder -> getBundleDocumentClasses ( $ name , $ documentDir ) ; $ bundle = $ name ; } $ bundleNamespace = $ this -> finder -> getBundleClass ( $ bundle ) ; $ bundleNamespace = substr ( $ bundleNamespace , 0 , strrpos ( $ bundleNamespace , '\\' ) ) ; if ( ! count ( $ documents ) ) { return [ ] ; } // Loop through documents found in bundle. foreach ( $ documents as $ document ) { $ documentReflection = new \ ReflectionClass ( $ bundleNamespace . '\\' . str_replace ( '/' , '\\' , $ documentDir ) . '\\' . $ document ) ; try { $ documentMapping = $ this -> getDocumentReflectionMapping ( $ documentReflection ) ; if ( ! $ documentMapping ) { continue ; } } catch ( MissingDocumentAnnotationException $ exception ) { // Not a document, just ignore continue ; } if ( ! array_key_exists ( $ documentMapping [ 'type' ] , $ mappings ) ) { $ documentMapping [ 'bundle' ] = $ bundle ; $ mappings = array_merge ( $ mappings , [ $ documentMapping [ 'type' ] => $ documentMapping ] ) ; } else { throw new \ LogicException ( $ bundle . ' has 2 same type names defined in the documents. ' . 'Type names must be unique!' ) ; } } $ this -> enableCache && $ this -> cache -> save ( $ cacheName , $ mappings ) ; return $ mappings ; }
Searches for documents in the bundle and tries to read them.

@param string $name
@param array $config Bundle configuration

@return array Empty array on containing zero documents.
Searches for documents in the bundle and tries to read them .