Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1320 from formapro-forks/4x-to-master
4x to master
- Loading branch information
Showing
78 changed files
with
3,608 additions
and
87 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
85 changes: 85 additions & 0 deletions
85
DependencyInjection/Compiler/RegisterPagerProvidersPass.php
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,85 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the FOSElasticaBundle package. | ||
* | ||
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FOS\ElasticaBundle\DependencyInjection\Compiler; | ||
|
||
use FOS\ElasticaBundle\Provider\PagerProviderInterface; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
final class RegisterPagerProvidersPass implements CompilerPassInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
if (!$container->hasDefinition('fos_elastica.pager_provider_registry')) { | ||
return; | ||
} | ||
|
||
$defaultIndex = $container->getParameter('fos_elastica.default_index'); | ||
$registry = $container->getDefinition('fos_elastica.pager_provider_registry'); | ||
|
||
$registeredProviders = []; | ||
foreach ($container->findTaggedServiceIds('fos_elastica.pager_provider') as $id => $attributes) { | ||
foreach ($attributes as $attribute) { | ||
if (!isset($attribute['type'])) { | ||
throw new \InvalidArgumentException(sprintf('Elastica provider "%s" must specify the "type" attribute.', $id)); | ||
} | ||
|
||
$index = isset($attribute['index']) ? $attribute['index'] : $defaultIndex; | ||
$type = $attribute['type']; | ||
|
||
if (isset($registeredProviders[$index][$type])) { | ||
throw new \InvalidArgumentException(sprintf( | ||
'Cannot register provider "%s". The provider "%s" has been registered for same index "%s" and type "%s"', | ||
$id, | ||
$registeredProviders[$index][$type], | ||
$index, | ||
$type | ||
)); | ||
} | ||
|
||
$providerDef = $container->getDefinition($id); | ||
if (!$providerDef->getFactory()) { | ||
// You are on your own if you use a factory to create a provider. | ||
// It would fail in runtime if the factory does not return a proper provider. | ||
$this->assertClassImplementsPagerProviderInterface($id, $providerDef->getClass()); | ||
} | ||
|
||
$registeredProviders[$index][$type] = $id; | ||
} | ||
} | ||
|
||
$registry->replaceArgument(0, $registeredProviders); | ||
} | ||
|
||
/** | ||
* @param $providerId | ||
* @param $providerClass | ||
* | ||
* @throws \InvalidArgumentException if provider service does not implement PagerProviderInterface | ||
*/ | ||
private function assertClassImplementsPagerProviderInterface($providerId, $providerClass) | ||
{ | ||
$rc = new \ReflectionClass($providerClass); | ||
|
||
if (!$rc->implementsInterface(PagerProviderInterface::class)) { | ||
throw new \InvalidArgumentException(sprintf( | ||
'Elastica provider "%s" with class "%s" must implement "%s".', | ||
$providerId, | ||
$providerClass, | ||
PagerProviderInterface::class | ||
)); | ||
} | ||
} | ||
} |
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,85 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the FOSElasticaBundle package. | ||
* | ||
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FOS\ElasticaBundle\DependencyInjection\Compiler; | ||
|
||
use FOS\ElasticaBundle\Persister\ObjectPersisterInterface; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
final class RegisterPersistersPass implements CompilerPassInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
if (!$container->hasDefinition('fos_elastica.persister_registry')) { | ||
return; | ||
} | ||
|
||
$defaultIndex = $container->getParameter('fos_elastica.default_index'); | ||
$registry = $container->getDefinition('fos_elastica.persister_registry'); | ||
|
||
$registeredPersisters = []; | ||
foreach ($container->findTaggedServiceIds('fos_elastica.persister') as $id => $attributes) { | ||
foreach ($attributes as $attribute) { | ||
if (!isset($attribute['type'])) { | ||
throw new \InvalidArgumentException(sprintf('Elastica persister "%s" must specify the "type" attribute.', $id)); | ||
} | ||
|
||
$index = isset($attribute['index']) ? $attribute['index'] : $defaultIndex; | ||
$type = $attribute['type']; | ||
|
||
if (isset($registeredPersisters[$index][$type])) { | ||
throw new \InvalidArgumentException(sprintf( | ||
'Cannot register persister "%s". The persister "%s" has been registered for same index "%s" and type "%s"', | ||
$id, | ||
$registeredPersisters[$index][$type], | ||
$index, | ||
$type | ||
)); | ||
} | ||
|
||
$persisterDef = $container->getDefinition($id); | ||
if (!$persisterDef->getFactory()) { | ||
// You are on your own if you use a factory to create a persister. | ||
// It would fail in runtime if the factory does not return a proper persister. | ||
$this->assertClassImplementsPersisterInterface($id, $persisterDef->getClass()); | ||
} | ||
|
||
$registeredPersisters[$index][$type] = $id; | ||
} | ||
} | ||
|
||
$registry->replaceArgument(0, $registeredPersisters); | ||
} | ||
|
||
/** | ||
* @param $persisterId | ||
* @param $persisterClass | ||
* | ||
* @throws \InvalidArgumentException if persister service does not implement ObjectPersisterInterface | ||
*/ | ||
private function assertClassImplementsPersisterInterface($persisterId, $persisterClass) | ||
{ | ||
$rc = new \ReflectionClass($persisterClass); | ||
|
||
if (!$rc->implementsInterface(ObjectPersisterInterface::class)) { | ||
throw new \InvalidArgumentException(sprintf( | ||
'Elastica persister "%s" with class "%s" must implement "%s".', | ||
$persisterId, | ||
$persisterClass, | ||
ObjectPersisterInterface::class | ||
)); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.