Skip to content

Commit e26e5eb

Browse files
Add namespaces for metadata related to the kernel namespace (#144)
1 parent d7ac832 commit e26e5eb

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the MassiveSearchBundle
5+
*
6+
* (c) MASSIVE ART WebServices GmbH
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
12+
namespace Massive\Bundle\SearchBundle\DependencyInjection\Compiler;
13+
14+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
17+
/**
18+
* Compiler pass to add additional paths based on the kernel namespace.
19+
*/
20+
class MetadataFileLocatorPass implements CompilerPassInterface
21+
{
22+
public function process(ContainerBuilder $container)
23+
{
24+
if (!$container->hasDefinition(
25+
'massive_search.metadata.file_locator'
26+
)) {
27+
return;
28+
}
29+
$kernelClass = $container->getDefinition('kernel')->getClass();
30+
if (empty($kernelClass)) {
31+
return;
32+
}
33+
if ('App\\Kernel' === $kernelClass) {
34+
return; // App paths already set in MassiveSearchExtension::loadMetadata
35+
}
36+
37+
$projectNamespace = substr($kernelClass, 0, strrpos($kernelClass, '\\'));
38+
$kernelProjectDir = $container->getParameter('kernel.project_dir');
39+
$kernelDirectory = dirname((new \ReflectionClass($kernelClass))->getFileName());
40+
41+
$fileLocator = $container->getDefinition('massive_search.metadata.file_locator');
42+
$metadataPaths = $fileLocator->getArgument(0);
43+
44+
foreach (['Entity', 'Document', 'Model'] as $entityNamespace) {
45+
if (!file_exists($kernelDirectory . '/' . $entityNamespace)) {
46+
continue;
47+
}
48+
49+
$namespace = $projectNamespace . '\\' . $entityNamespace;
50+
$metadataPaths[$namespace] = $kernelProjectDir . '/config/massive-search';
51+
}
52+
53+
$fileLocator->replaceArgument(0, $metadataPaths);
54+
}
55+
}

MassiveSearchBundle.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Massive\Bundle\SearchBundle\DependencyInjection\Compiler\ConverterPass;
1515
use Massive\Bundle\SearchBundle\DependencyInjection\Compiler\MetadataDriverPass;
16+
use Massive\Bundle\SearchBundle\DependencyInjection\Compiler\MetadataFileLocatorPass;
1617
use Massive\Bundle\SearchBundle\DependencyInjection\Compiler\MetadataProviderPass;
1718
use Massive\Bundle\SearchBundle\DependencyInjection\Compiler\ReindexProviderPass;
1819
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -27,5 +28,6 @@ public function build(ContainerBuilder $container)
2728
$container->addCompilerPass(new MetadataProviderPass());
2829
$container->addCompilerPass(new ConverterPass());
2930
$container->addCompilerPass(new ReindexProviderPass());
31+
$container->addCompilerPass(new MetadataFileLocatorPass());
3032
}
3133
}

0 commit comments

Comments
 (0)