forked from ongr-io/ElasticsearchBundle
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Repository creation into own compiler pass (#14)
- Loading branch information
1 parent
e168774
commit 9a1a3c0
Showing
4 changed files
with
75 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the ONGR package. | ||
* | ||
* (c) NFQ Technologies UAB <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace ONGR\ElasticsearchBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
use Symfony\Component\HttpKernel\Kernel; | ||
|
||
/** | ||
* Compiles elastic search data. | ||
*/ | ||
class RepositoryPass implements CompilerPassInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
$managers = $container->getParameter('es.managers'); | ||
|
||
$collector = $container->get('es.metadata_collector'); | ||
|
||
foreach ($managers as $managerName => $manager) { | ||
$mappings = $collector->getMappings($manager['mappings']); | ||
|
||
// Building repository services. | ||
foreach ($mappings as $repositoryType => $repositoryDetails) { | ||
$repositoryDefinition = new Definition( | ||
'ONGR\ElasticsearchBundle\Service\Repository', | ||
[$repositoryDetails['namespace']] | ||
); | ||
$repositoryDefinition->setPublic(true); | ||
|
||
if (isset($repositoryDetails['directory_name']) && $managerName == 'default') { | ||
$container->get('es.document_finder')->setDocumentDir($repositoryDetails['directory_name']); | ||
} | ||
|
||
$repositoryDefinition->setFactory( | ||
[ | ||
new Reference(sprintf('es.manager.%s', $managerName)), | ||
'getRepository', | ||
] | ||
); | ||
|
||
$repositoryId = sprintf('es.manager.%s.%s', $managerName, $repositoryType); | ||
$container->setDefinition($repositoryId, $repositoryDefinition); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters