From 00aa83df80e15b0d1ddc4354fa39b8f3125abb4c Mon Sep 17 00:00:00 2001 From: William DURAND Date: Tue, 20 Dec 2011 17:48:56 +0100 Subject: [PATCH] Fixed comments see https://github.com/Exercise/FOQElasticaBundle/pull/51 --- DependencyInjection/Configuration.php | 2 +- DependencyInjection/FOQElasticaExtension.php | 46 ++++++-------------- Propel/ElasticaToModelTransformer.php | 4 +- Propel/Provider.php | 2 +- README.md | 24 +++++----- 5 files changed, 30 insertions(+), 48 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index d0fd3f5..908cb2b 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -7,7 +7,7 @@ use Symfony\Component\Config\Definition\Builder\TreeBuilder; class Configuration { - protected $supportedDrivers = array('orm', 'mongodb', 'propel'); + private $supportedDrivers = array('orm', 'mongodb', 'propel'); /** * Generates the configuration tree. diff --git a/DependencyInjection/FOQElasticaExtension.php b/DependencyInjection/FOQElasticaExtension.php index 08dffc5..e813723 100644 --- a/DependencyInjection/FOQElasticaExtension.php +++ b/DependencyInjection/FOQElasticaExtension.php @@ -14,16 +14,15 @@ use InvalidArgumentException; class FOQElasticaExtension extends Extension { - protected $supportedProviderDrivers = array('mongodb', 'orm', 'propel'); protected $indexConfigs = array(); protected $typeFields = array(); protected $loadedDrivers = array(); public function load(array $configs, ContainerBuilder $container) { - $configuration = new Configuration(); - $processor = new Processor(); - $config = $processor->process($configuration->getConfigTree(), $configs); + $configuration = new Configuration(); + $processor = new Processor(); + $config = $processor->process($configuration->getConfigTree(), $configs); $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('config.xml'); @@ -42,9 +41,9 @@ class FOQElasticaExtension extends Extension $config['default_index'] = reset($keys); } - $clientIdsByName = $this->loadClients($config['clients'], $container); - $indexIdsByName = $this->loadIndexes($config['indexes'], $container, $clientIdsByName, $config['default_client']); - $indexDefsByName = array_map(function($id) use ($container) { + $clientIdsByName = $this->loadClients($config['clients'], $container); + $indexIdsByName = $this->loadIndexes($config['indexes'], $container, $clientIdsByName, $config['default_client']); + $indexDefsByName = array_map(function($id) use ($container) { return $container->getDefinition($id); }, $indexIdsByName); @@ -186,10 +185,6 @@ class FOQElasticaExtension extends Extension **/ protected function loadTypePersistenceIntegration(array $typeConfig, ContainerBuilder $container, Definition $typeDef, $indexName, $typeName) { - if (!in_array($typeConfig['driver'], $this->supportedProviderDrivers)) { - throw new InvalidArgumentException(sprintf('The provider driver "%s" is not supported', $typeConfig['driver'])); - } - $this->loadDriver($container, $typeConfig['driver']); $elasticaToModelTransformerId = $this->loadElasticaToModelTransformer($typeConfig, $container, $indexName, $typeName); @@ -203,7 +198,7 @@ class FOQElasticaExtension extends Extension if (isset($typeConfig['finder'])) { $this->loadTypeFinder($typeConfig, $container, $elasticaToModelTransformerId, $typeDef, $indexName, $typeName); } - if ('propel' !== $typeConfig['driver'] && isset($typeConfig['listener'])) { + if (isset($typeConfig['listener'])) { $this->loadTypeListener($typeConfig, $container, $objectPersisterId, $typeDef, $indexName, $typeName); } } @@ -218,11 +213,7 @@ class FOQElasticaExtension extends Extension $serviceDef = new DefinitionDecorator($abstractId); // Doctrine has a mandatory service as first argument - if ('propel' === $typeConfig['driver']) { - $argPos = 0; - } else { - $argPos = 1; - } + $argPos = ('propel' === $typeConfig['driver']) ? 0 : 1; $serviceDef->replaceArgument($argPos, $typeConfig['model']); $serviceDef->replaceArgument($argPos + 1, array( @@ -275,25 +266,16 @@ class FOQElasticaExtension extends Extension $providerDef->replaceArgument(0, $typeDef); // Doctrine has a mandatory service as second argument - if ('propel' === $typeConfig['driver']) { - $argPos = 1; - } else { - $argPos = 2; - } + $argPos = ('propel' === $typeConfig['driver']) ? 1 : 2; $providerDef->replaceArgument($argPos, new Reference($objectPersisterId)); $providerDef->replaceArgument($argPos + 1, $typeConfig['model']); - if ('propel' === $typeConfig['driver']) { - $options = array( - 'batch_size' => $typeConfig['provider']['batch_size'], - ); - } else { - $options = array( - 'query_builder_method' => $typeConfig['provider']['query_builder_method'], - 'batch_size' => $typeConfig['provider']['batch_size'], - 'clear_object_manager' => $typeConfig['provider']['clear_object_manager'] - ); + $options = array('batch_size' => $typeConfig['provider']['batch_size']); + + if ('propel' !== $typeConfig['driver']) { + $options['query_builder_method'] = $typeConfig['provider']['query_builder_method']; + $options['clear_object_manager'] = $typeConfig['provider']['clear_object_manager']; } $providerDef->replaceArgument($argPos + 2, $options); diff --git a/Propel/ElasticaToModelTransformer.php b/Propel/ElasticaToModelTransformer.php index a9af9fa..92f8142 100644 --- a/Propel/ElasticaToModelTransformer.php +++ b/Propel/ElasticaToModelTransformer.php @@ -28,7 +28,7 @@ class ElasticaToModelTransformer implements ElasticaToModelTransformerInterface */ protected $options = array( 'hydrate' => true, - 'identifier' => 'id' + 'identifier' => 'id' ); /** @@ -49,7 +49,7 @@ class ElasticaToModelTransformer implements ElasticaToModelTransformerInterface * * @param array of elastica objects * @return array - **/ + */ public function transform(array $elasticaObjects) { $ids = array_map(function($elasticaObject) { diff --git a/Propel/Provider.php b/Propel/Provider.php index 814e4ea..46d28a2 100644 --- a/Propel/Provider.php +++ b/Propel/Provider.php @@ -63,7 +63,7 @@ class Provider implements ProviderInterface $objects = $queryClass::create() ->limit($this->options['batch_size']) ->offset($offset) - ->find(); + ->find(); $this->objectPersister->insertMany($objects->getArrayCopy()); diff --git a/README.md b/README.md index 8870193..c9c1a1e 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ Most of the time, you will need only one. #### Declare an index -Elasticsearch index is comparable to doctrine entity manager. +Elasticsearch index is comparable to Doctrine entity manager. Most of the time, you will need only one. foq_elastica: @@ -121,7 +121,7 @@ Our index is now available as a service: `foq_elastica.index.website`. It is an #### Declare a type -Elasticsearch type is comparable to doctrine entity repository. +Elasticsearch type is comparable to Doctrine entity repository. foq_elastica: clients: @@ -148,12 +148,12 @@ It applies the configured mappings to the types. This command needs providers to insert new documents in the elasticsearch types. There are 2 ways to create providers. -If your elasticsearch type matches a doctrine repository or a Propel query, go for the persistence automatic provider. +If your elasticsearch type matches a Doctrine repository or a Propel query, go for the persistence automatic provider. Or, for complete flexibility, go for manual provider. #### Persistence automatic provider -If we want to index the entities from a doctrine repository or a Propel query, +If we want to index the entities from a Doctrine repository or a Propel query, some configuration will let ElasticaBundle do it for us. foq_elastica: @@ -173,9 +173,9 @@ some configuration will let ElasticaBundle do it for us. model: Application\UserBundle\Entity\User provider: -Two drivers are actually supported: orm, mongodb, and propel. +Three drivers are actually supported: orm, mongodb, and propel. -##### Use a custom doctrine query builder +##### Use a custom Doctrine query builder You can control which entities will be indexed by specifying a custom query builder method. @@ -185,7 +185,7 @@ You can control which entities will be indexed by specifying a custom query buil provider: query_builder_method: createIsActiveQueryBuilder -Your repository must implement this method and return a doctrine query builder. +Your repository must implement this method and return a Doctrine query builder. > **Propel** doesn't support this feature yet. @@ -267,9 +267,9 @@ You can just use the index and type Elastica objects, provided as services, to p #### Doctrine finder -If your elasticsearch type is bound to a doctrine entity repository or a Propel query, +If your elasticsearch type is bound to a Doctrine entity repository or a Propel query, you can get your entities instead of Elastica results when you perform a search. -Declare that you want a doctrine/propel finder in your configuration: +Declare that you want a Doctrine/Propel finder in your configuration: foq_elastica: clients: @@ -305,8 +305,8 @@ You can even get paginated results! ### Realtime, selective index update -If you use the doctrine integration, you can let ElasticaBundle update the indexes automatically -when an object is added, updated or removed. It uses doctrine lifecycle events. +If you use the Doctrine integration, you can let ElasticaBundle update the indexes automatically +when an object is added, updated or removed. It uses Doctrine lifecycle events. Declare that you want to update the index in real time: foq_elastica: @@ -324,7 +324,7 @@ Declare that you want to update the index in real time: model: Application\UserBundle\Entity\User listener: # by default, listens to "insert", "update" and "delete" -Now the index is automatically updated each time the state of the bound doctrine repository changes. +Now the index is automatically updated each time the state of the bound Doctrine repository changes. No need to repopulate the whole "user" index when a new `User` is created. You can also choose to only listen for some of the events: