/** * Tests if correct namespace is returned. * * @param string $expectedNamespace * @param string $document * @param bool $testPath * * @dataProvider getTestData */ public function testDocumentDir($expectedNamespace, $document, $testPath = false) { $finder = new DocumentFinder($this->getBundles()); $this->assertEquals($expectedNamespace, $finder->getNamespace($document)); if ($testPath) { $this->assertGreaterThan(0, count($finder->getBundleDocumentPaths('AcmeBarBundle'))); } }
/** * Searches for documents in the bundle and tries to read them. * * @param string $bundle * * @return array Empty array on containing zero documents. */ public function getBundleMapping($bundle) { $mappings = []; $bundleNamespace = $this->finder->getBundleClass($bundle); $bundleNamespace = substr($bundleNamespace, 0, strrpos($bundleNamespace, '\\')); // Checks if is mapped document or bundle. if (strpos($bundle, ':') !== false) { $documents = []; } else { $documents = $this->finder->getBundleDocumentPaths($bundle); } // Loop through documents found in bundle. foreach ($documents as $document) { $documentReflection = new \ReflectionClass($bundleNamespace . '\\' . DocumentFinder::DOCUMENT_DIR . '\\' . pathinfo($document, PATHINFO_FILENAME)); $documentMapping = $this->getDocumentReflectionMapping($documentReflection); if (is_array($documentMapping) && isset($documentMapping['type'])) { $documentMapping['bundle'] = $bundle; $mappings = array_replace_recursive($mappings, [$documentMapping['type'] => $documentMapping]); } } return $mappings; }
/** * Searches for documents in the bundle and tries to read them. * * @param string $name * * @return array Empty array on containing zero documents. */ public function getBundleMapping($name) { if (!is_string($name)) { throw new \LogicException('getBundleMapping() in the Metadata collector expects a string argument only!'); } if (isset($this->mappings[$name])) { return $this->mappings[$name]; } // Checks if is mapped document or bundle. if (strpos($name, ':') !== false) { $bundleInfo = explode(':', $name); $bundle = $bundleInfo[0]; $documentClass = $bundleInfo[1]; $documents = $this->finder->getBundleDocumentPaths($bundle); $documents = array_filter($documents, function ($document) use($documentClass) { if (pathinfo($document, PATHINFO_FILENAME) == $documentClass) { return true; } }); } else { $documents = $this->finder->getBundleDocumentPaths($name); $bundle = $name; } $mappings = []; $this->finder->getBundleClass($bundle); if (!count($documents)) { return []; } // Loop through documents found in bundle. foreach ($documents as $document) { $namespace = $this->getFileNamespace($document); if (!$namespace) { continue; } $documentReflection = new \ReflectionClass($namespace . '\\' . pathinfo($document, PATHINFO_FILENAME)); $documentMapping = $this->getDocumentReflectionMapping($documentReflection); if (!array_key_exists('type', $documentMapping)) { 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->cacheBundle($name, $mappings); return $mappings; }
/** * Searches for documents in bundle and tries to read them. * * @param string $bundle * * @return array Empty array on containing zero documents. */ public function getBundleMapping($bundle) { $mappings = []; $this->proxyPaths = []; $bundleNamespace = $this->finder->getBundleClass($bundle); $bundleNamespace = substr($bundleNamespace, 0, strrpos($bundleNamespace, '\\')); $documentDir = str_replace('/', '\\', $this->finder->getDocumentDir()); // Loop through documents found in bundle. foreach ($this->finder->getBundleDocumentPaths($bundle) as $document) { $documentReflection = new \ReflectionClass($bundleNamespace . '\\' . $documentDir . '\\' . pathinfo($document, PATHINFO_FILENAME)); $documentMapping = $this->getDocumentReflectionMapping($documentReflection); if ($documentMapping !== null) { $mappings = array_replace_recursive($mappings, $documentMapping); } } return $mappings; }
/** * Tests if document paths are returned for fixture bundle. */ public function testGetBundleDocumentPaths() { $finder = new DocumentFinder($this->getContainer()->getParameter('kernel.bundles')); $this->assertGreaterThan(0, count($finder->getBundleDocumentPaths('AcmeBarBundle'))); }