Skip to content

Commit

Permalink
Add namespaces for metadata related to the kernel namespace (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
gisostallenberg authored Apr 30, 2020
1 parent d7ac832 commit e26e5eb
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
55 changes: 55 additions & 0 deletions DependencyInjection/Compiler/MetadataFileLocatorPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

/*
* This file is part of the MassiveSearchBundle
*
* (c) MASSIVE ART WebServices GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Massive\Bundle\SearchBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* Compiler pass to add additional paths based on the kernel namespace.
*/
class MetadataFileLocatorPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition(
'massive_search.metadata.file_locator'
)) {
return;
}
$kernelClass = $container->getDefinition('kernel')->getClass();
if (empty($kernelClass)) {
return;
}
if ('App\\Kernel' === $kernelClass) {
return; // App paths already set in MassiveSearchExtension::loadMetadata
}

$projectNamespace = substr($kernelClass, 0, strrpos($kernelClass, '\\'));
$kernelProjectDir = $container->getParameter('kernel.project_dir');
$kernelDirectory = dirname((new \ReflectionClass($kernelClass))->getFileName());

$fileLocator = $container->getDefinition('massive_search.metadata.file_locator');
$metadataPaths = $fileLocator->getArgument(0);

foreach (['Entity', 'Document', 'Model'] as $entityNamespace) {
if (!file_exists($kernelDirectory . '/' . $entityNamespace)) {
continue;
}

$namespace = $projectNamespace . '\\' . $entityNamespace;
$metadataPaths[$namespace] = $kernelProjectDir . '/config/massive-search';
}

$fileLocator->replaceArgument(0, $metadataPaths);
}
}
2 changes: 2 additions & 0 deletions MassiveSearchBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Massive\Bundle\SearchBundle\DependencyInjection\Compiler\ConverterPass;
use Massive\Bundle\SearchBundle\DependencyInjection\Compiler\MetadataDriverPass;
use Massive\Bundle\SearchBundle\DependencyInjection\Compiler\MetadataFileLocatorPass;
use Massive\Bundle\SearchBundle\DependencyInjection\Compiler\MetadataProviderPass;
use Massive\Bundle\SearchBundle\DependencyInjection\Compiler\ReindexProviderPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand All @@ -27,5 +28,6 @@ public function build(ContainerBuilder $container)
$container->addCompilerPass(new MetadataProviderPass());
$container->addCompilerPass(new ConverterPass());
$container->addCompilerPass(new ReindexProviderPass());
$container->addCompilerPass(new MetadataFileLocatorPass());
}
}

0 comments on commit e26e5eb

Please sign in to comment.