Merge branch '3.1.x'
This commit is contained in:
commit
559b14b4a5
|
@ -3,7 +3,6 @@
|
|||
namespace FOS\ElasticaBundle\Command;
|
||||
|
||||
use FOS\ElasticaBundle\Event\IndexPopulateEvent;
|
||||
use FOS\ElasticaBundle\Event\PopulateEvent;
|
||||
use FOS\ElasticaBundle\Event\TypePopulateEvent;
|
||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||
use Symfony\Component\Console\Helper\DialogHelper;
|
||||
|
@ -16,7 +15,7 @@ use FOS\ElasticaBundle\Resetter;
|
|||
use Symfony\Component\Console\Helper\ProgressBar;
|
||||
|
||||
/**
|
||||
* Populate the search index
|
||||
* Populate the search index.
|
||||
*/
|
||||
class PopulateCommand extends ContainerAwareCommand
|
||||
{
|
||||
|
@ -181,8 +180,8 @@ class PopulateCommand extends ContainerAwareCommand
|
|||
* Refreshes an index.
|
||||
*
|
||||
* @param OutputInterface $output
|
||||
* @param string $index
|
||||
* @param bool $postPopulate
|
||||
* @param string $index
|
||||
* @param bool $postPopulate
|
||||
*/
|
||||
private function refreshIndex(OutputInterface $output, $index, $postPopulate = true)
|
||||
{
|
||||
|
|
|
@ -21,9 +21,10 @@ class ProgressClosureBuilder
|
|||
* line.
|
||||
*
|
||||
* @param OutputInterface $output
|
||||
* @param string $action
|
||||
* @param string $index
|
||||
* @param string $type
|
||||
* @param string $action
|
||||
* @param string $index
|
||||
* @param string $type
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
public function build(OutputInterface $output, $action, $index, $type)
|
||||
|
@ -58,9 +59,10 @@ class ProgressClosureBuilder
|
|||
* methods to support what we need.
|
||||
*
|
||||
* @param OutputInterface $output
|
||||
* @param string $action
|
||||
* @param string $index
|
||||
* @param string $type
|
||||
* @param string $action
|
||||
* @param string $index
|
||||
* @param string $type
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
private function buildLegacy(OutputInterface $output, $action, $index, $type)
|
||||
|
|
|
@ -10,7 +10,7 @@ use FOS\ElasticaBundle\IndexManager;
|
|||
use FOS\ElasticaBundle\Resetter;
|
||||
|
||||
/**
|
||||
* Reset search indexes
|
||||
* Reset search indexes.
|
||||
*/
|
||||
class ResetCommand extends ContainerAwareCommand
|
||||
{
|
||||
|
|
|
@ -11,7 +11,7 @@ use Elastica\Query;
|
|||
use Elastica\Result;
|
||||
|
||||
/**
|
||||
* Searches a type
|
||||
* Searches a type.
|
||||
*/
|
||||
class SearchCommand extends ContainerAwareCommand
|
||||
{
|
||||
|
|
|
@ -53,9 +53,9 @@ class IndexConfig
|
|||
/**
|
||||
* Constructor expects an array as generated by the Container Configuration builder.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $name
|
||||
* @param TypeConfig[] $types
|
||||
* @param array $config
|
||||
* @param array $config
|
||||
*/
|
||||
public function __construct($name, array $types, array $config)
|
||||
{
|
||||
|
@ -92,7 +92,9 @@ class IndexConfig
|
|||
|
||||
/**
|
||||
* @param string $typeName
|
||||
*
|
||||
* @return TypeConfig
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function getType($typeName)
|
||||
|
|
|
@ -20,6 +20,7 @@ interface ManagerInterface
|
|||
* Returns configuration for an index.
|
||||
*
|
||||
* @param $index
|
||||
*
|
||||
* @return IndexConfig
|
||||
*/
|
||||
public function getIndexConfiguration($index);
|
||||
|
@ -36,6 +37,7 @@ interface ManagerInterface
|
|||
*
|
||||
* @param string $index
|
||||
* @param string $type
|
||||
*
|
||||
* @return TypeConfig
|
||||
*/
|
||||
public function getTypeConfiguration($index, $type);
|
||||
|
|
|
@ -17,6 +17,7 @@ use FOS\ElasticaBundle\Annotation\Search as BaseSearch;
|
|||
* Annotation class for setting search repository.
|
||||
*
|
||||
* @Annotation
|
||||
*
|
||||
* @deprecated Use FOS\ElasticaBundle\Annotation\Search instead
|
||||
* @Target("CLASS")
|
||||
*/
|
||||
|
|
|
@ -57,6 +57,7 @@ class ContainerSource implements SourceInterface
|
|||
* Builds TypeConfig objects for each type.
|
||||
*
|
||||
* @param array $config
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getTypes($config)
|
||||
|
|
|
@ -55,6 +55,7 @@ class RegisterProvidersPass implements CompilerPassInterface
|
|||
* Returns whether the class implements ProviderInterface.
|
||||
*
|
||||
* @param string $class
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private function isProviderImplementation($class)
|
||||
|
|
|
@ -31,7 +31,7 @@ class TransformerPass implements CompilerPassInterface
|
|||
throw new InvalidArgumentException('The Transformer must have both a type and an index defined.');
|
||||
}
|
||||
|
||||
$transformers[$tag['index']][$tag['type']]= new Reference($id);
|
||||
$transformers[$tag['index']][$tag['type']] = new Reference($id);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ class Configuration implements ConfigurationInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Adds the configuration for the "clients" key
|
||||
* Adds the configuration for the "clients" key.
|
||||
*/
|
||||
private function addClientsSection(ArrayNodeDefinition $rootNode)
|
||||
{
|
||||
|
@ -76,8 +76,8 @@ class Configuration implements ConfigurationInterface
|
|||
->performNoDeepMerging()
|
||||
// BC - Renaming 'servers' node to 'connections'
|
||||
->beforeNormalization()
|
||||
->ifTrue(function($v) { return isset($v['servers']); })
|
||||
->then(function($v) {
|
||||
->ifTrue(function ($v) { return isset($v['servers']); })
|
||||
->then(function ($v) {
|
||||
$v['connections'] = $v['servers'];
|
||||
unset($v['servers']);
|
||||
|
||||
|
@ -99,7 +99,7 @@ class Configuration implements ConfigurationInterface
|
|||
->ifTrue(function ($v) { return is_array($v) && !array_key_exists('connections', $v); })
|
||||
->then(function ($v) {
|
||||
return array(
|
||||
'connections' => array($v)
|
||||
'connections' => array($v),
|
||||
);
|
||||
})
|
||||
->end()
|
||||
|
@ -111,8 +111,8 @@ class Configuration implements ConfigurationInterface
|
|||
->children()
|
||||
->scalarNode('url')
|
||||
->validate()
|
||||
->ifTrue(function($url) { return $url && substr($url, -1) !== '/'; })
|
||||
->then(function($url) { return $url.'/'; })
|
||||
->ifTrue(function ($url) { return $url && substr($url, -1) !== '/'; })
|
||||
->then(function ($url) { return $url.'/'; })
|
||||
->end()
|
||||
->end()
|
||||
->scalarNode('host')->end()
|
||||
|
@ -143,7 +143,7 @@ class Configuration implements ConfigurationInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Adds the configuration for the "indexes" key
|
||||
* Adds the configuration for the "indexes" key.
|
||||
*/
|
||||
private function addIndexesSection(ArrayNodeDefinition $rootNode)
|
||||
{
|
||||
|
@ -198,8 +198,8 @@ class Configuration implements ConfigurationInterface
|
|||
->end()
|
||||
// BC - Renaming 'mappings' node to 'properties'
|
||||
->beforeNormalization()
|
||||
->ifTrue(function($v) { return array_key_exists('mappings', $v); })
|
||||
->then(function($v) {
|
||||
->ifTrue(function ($v) { return array_key_exists('mappings', $v); })
|
||||
->then(function ($v) {
|
||||
$v['properties'] = $v['mappings'];
|
||||
unset($v['mappings']);
|
||||
|
||||
|
@ -422,7 +422,7 @@ class Configuration implements ConfigurationInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the array node used for "_all"
|
||||
* Returns the array node used for "_all".
|
||||
*/
|
||||
protected function getAllNode()
|
||||
{
|
||||
|
@ -441,7 +441,7 @@ class Configuration implements ConfigurationInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the array node used for "_timestamp"
|
||||
* Returns the array node used for "_timestamp".
|
||||
*/
|
||||
protected function getTimestampNode()
|
||||
{
|
||||
|
@ -462,7 +462,7 @@ class Configuration implements ConfigurationInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the array node used for "_ttl"
|
||||
* Returns the array node used for "_ttl".
|
||||
*/
|
||||
protected function getTtlNode()
|
||||
{
|
||||
|
@ -491,9 +491,9 @@ class Configuration implements ConfigurationInterface
|
|||
|
||||
$node
|
||||
->validate()
|
||||
->ifTrue(function($v) { return isset($v['driver']) && 'propel' === $v['driver'] && isset($v['listener']); })
|
||||
->ifTrue(function ($v) { return isset($v['driver']) && 'propel' === $v['driver'] && isset($v['listener']); })
|
||||
->thenInvalid('Propel doesn\'t support listeners')
|
||||
->ifTrue(function($v) { return isset($v['driver']) && 'propel' === $v['driver'] && isset($v['repository']); })
|
||||
->ifTrue(function ($v) { return isset($v['driver']) && 'propel' === $v['driver'] && isset($v['repository']); })
|
||||
->thenInvalid('Propel doesn\'t support the "repository" parameter')
|
||||
->end()
|
||||
->children()
|
||||
|
|
|
@ -80,8 +80,9 @@ class FOSElasticaExtension extends Extension
|
|||
}
|
||||
|
||||
/**
|
||||
* @param array $config
|
||||
* @param array $config
|
||||
* @param ContainerBuilder $container
|
||||
*
|
||||
* @return Configuration
|
||||
*/
|
||||
public function getConfiguration(array $config, ContainerBuilder $container)
|
||||
|
@ -92,8 +93,9 @@ class FOSElasticaExtension extends Extension
|
|||
/**
|
||||
* Loads the configured clients.
|
||||
*
|
||||
* @param array $clients An array of clients configurations
|
||||
* @param array $clients An array of clients configurations
|
||||
* @param ContainerBuilder $container A ContainerBuilder instance
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function loadClients(array $clients, ContainerBuilder $container)
|
||||
|
@ -114,7 +116,7 @@ class FOSElasticaExtension extends Extension
|
|||
|
||||
$this->clients[$name] = array(
|
||||
'id' => $clientId,
|
||||
'reference' => new Reference($clientId)
|
||||
'reference' => new Reference($clientId),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -122,9 +124,11 @@ class FOSElasticaExtension extends Extension
|
|||
/**
|
||||
* Loads the configured indexes.
|
||||
*
|
||||
* @param array $indexes An array of indexes configurations
|
||||
* @param array $indexes An array of indexes configurations
|
||||
* @param ContainerBuilder $container A ContainerBuilder instance
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function loadIndexes(array $indexes, ContainerBuilder $container)
|
||||
|
@ -133,7 +137,7 @@ class FOSElasticaExtension extends Extension
|
|||
|
||||
foreach ($indexes as $name => $index) {
|
||||
$indexId = sprintf('fos_elastica.index.%s', $name);
|
||||
$indexName = isset($index['index_name']) ? $index['index_name']: $name;
|
||||
$indexName = isset($index['index_name']) ? $index['index_name'] : $name;
|
||||
|
||||
$indexDef = new DefinitionDecorator('fos_elastica.index_prototype');
|
||||
$indexDef->replaceArgument(0, $indexName);
|
||||
|
@ -173,8 +177,9 @@ class FOSElasticaExtension extends Extension
|
|||
* Loads the configured index finders.
|
||||
*
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
||||
* @param string $name The index name
|
||||
* @param Reference $index Reference to the related index
|
||||
* @param string $name The index name
|
||||
* @param Reference $index Reference to the related index
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function loadIndexFinder(ContainerBuilder $container, $name, Reference $index)
|
||||
|
@ -197,10 +202,10 @@ class FOSElasticaExtension extends Extension
|
|||
/**
|
||||
* Loads the configured types.
|
||||
*
|
||||
* @param array $types
|
||||
* @param array $types
|
||||
* @param ContainerBuilder $container
|
||||
* @param array $indexConfig
|
||||
* @param array $indexableCallbacks
|
||||
* @param array $indexConfig
|
||||
* @param array $indexableCallbacks
|
||||
*/
|
||||
private function loadTypes(array $types, ContainerBuilder $container, array $indexConfig, array &$indexableCallbacks)
|
||||
{
|
||||
|
@ -280,13 +285,13 @@ class FOSElasticaExtension extends Extension
|
|||
}
|
||||
|
||||
/**
|
||||
* Loads the optional provider and finder for a type
|
||||
* Loads the optional provider and finder for a type.
|
||||
*
|
||||
* @param array $typeConfig
|
||||
* @param array $typeConfig
|
||||
* @param ContainerBuilder $container
|
||||
* @param Reference $typeRef
|
||||
* @param string $indexName
|
||||
* @param string $typeName
|
||||
* @param Reference $typeRef
|
||||
* @param string $indexName
|
||||
* @param string $typeName
|
||||
*/
|
||||
private function loadTypePersistenceIntegration(array $typeConfig, ContainerBuilder $container, Reference $typeRef, $indexName, $typeName)
|
||||
{
|
||||
|
@ -310,10 +315,11 @@ class FOSElasticaExtension extends Extension
|
|||
/**
|
||||
* Creates and loads an ElasticaToModelTransformer.
|
||||
*
|
||||
* @param array $typeConfig
|
||||
* @param array $typeConfig
|
||||
* @param ContainerBuilder $container
|
||||
* @param string $indexName
|
||||
* @param string $typeName
|
||||
* @param string $indexName
|
||||
* @param string $typeName
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function loadElasticaToModelTransformer(array $typeConfig, ContainerBuilder $container, $indexName, $typeName)
|
||||
|
@ -345,10 +351,11 @@ class FOSElasticaExtension extends Extension
|
|||
/**
|
||||
* Creates and loads a ModelToElasticaTransformer for an index/type.
|
||||
*
|
||||
* @param array $typeConfig
|
||||
* @param array $typeConfig
|
||||
* @param ContainerBuilder $container
|
||||
* @param string $indexName
|
||||
* @param string $typeName
|
||||
* @param string $indexName
|
||||
* @param string $typeName
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function loadModelToElasticaTransformer(array $typeConfig, ContainerBuilder $container, $indexName, $typeName)
|
||||
|
@ -364,7 +371,7 @@ class FOSElasticaExtension extends Extension
|
|||
$serviceId = sprintf('fos_elastica.model_to_elastica_transformer.%s.%s', $indexName, $typeName);
|
||||
$serviceDef = new DefinitionDecorator($abstractId);
|
||||
$serviceDef->replaceArgument(0, array(
|
||||
'identifier' => $typeConfig['identifier']
|
||||
'identifier' => $typeConfig['identifier'],
|
||||
));
|
||||
$container->setDefinition($serviceId, $serviceDef);
|
||||
|
||||
|
@ -374,12 +381,13 @@ class FOSElasticaExtension extends Extension
|
|||
/**
|
||||
* Creates and loads an object persister for a type.
|
||||
*
|
||||
* @param array $typeConfig
|
||||
* @param Reference $typeRef
|
||||
* @param array $typeConfig
|
||||
* @param Reference $typeRef
|
||||
* @param ContainerBuilder $container
|
||||
* @param string $indexName
|
||||
* @param string $typeName
|
||||
* @param string $transformerId
|
||||
* @param string $indexName
|
||||
* @param string $typeName
|
||||
* @param string $transformerId
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function loadObjectPersister(array $typeConfig, Reference $typeRef, ContainerBuilder $container, $indexName, $typeName, $transformerId)
|
||||
|
@ -398,7 +406,7 @@ class FOSElasticaExtension extends Extension
|
|||
$abstractId = 'fos_elastica.object_persister';
|
||||
$mapping = $this->indexConfigs[$indexName]['types'][$typeName]['mapping'];
|
||||
$argument = $mapping['properties'];
|
||||
if(isset($mapping['_parent'])){
|
||||
if (isset($mapping['_parent'])) {
|
||||
$argument['_parent'] = $mapping['_parent'];
|
||||
}
|
||||
$arguments[] = $argument;
|
||||
|
@ -418,11 +426,12 @@ class FOSElasticaExtension extends Extension
|
|||
/**
|
||||
* Loads a provider for a type.
|
||||
*
|
||||
* @param array $typeConfig
|
||||
* @param array $typeConfig
|
||||
* @param ContainerBuilder $container
|
||||
* @param string $objectPersisterId
|
||||
* @param string $indexName
|
||||
* @param string $typeName
|
||||
* @param string $objectPersisterId
|
||||
* @param string $indexName
|
||||
* @param string $typeName
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function loadTypeProvider(array $typeConfig, ContainerBuilder $container, $objectPersisterId, $indexName, $typeName)
|
||||
|
@ -435,7 +444,7 @@ class FOSElasticaExtension extends Extension
|
|||
* index and type names were "prototype" and a driver, respectively.
|
||||
*/
|
||||
$providerId = sprintf('fos_elastica.provider.%s.%s', $indexName, $typeName);
|
||||
$providerDef = new DefinitionDecorator('fos_elastica.provider.prototype.' . $typeConfig['driver']);
|
||||
$providerDef = new DefinitionDecorator('fos_elastica.provider.prototype.'.$typeConfig['driver']);
|
||||
$providerDef->addTag('fos_elastica.provider', array('index' => $indexName, 'type' => $typeName));
|
||||
$providerDef->replaceArgument(0, new Reference($objectPersisterId));
|
||||
$providerDef->replaceArgument(2, $typeConfig['model']);
|
||||
|
@ -452,11 +461,12 @@ class FOSElasticaExtension extends Extension
|
|||
/**
|
||||
* Loads doctrine listeners to handle indexing of new or updated objects.
|
||||
*
|
||||
* @param array $typeConfig
|
||||
* @param array $typeConfig
|
||||
* @param ContainerBuilder $container
|
||||
* @param string $objectPersisterId
|
||||
* @param string $indexName
|
||||
* @param string $typeName
|
||||
* @param string $objectPersisterId
|
||||
* @param string $indexName
|
||||
* @param string $typeName
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function loadTypeListener(array $typeConfig, ContainerBuilder $container, $objectPersisterId, $indexName, $typeName)
|
||||
|
@ -503,7 +513,7 @@ class FOSElasticaExtension extends Extension
|
|||
}
|
||||
|
||||
/**
|
||||
* Map Elastica to Doctrine events for the current driver
|
||||
* Map Elastica to Doctrine events for the current driver.
|
||||
*/
|
||||
private function getDoctrineEvents(array $typeConfig)
|
||||
{
|
||||
|
@ -524,7 +534,7 @@ class FOSElasticaExtension extends Extension
|
|||
'insert' => array(constant($eventsClass.'::postPersist')),
|
||||
'update' => array(constant($eventsClass.'::postUpdate')),
|
||||
'delete' => array(constant($eventsClass.'::preRemove')),
|
||||
'flush' => array($typeConfig['listener']['immediate'] ? constant($eventsClass.'::preFlush') : constant($eventsClass.'::postFlush'))
|
||||
'flush' => array($typeConfig['listener']['immediate'] ? constant($eventsClass.'::preFlush') : constant($eventsClass.'::postFlush')),
|
||||
);
|
||||
|
||||
foreach ($eventMapping as $event => $doctrineEvents) {
|
||||
|
@ -539,12 +549,13 @@ class FOSElasticaExtension extends Extension
|
|||
/**
|
||||
* Loads a Type specific Finder.
|
||||
*
|
||||
* @param array $typeConfig
|
||||
* @param array $typeConfig
|
||||
* @param ContainerBuilder $container
|
||||
* @param string $elasticaToModelId
|
||||
* @param Reference $typeRef
|
||||
* @param string $indexName
|
||||
* @param string $typeName
|
||||
* @param string $elasticaToModelId
|
||||
* @param Reference $typeRef
|
||||
* @param string $indexName
|
||||
* @param string $typeName
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function loadTypeFinder(array $typeConfig, ContainerBuilder $container, $elasticaToModelId, Reference $typeRef, $indexName, $typeName)
|
||||
|
@ -571,7 +582,7 @@ class FOSElasticaExtension extends Extension
|
|||
}
|
||||
|
||||
/**
|
||||
* Loads the index manager
|
||||
* Loads the index manager.
|
||||
*
|
||||
* @param ContainerBuilder $container
|
||||
**/
|
||||
|
@ -589,7 +600,7 @@ class FOSElasticaExtension extends Extension
|
|||
* Makes sure a specific driver has been loaded.
|
||||
*
|
||||
* @param ContainerBuilder $container
|
||||
* @param string $driver
|
||||
* @param string $driver
|
||||
*/
|
||||
private function loadDriver(ContainerBuilder $container, $driver)
|
||||
{
|
||||
|
@ -605,7 +616,7 @@ class FOSElasticaExtension extends Extension
|
|||
/**
|
||||
* Loads and configures the serializer prototype.
|
||||
*
|
||||
* @param array $config
|
||||
* @param array $config
|
||||
* @param ContainerBuilder $container
|
||||
*/
|
||||
private function loadSerializer($config, ContainerBuilder $container)
|
||||
|
@ -624,7 +635,7 @@ class FOSElasticaExtension extends Extension
|
|||
/**
|
||||
* Creates a default manager alias for defined default manager or the first loaded driver.
|
||||
*
|
||||
* @param string $defaultManager
|
||||
* @param string $defaultManager
|
||||
* @param ContainerBuilder $container
|
||||
*/
|
||||
private function createDefaultManagerAlias($defaultManager, ContainerBuilder $container)
|
||||
|
@ -648,7 +659,9 @@ class FOSElasticaExtension extends Extension
|
|||
* Returns a reference to a client given its configured name.
|
||||
*
|
||||
* @param string $clientName
|
||||
*
|
||||
* @return Reference
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
private function getClient($clientName)
|
||||
|
|
|
@ -10,24 +10,24 @@ use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
|
|||
/**
|
||||
* Maps Elastica documents with Doctrine objects
|
||||
* This mapper assumes an exact match between
|
||||
* elastica documents ids and doctrine object ids
|
||||
* elastica documents ids and doctrine object ids.
|
||||
*/
|
||||
abstract class AbstractElasticaToModelTransformer implements ElasticaToModelTransformerInterface
|
||||
{
|
||||
/**
|
||||
* Manager registry
|
||||
* Manager registry.
|
||||
*/
|
||||
protected $registry = null;
|
||||
|
||||
/**
|
||||
* Class of the model to map to the elastica documents
|
||||
* Class of the model to map to the elastica documents.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $objectClass = null;
|
||||
|
||||
/**
|
||||
* Optional parameters
|
||||
* Optional parameters.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
|
@ -39,18 +39,18 @@ abstract class AbstractElasticaToModelTransformer implements ElasticaToModelTran
|
|||
);
|
||||
|
||||
/**
|
||||
* PropertyAccessor instance
|
||||
* PropertyAccessor instance.
|
||||
*
|
||||
* @var PropertyAccessorInterface
|
||||
*/
|
||||
protected $propertyAccessor;
|
||||
|
||||
/**
|
||||
* Instantiates a new Mapper
|
||||
* Instantiates a new Mapper.
|
||||
*
|
||||
* @param object $registry
|
||||
* @param string $objectClass
|
||||
* @param array $options
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct($registry, $objectClass, array $options = array())
|
||||
{
|
||||
|
@ -70,7 +70,7 @@ abstract class AbstractElasticaToModelTransformer implements ElasticaToModelTran
|
|||
}
|
||||
|
||||
/**
|
||||
* Set the PropertyAccessor
|
||||
* Set the PropertyAccessor.
|
||||
*
|
||||
* @param PropertyAccessorInterface $propertyAccessor
|
||||
*/
|
||||
|
@ -81,10 +81,12 @@ abstract class AbstractElasticaToModelTransformer implements ElasticaToModelTran
|
|||
|
||||
/**
|
||||
* Transforms an array of elastica objects into an array of
|
||||
* model objects fetched from the doctrine repository
|
||||
* model objects fetched from the doctrine repository.
|
||||
*
|
||||
* @param array $elasticaObjects of elastica objects
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
*
|
||||
* @return array
|
||||
**/
|
||||
public function transform(array $elasticaObjects)
|
||||
|
@ -110,8 +112,7 @@ abstract class AbstractElasticaToModelTransformer implements ElasticaToModelTran
|
|||
$idPos = array_flip($ids);
|
||||
$identifier = $this->options['identifier'];
|
||||
$propertyAccessor = $this->propertyAccessor;
|
||||
usort($objects, function($a, $b) use ($idPos, $identifier, $propertyAccessor)
|
||||
{
|
||||
usort($objects, function ($a, $b) use ($idPos, $identifier, $propertyAccessor) {
|
||||
return $idPos[$propertyAccessor->getValue($a, $identifier)] > $idPos[$propertyAccessor->getValue($b, $identifier)];
|
||||
});
|
||||
|
||||
|
@ -145,11 +146,12 @@ abstract class AbstractElasticaToModelTransformer implements ElasticaToModelTran
|
|||
}
|
||||
|
||||
/**
|
||||
* Fetches objects by theses identifier values
|
||||
* Fetches objects by theses identifier values.
|
||||
*
|
||||
* @param array $identifierValues ids values
|
||||
* @param Boolean $hydrate whether or not to hydrate the objects, false returns arrays
|
||||
*
|
||||
* @param array $identifierValues ids values
|
||||
* @param Boolean $hydrate whether or not to hydrate the objects, false returns arrays
|
||||
* @return array of objects or arrays
|
||||
*/
|
||||
protected abstract function findByIdentifiers(array $identifierValues, $hydrate);
|
||||
abstract protected function findByIdentifiers(array $identifierValues, $hydrate);
|
||||
}
|
||||
|
|
|
@ -24,11 +24,11 @@ abstract class AbstractProvider extends BaseAbstractProvider
|
|||
* Constructor.
|
||||
*
|
||||
* @param ObjectPersisterInterface $objectPersister
|
||||
* @param IndexableInterface $indexable
|
||||
* @param string $objectClass
|
||||
* @param array $options
|
||||
* @param ManagerRegistry $managerRegistry
|
||||
* @param SliceFetcherInterface $sliceFetcher
|
||||
* @param IndexableInterface $indexable
|
||||
* @param string $objectClass
|
||||
* @param array $options
|
||||
* @param ManagerRegistry $managerRegistry
|
||||
* @param SliceFetcherInterface $sliceFetcher
|
||||
*/
|
||||
public function __construct(
|
||||
ObjectPersisterInterface $objectPersister,
|
||||
|
@ -77,7 +77,7 @@ abstract class AbstractProvider extends BaseAbstractProvider
|
|||
} else {
|
||||
try {
|
||||
$this->objectPersister->insertMany($objects);
|
||||
} catch(BulkResponseException $e) {
|
||||
} catch (BulkResponseException $e) {
|
||||
if ($loggerClosure) {
|
||||
$loggerClosure($batchSize, $nbObjects, sprintf('<error>%s</error>', $e->getMessage()));
|
||||
}
|
||||
|
@ -106,9 +106,10 @@ abstract class AbstractProvider extends BaseAbstractProvider
|
|||
* the fetchSlice methods defined in the ORM/MongoDB subclasses.
|
||||
*
|
||||
* @param $queryBuilder
|
||||
* @param int $limit
|
||||
* @param int $offset
|
||||
* @param int $limit
|
||||
* @param int $offset
|
||||
* @param array $lastSlice
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getSlice($queryBuilder, $limit, $offset, $lastSlice)
|
||||
|
@ -135,24 +136,26 @@ abstract class AbstractProvider extends BaseAbstractProvider
|
|||
* Counts objects that would be indexed using the query builder.
|
||||
*
|
||||
* @param object $queryBuilder
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
protected abstract function countObjects($queryBuilder);
|
||||
abstract protected function countObjects($queryBuilder);
|
||||
|
||||
/**
|
||||
* Disables logging and returns the logger that was previously set.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected abstract function disableLogging();
|
||||
abstract protected function disableLogging();
|
||||
|
||||
/**
|
||||
* Reenables the logger with the previously returned logger from disableLogging();
|
||||
* Reenables the logger with the previously returned logger from disableLogging();.
|
||||
*
|
||||
* @param mixed $logger
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected abstract function enableLogging($logger);
|
||||
abstract protected function enableLogging($logger);
|
||||
|
||||
/**
|
||||
* Fetches a slice of objects using the query builder.
|
||||
|
@ -160,14 +163,15 @@ abstract class AbstractProvider extends BaseAbstractProvider
|
|||
* @param object $queryBuilder
|
||||
* @param integer $limit
|
||||
* @param integer $offset
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected abstract function fetchSlice($queryBuilder, $limit, $offset);
|
||||
abstract protected function fetchSlice($queryBuilder, $limit, $offset);
|
||||
|
||||
/**
|
||||
* Creates the query builder, which will be used to fetch objects to index.
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
protected abstract function createQueryBuilder();
|
||||
abstract protected function createQueryBuilder();
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
|
|||
use FOS\ElasticaBundle\Persister\ObjectPersisterInterface;
|
||||
use FOS\ElasticaBundle\Persister\ObjectPersister;
|
||||
use FOS\ElasticaBundle\Provider\IndexableInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\PropertyAccess\PropertyAccess;
|
||||
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
|
||||
|
||||
|
@ -16,14 +17,14 @@ use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
|
|||
class Listener
|
||||
{
|
||||
/**
|
||||
* Object persister
|
||||
* Object persister.
|
||||
*
|
||||
* @var ObjectPersister
|
||||
*/
|
||||
protected $objectPersister;
|
||||
|
||||
/**
|
||||
* Configuration for the listener
|
||||
* Configuration for the listener.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
|
@ -44,14 +45,14 @@ class Listener
|
|||
public $scheduledForUpdate = array();
|
||||
|
||||
/**
|
||||
* IDs of objects scheduled for removal
|
||||
* IDs of objects scheduled for removal.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $scheduledForDeletion = array();
|
||||
|
||||
/**
|
||||
* PropertyAccessor instance
|
||||
* PropertyAccessor instance.
|
||||
*
|
||||
* @var PropertyAccessorInterface
|
||||
*/
|
||||
|
@ -66,15 +67,15 @@ class Listener
|
|||
* Constructor.
|
||||
*
|
||||
* @param ObjectPersisterInterface $objectPersister
|
||||
* @param IndexableInterface $indexable
|
||||
* @param array $config
|
||||
* @param null $logger
|
||||
* @param IndexableInterface $indexable
|
||||
* @param array $config
|
||||
* @param LoggerInterface $logger
|
||||
*/
|
||||
public function __construct(
|
||||
ObjectPersisterInterface $objectPersister,
|
||||
IndexableInterface $indexable,
|
||||
array $config = array(),
|
||||
$logger = null
|
||||
LoggerInterface $logger = null
|
||||
) {
|
||||
$this->config = array_merge(array(
|
||||
'identifier' => 'id',
|
||||
|
@ -123,7 +124,7 @@ class Listener
|
|||
|
||||
/**
|
||||
* Delete objects preRemove instead of postRemove so that we have access to the id. Because this is called
|
||||
* preRemove, first check that the entity is managed by Doctrine
|
||||
* preRemove, first check that the entity is managed by Doctrine.
|
||||
*
|
||||
* @param LifecycleEventArgs $eventArgs
|
||||
*/
|
||||
|
@ -138,7 +139,7 @@ class Listener
|
|||
|
||||
/**
|
||||
* Persist scheduled objects to ElasticSearch
|
||||
* After persisting, clear the scheduled queue to prevent multiple data updates when using multiple flush calls
|
||||
* After persisting, clear the scheduled queue to prevent multiple data updates when using multiple flush calls.
|
||||
*/
|
||||
private function persistScheduled()
|
||||
{
|
||||
|
@ -197,6 +198,7 @@ class Listener
|
|||
* Checks if the object is indexable or not.
|
||||
*
|
||||
* @param object $object
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isObjectIndexable($object)
|
||||
|
|
|
@ -7,15 +7,16 @@ use FOS\ElasticaBundle\Doctrine\AbstractElasticaToModelTransformer;
|
|||
/**
|
||||
* Maps Elastica documents with Doctrine objects
|
||||
* This mapper assumes an exact match between
|
||||
* elastica documents ids and doctrine object ids
|
||||
* elastica documents ids and doctrine object ids.
|
||||
*/
|
||||
class ElasticaToModelTransformer extends AbstractElasticaToModelTransformer
|
||||
{
|
||||
/**
|
||||
* Fetch objects for theses identifier values
|
||||
* Fetch objects for theses identifier values.
|
||||
*
|
||||
* @param array $identifierValues ids values
|
||||
* @param Boolean $hydrate whether or not to hydrate the objects, false returns arrays
|
||||
*
|
||||
* @param array $identifierValues ids values
|
||||
* @param Boolean $hydrate whether or not to hydrate the objects, false returns arrays
|
||||
* @return array of objects or arrays
|
||||
*/
|
||||
protected function findByIdentifiers(array $identifierValues, $hydrate)
|
||||
|
|
|
@ -27,9 +27,10 @@ class Provider extends AbstractProvider
|
|||
}
|
||||
|
||||
/**
|
||||
* Reenables the logger with the previously returned logger from disableLogging();
|
||||
* Reenables the logger with the previously returned logger from disableLogging();.
|
||||
*
|
||||
* @param mixed $logger
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function enableLogging($logger)
|
||||
|
|
|
@ -7,7 +7,7 @@ use FOS\ElasticaBundle\Exception\InvalidArgumentTypeException;
|
|||
use FOS\ElasticaBundle\Doctrine\SliceFetcherInterface;
|
||||
|
||||
/**
|
||||
* Fetches a slice of objects
|
||||
* Fetches a slice of objects.
|
||||
*
|
||||
* @author Thomas Prelot <tprelot@gmail.com>
|
||||
*/
|
||||
|
|
|
@ -8,17 +8,18 @@ use Doctrine\ORM\Query;
|
|||
/**
|
||||
* Maps Elastica documents with Doctrine objects
|
||||
* This mapper assumes an exact match between
|
||||
* elastica documents ids and doctrine object ids
|
||||
* elastica documents ids and doctrine object ids.
|
||||
*/
|
||||
class ElasticaToModelTransformer extends AbstractElasticaToModelTransformer
|
||||
{
|
||||
const ENTITY_ALIAS = 'o';
|
||||
|
||||
/**
|
||||
* Fetch objects for theses identifier values
|
||||
* Fetch objects for theses identifier values.
|
||||
*
|
||||
* @param array $identifierValues ids values
|
||||
* @param Boolean $hydrate whether or not to hydrate the objects, false returns arrays
|
||||
*
|
||||
* @param array $identifierValues ids values
|
||||
* @param Boolean $hydrate whether or not to hydrate the objects, false returns arrays
|
||||
* @return array of objects or arrays
|
||||
*/
|
||||
protected function findByIdentifiers(array $identifierValues, $hydrate)
|
||||
|
@ -36,7 +37,7 @@ class ElasticaToModelTransformer extends AbstractElasticaToModelTransformer
|
|||
}
|
||||
|
||||
/**
|
||||
* Retrieves a query builder to be used for querying by identifiers
|
||||
* Retrieves a query builder to be used for querying by identifiers.
|
||||
*
|
||||
* @return \Doctrine\ORM\QueryBuilder
|
||||
*/
|
||||
|
|
|
@ -29,9 +29,10 @@ class Provider extends AbstractProvider
|
|||
}
|
||||
|
||||
/**
|
||||
* Reenables the logger with the previously returned logger from disableLogging();
|
||||
* Reenables the logger with the previously returned logger from disableLogging();.
|
||||
*
|
||||
* @param mixed $logger
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function enableLogging($logger)
|
||||
|
@ -76,7 +77,7 @@ class Provider extends AbstractProvider
|
|||
throw new InvalidArgumentTypeException($queryBuilder, 'Doctrine\ORM\QueryBuilder');
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* An orderBy DQL part is required to avoid feching the same row twice.
|
||||
* @see http://stackoverflow.com/questions/6314879/does-limit-offset-length-require-order-by-for-pagination
|
||||
* @see http://www.postgresql.org/docs/current/static/queries-limit.html
|
||||
|
|
|
@ -7,7 +7,7 @@ use FOS\ElasticaBundle\Exception\InvalidArgumentTypeException;
|
|||
use FOS\ElasticaBundle\Doctrine\SliceFetcherInterface;
|
||||
|
||||
/**
|
||||
* Fetches a slice of objects
|
||||
* Fetches a slice of objects.
|
||||
*
|
||||
* @author Thomas Prelot <tprelot@gmail.com>
|
||||
*/
|
||||
|
@ -22,7 +22,7 @@ class SliceFetcher implements SliceFetcherInterface
|
|||
throw new InvalidArgumentTypeException($queryBuilder, 'Doctrine\ORM\QueryBuilder');
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* An orderBy DQL part is required to avoid feching the same row twice.
|
||||
* @see http://stackoverflow.com/questions/6314879/does-limit-offset-length-require-order-by-for-pagination
|
||||
* @see http://www.postgresql.org/docs/current/static/queries-limit.html
|
||||
|
|
|
@ -25,7 +25,7 @@ class RepositoryManager extends BaseManager
|
|||
}
|
||||
|
||||
/**
|
||||
* Return repository for entity
|
||||
* Return repository for entity.
|
||||
*
|
||||
* Returns custom repository if one specified otherwise
|
||||
* returns a basic repository.
|
||||
|
@ -35,7 +35,7 @@ class RepositoryManager extends BaseManager
|
|||
$realEntityName = $entityName;
|
||||
if (strpos($entityName, ':') !== false) {
|
||||
list($namespaceAlias, $simpleClassName) = explode(':', $entityName);
|
||||
$realEntityName = $this->managerRegistry->getAliasNamespace($namespaceAlias) . '\\' . $simpleClassName;
|
||||
$realEntityName = $this->managerRegistry->getAliasNamespace($namespaceAlias).'\\'.$simpleClassName;
|
||||
}
|
||||
|
||||
return parent::getRepository($realEntityName);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace FOS\ElasticaBundle\Doctrine;
|
||||
|
||||
/**
|
||||
* Fetches a slice of objects
|
||||
* Fetches a slice of objects.
|
||||
*
|
||||
* @author Thomas Prelot <tprelot@gmail.com>
|
||||
*/
|
||||
|
@ -17,7 +17,8 @@ interface SliceFetcherInterface
|
|||
* @param integer $offset
|
||||
* @param array $previousSlice
|
||||
* @param array $identifierFieldNames
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function fetch($queryBuilder, $limit, $offset, array $previousSlice, array $identifierFieldNames);
|
||||
public function fetch($queryBuilder, $limit, $offset, array $previousSlice, array $identifierFieldNames);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ class Client extends BaseClient
|
|||
private $indexCache = array();
|
||||
|
||||
/**
|
||||
* Symfony's debugging Stopwatch
|
||||
* Symfony's debugging Stopwatch.
|
||||
*
|
||||
* @var Stopwatch|null
|
||||
*/
|
||||
|
@ -32,8 +32,9 @@ class Client extends BaseClient
|
|||
/**
|
||||
* @param string $path
|
||||
* @param string $method
|
||||
* @param array $data
|
||||
* @param array $query
|
||||
* @param array $data
|
||||
* @param array $query
|
||||
*
|
||||
* @return \Elastica\Response
|
||||
*/
|
||||
public function request($path, $method = Request::GET, $data = array(), array $query = array())
|
||||
|
@ -78,9 +79,9 @@ class Client extends BaseClient
|
|||
*
|
||||
* @param string $path
|
||||
* @param string $method
|
||||
* @param array $data
|
||||
* @param array $query
|
||||
* @param int $start
|
||||
* @param array $data
|
||||
* @param array $query
|
||||
* @param int $start
|
||||
*/
|
||||
private function logQuery($path, $method, $data, array $query, $start)
|
||||
{
|
||||
|
|
|
@ -44,14 +44,12 @@ class Index extends BaseIndex
|
|||
}
|
||||
|
||||
/**
|
||||
* Reassign index name
|
||||
* Reassign index name.
|
||||
*
|
||||
* While it's technically a regular setter for name property, it's specifically named overrideName, but not setName
|
||||
* since it's used for a very specific case and normally should not be used
|
||||
*
|
||||
* @param string $name Index name
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function overrideName($name)
|
||||
{
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace FOS\ElasticaBundle\Event;
|
|||
use Symfony\Component\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* Index Populate Event
|
||||
* Index Populate Event.
|
||||
*
|
||||
* @author Oleg Andreyev <oleg.andreyev@intexsys.lv>
|
||||
*/
|
||||
|
@ -39,9 +39,9 @@ class IndexPopulateEvent extends Event
|
|||
private $options;
|
||||
|
||||
/**
|
||||
* @param string $index
|
||||
* @param boolean $reset
|
||||
* @param array $options
|
||||
* @param string $index
|
||||
* @param boolean $reset
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct($index, $reset, $options)
|
||||
{
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace FOS\ElasticaBundle\Event;
|
|||
use Symfony\Component\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* Index ResetEvent
|
||||
* Index ResetEvent.
|
||||
*
|
||||
* @author Oleg Andreyev <oleg.andreyev@intexsys.lv>
|
||||
*/
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace FOS\ElasticaBundle\Event;
|
|||
use Symfony\Component\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* Type Populate Event
|
||||
* Type Populate Event.
|
||||
*
|
||||
* @author Oleg Andreyev <oleg.andreyev@intexsys.lv>
|
||||
*/
|
||||
|
@ -31,8 +31,8 @@ class TypePopulateEvent extends IndexPopulateEvent
|
|||
/**
|
||||
* @param string $index
|
||||
* @param string $type
|
||||
* @param bool $reset
|
||||
* @param array $options
|
||||
* @param bool $reset
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct($index, $type, $reset, $options)
|
||||
{
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace FOS\ElasticaBundle\Event;
|
|||
use Symfony\Component\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* Type ResetEvent
|
||||
* Type ResetEvent.
|
||||
*
|
||||
* @author Oleg Andreyev <oleg.andreyev@intexsys.lv>
|
||||
*/
|
||||
|
|
|
@ -9,4 +9,3 @@ class AliasIsIndexException extends \Exception
|
|||
parent::__construct(sprintf('Expected alias %s instead of index', $indexName));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ use Symfony\Component\HttpKernel\Bundle\Bundle;
|
|||
|
||||
/**
|
||||
* Bundle.
|
||||
*
|
||||
*/
|
||||
class FOSElasticaBundle extends Bundle
|
||||
{
|
||||
|
|
|
@ -5,12 +5,13 @@ namespace FOS\ElasticaBundle\Finder;
|
|||
interface FinderInterface
|
||||
{
|
||||
/**
|
||||
* Searches for query results within a given limit
|
||||
* Searches for query results within a given limit.
|
||||
*
|
||||
* @param mixed $query Can be a string, an array or an \Elastica\Query object
|
||||
* @param int $limit How many results to get
|
||||
* @param mixed $query Can be a string, an array or an \Elastica\Query object
|
||||
* @param int $limit How many results to get
|
||||
* @param array $options
|
||||
*
|
||||
* @return array results
|
||||
*/
|
||||
function find($query, $limit = null, $options = array());
|
||||
public function find($query, $limit = null, $options = array());
|
||||
}
|
||||
|
|
|
@ -9,20 +9,22 @@ use Elastica\Query;
|
|||
interface PaginatedFinderInterface extends FinderInterface
|
||||
{
|
||||
/**
|
||||
* Searches for query results and returns them wrapped in a paginator
|
||||
* Searches for query results and returns them wrapped in a paginator.
|
||||
*
|
||||
* @param mixed $query Can be a string, an array or an \Elastica\Query object
|
||||
* @param mixed $query Can be a string, an array or an \Elastica\Query object
|
||||
* @param array $options
|
||||
*
|
||||
* @return Pagerfanta paginated results
|
||||
*/
|
||||
function findPaginated($query, $options = array());
|
||||
public function findPaginated($query, $options = array());
|
||||
|
||||
/**
|
||||
* Creates a paginator adapter for this query
|
||||
* Creates a paginator adapter for this query.
|
||||
*
|
||||
* @param mixed $query
|
||||
* @param array $options
|
||||
*
|
||||
* @return PaginatorAdapterInterface
|
||||
*/
|
||||
function createPaginatorAdapter($query, $options = array());
|
||||
public function createPaginatorAdapter($query, $options = array());
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ use Elastica\SearchableInterface;
|
|||
use Elastica\Query;
|
||||
|
||||
/**
|
||||
* Finds elastica documents and map them to persisted objects
|
||||
* Finds elastica documents and map them to persisted objects.
|
||||
*/
|
||||
class TransformedFinder implements PaginatedFinderInterface
|
||||
{
|
||||
|
@ -25,11 +25,12 @@ class TransformedFinder implements PaginatedFinderInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Search for a query string
|
||||
* Search for a query string.
|
||||
*
|
||||
* @param string $query
|
||||
* @param string $query
|
||||
* @param integer $limit
|
||||
* @param array $options
|
||||
* @param array $options
|
||||
*
|
||||
* @return array of model objects
|
||||
**/
|
||||
public function find($query, $limit = null, $options = array())
|
||||
|
@ -50,8 +51,9 @@ class TransformedFinder implements PaginatedFinderInterface
|
|||
* Find documents similar to one with passed id.
|
||||
*
|
||||
* @param integer $id
|
||||
* @param array $params
|
||||
* @param array $query
|
||||
* @param array $params
|
||||
* @param array $query
|
||||
*
|
||||
* @return array of model objects
|
||||
**/
|
||||
public function moreLikeThis($id, $params = array(), $query = array())
|
||||
|
@ -65,7 +67,8 @@ class TransformedFinder implements PaginatedFinderInterface
|
|||
/**
|
||||
* @param $query
|
||||
* @param null|int $limit
|
||||
* @param array $options
|
||||
* @param array $options
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function search($query, $limit = null, $options = array())
|
||||
|
@ -80,10 +83,11 @@ class TransformedFinder implements PaginatedFinderInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets a paginator wrapping the result of a search
|
||||
* Gets a paginator wrapping the result of a search.
|
||||
*
|
||||
* @param string $query
|
||||
* @param array $options
|
||||
* @param array $options
|
||||
*
|
||||
* @return Pagerfanta
|
||||
*/
|
||||
public function findPaginated($query, $options = array())
|
||||
|
|
|
@ -24,7 +24,7 @@ class AliasProcessor
|
|||
* Sets the randomised root name for an index.
|
||||
*
|
||||
* @param IndexConfig $indexConfig
|
||||
* @param Index $index
|
||||
* @param Index $index
|
||||
*/
|
||||
public function setRootName(IndexConfig $indexConfig, Index $index)
|
||||
{
|
||||
|
@ -43,8 +43,9 @@ class AliasProcessor
|
|||
* $force will delete an index encountered where an alias is expected.
|
||||
*
|
||||
* @param IndexConfig $indexConfig
|
||||
* @param Index $index
|
||||
* @param bool $force
|
||||
* @param Index $index
|
||||
* @param bool $force
|
||||
*
|
||||
* @throws AliasIsIndexException
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
|
@ -58,7 +59,7 @@ class AliasProcessor
|
|||
|
||||
try {
|
||||
$aliasedIndexes = $this->getAliasedIndexes($client, $aliasName);
|
||||
} catch(AliasIsIndexException $e) {
|
||||
} catch (AliasIsIndexException $e) {
|
||||
if (!$force) {
|
||||
throw $e;
|
||||
}
|
||||
|
@ -73,7 +74,7 @@ class AliasProcessor
|
|||
'Alias %s is used for multiple indexes: [%s].
|
||||
Make sure it\'s either not used or is assigned to one index only',
|
||||
$aliasName,
|
||||
join(', ', $aliasedIndexes)
|
||||
implode(', ', $aliasedIndexes)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -83,13 +84,13 @@ class AliasProcessor
|
|||
// if the alias is set - add an action to remove it
|
||||
$oldIndexName = $aliasedIndexes[0];
|
||||
$aliasUpdateRequest['actions'][] = array(
|
||||
'remove' => array('index' => $oldIndexName, 'alias' => $aliasName)
|
||||
'remove' => array('index' => $oldIndexName, 'alias' => $aliasName),
|
||||
);
|
||||
}
|
||||
|
||||
// add an action to point the alias to the new index
|
||||
$aliasUpdateRequest['actions'][] = array(
|
||||
'add' => array('index' => $newIndexName, 'alias' => $aliasName)
|
||||
'add' => array('index' => $newIndexName, 'alias' => $aliasName),
|
||||
);
|
||||
|
||||
try {
|
||||
|
@ -134,12 +135,13 @@ class AliasProcessor
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns array of indexes which are mapped to given alias
|
||||
* Returns array of indexes which are mapped to given alias.
|
||||
*
|
||||
* @param Client $client
|
||||
* @param string $aliasName Alias name
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws AliasIsIndexException
|
||||
*/
|
||||
private function getAliasedIndexes(Client $client, $aliasName)
|
||||
|
@ -165,7 +167,7 @@ class AliasProcessor
|
|||
}
|
||||
|
||||
/**
|
||||
* Delete an index
|
||||
* Delete an index.
|
||||
*
|
||||
* @param Client $client
|
||||
* @param string $indexName Index name to delete
|
||||
|
|
|
@ -22,7 +22,7 @@ class IndexManager
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets all registered indexes
|
||||
* Gets all registered indexes.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
@ -32,10 +32,12 @@ class IndexManager
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets an index by its name
|
||||
* Gets an index by its name.
|
||||
*
|
||||
* @param string $name Index to return, or the default index if null
|
||||
*
|
||||
* @return Index
|
||||
*
|
||||
* @throws \InvalidArgumentException if no index exists for the given name
|
||||
*/
|
||||
public function getIndex($name = null)
|
||||
|
@ -52,7 +54,7 @@ class IndexManager
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets the default index
|
||||
* Gets the default index.
|
||||
*
|
||||
* @return Index
|
||||
*/
|
||||
|
|
|
@ -27,6 +27,7 @@ class MappingBuilder
|
|||
* Builds mappings for an entire index.
|
||||
*
|
||||
* @param IndexConfig $indexConfig
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function buildIndexMapping(IndexConfig $indexConfig)
|
||||
|
@ -54,6 +55,7 @@ class MappingBuilder
|
|||
* Builds mappings for a single type.
|
||||
*
|
||||
* @param TypeConfig $typeConfig
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function buildTypeMapping(TypeConfig $typeConfig)
|
||||
|
@ -95,7 +97,7 @@ class MappingBuilder
|
|||
|
||||
if (!$mapping) {
|
||||
// Empty mapping, we want it encoded as a {} instead of a []
|
||||
$mapping = new \stdClass;
|
||||
$mapping = new \stdClass();
|
||||
}
|
||||
|
||||
return $mapping;
|
||||
|
|
|
@ -11,7 +11,7 @@ use FOS\ElasticaBundle\Event\TypeResetEvent;
|
|||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
/**
|
||||
* Deletes and recreates indexes
|
||||
* Deletes and recreates indexes.
|
||||
*/
|
||||
class Resetter
|
||||
{
|
||||
|
@ -62,7 +62,7 @@ class Resetter
|
|||
}
|
||||
|
||||
/**
|
||||
* Deletes and recreates all indexes
|
||||
* Deletes and recreates all indexes.
|
||||
*
|
||||
* @param bool $populating
|
||||
* @param bool $force
|
||||
|
@ -79,8 +79,9 @@ class Resetter
|
|||
* with a randomised name for an alias to be set after population.
|
||||
*
|
||||
* @param string $indexName
|
||||
* @param bool $populating
|
||||
* @param bool $force If index exists with same name as alias, remove it
|
||||
* @param bool $populating
|
||||
* @param bool $force If index exists with same name as alias, remove it
|
||||
*
|
||||
* @throws \InvalidArgumentException if no index exists for the given name
|
||||
*/
|
||||
public function resetIndex($indexName, $populating = false, $force = false)
|
||||
|
@ -106,10 +107,11 @@ class Resetter
|
|||
}
|
||||
|
||||
/**
|
||||
* Deletes and recreates a mapping type for the named index
|
||||
* Deletes and recreates a mapping type for the named index.
|
||||
*
|
||||
* @param string $indexName
|
||||
* @param string $typeName
|
||||
*
|
||||
* @throws \InvalidArgumentException if no index or type mapping exists for the given names
|
||||
* @throws ResponseException
|
||||
*/
|
||||
|
|
|
@ -25,13 +25,13 @@ class RepositoryManager implements RepositoryManagerInterface
|
|||
|
||||
public function addEntity($entityName, FinderInterface $finder, $repositoryName = null)
|
||||
{
|
||||
$this->entities[$entityName]= array();
|
||||
$this->entities[$entityName] = array();
|
||||
$this->entities[$entityName]['finder'] = $finder;
|
||||
$this->entities[$entityName]['repositoryName'] = $repositoryName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return repository for entity
|
||||
* Return repository for entity.
|
||||
*
|
||||
* Returns custom repository if one specified otherwise
|
||||
* returns a basic repository.
|
||||
|
@ -63,6 +63,7 @@ class RepositoryManager implements RepositoryManagerInterface
|
|||
if ($annotation) {
|
||||
$this->entities[$entityName]['repositoryName']
|
||||
= $annotation->repositoryClass;
|
||||
|
||||
return $annotation->repositoryClass;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ use FOS\ElasticaBundle\Finder\FinderInterface;
|
|||
*/
|
||||
interface RepositoryManagerInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Adds entity name and its finder.
|
||||
* Custom repository class name can also be added.
|
||||
|
@ -24,7 +23,7 @@ interface RepositoryManagerInterface
|
|||
public function addEntity($entityName, FinderInterface $finder, $repositoryName = null);
|
||||
|
||||
/**
|
||||
* Return repository for entity
|
||||
* Return repository for entity.
|
||||
*
|
||||
* Returns custom repository if one specified otherwise
|
||||
* returns a basic repository.
|
||||
|
|
|
@ -20,8 +20,6 @@ class FantaPaginatorAdapter implements AdapterInterface
|
|||
* Returns the number of results.
|
||||
*
|
||||
* @return integer The number of results.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function getNbResults()
|
||||
{
|
||||
|
@ -29,11 +27,9 @@ class FantaPaginatorAdapter implements AdapterInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns Facets
|
||||
* Returns Facets.
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function getFacets()
|
||||
{
|
||||
|
@ -41,7 +37,7 @@ class FantaPaginatorAdapter implements AdapterInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns Aggregations
|
||||
* Returns Aggregations.
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
|
@ -59,8 +55,6 @@ class FantaPaginatorAdapter implements AdapterInterface
|
|||
* @param integer $length The length.
|
||||
*
|
||||
* @return array|\Traversable The slice.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function getSlice($offset, $length)
|
||||
{
|
||||
|
|
|
@ -8,10 +8,8 @@ interface PaginatorAdapterInterface
|
|||
* Returns the number of results.
|
||||
*
|
||||
* @return integer The number of results.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
function getTotalHits();
|
||||
public function getTotalHits();
|
||||
|
||||
/**
|
||||
* Returns an slice of the results.
|
||||
|
@ -20,22 +18,20 @@ interface PaginatorAdapterInterface
|
|||
* @param integer $length The length.
|
||||
*
|
||||
* @return PartialResultsInterface
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
function getResults($offset, $length);
|
||||
public function getResults($offset, $length);
|
||||
|
||||
/**
|
||||
* Returns Facets
|
||||
* Returns Facets.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function getFacets();
|
||||
public function getFacets();
|
||||
|
||||
/**
|
||||
* Returns Aggregations
|
||||
* Returns Aggregations.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function getAggregations();
|
||||
public function getAggregations();
|
||||
}
|
||||
|
|
|
@ -8,31 +8,27 @@ interface PartialResultsInterface
|
|||
* Returns the paginated results.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
function toArray();
|
||||
public function toArray();
|
||||
|
||||
/**
|
||||
* Returns the number of results.
|
||||
*
|
||||
* @return integer The number of results.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
function getTotalHits();
|
||||
public function getTotalHits();
|
||||
|
||||
/**
|
||||
* Returns the facets
|
||||
* Returns the facets.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function getFacets();
|
||||
public function getFacets();
|
||||
|
||||
/**
|
||||
* Returns the aggregations
|
||||
* Returns the aggregations.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function getAggregations();
|
||||
public function getAggregations();
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ use Elastica\ResultSet;
|
|||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Allows pagination of Elastica\Query. Does not map results
|
||||
* Allows pagination of Elastica\Query. Does not map results.
|
||||
*/
|
||||
class RawPaginatorAdapter implements PaginatorAdapterInterface
|
||||
{
|
||||
|
@ -46,7 +46,7 @@ class RawPaginatorAdapter implements PaginatorAdapterInterface
|
|||
* @see PaginatorAdapterInterface::__construct
|
||||
*
|
||||
* @param SearchableInterface $searchable the object to search in
|
||||
* @param Query $query the query to search
|
||||
* @param Query $query the query to search
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct(SearchableInterface $searchable, Query $query, array $options = array())
|
||||
|
@ -61,7 +61,9 @@ class RawPaginatorAdapter implements PaginatorAdapterInterface
|
|||
*
|
||||
* @param integer $offset
|
||||
* @param integer $itemCountPerPage
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return ResultSet
|
||||
*/
|
||||
protected function getElasticaResults($offset, $itemCountPerPage)
|
||||
|
@ -88,6 +90,7 @@ class RawPaginatorAdapter implements PaginatorAdapterInterface
|
|||
$this->totalHits = $resultSet->getTotalHits();
|
||||
$this->facets = $resultSet->getFacets();
|
||||
$this->aggregations = $resultSet->getAggregations();
|
||||
|
||||
return $resultSet;
|
||||
}
|
||||
|
||||
|
@ -96,6 +99,7 @@ class RawPaginatorAdapter implements PaginatorAdapterInterface
|
|||
*
|
||||
* @param int $offset
|
||||
* @param int $itemCountPerPage
|
||||
*
|
||||
* @return PartialResultsInterface
|
||||
*/
|
||||
public function getResults($offset, $itemCountPerPage)
|
||||
|
@ -106,14 +110,17 @@ class RawPaginatorAdapter implements PaginatorAdapterInterface
|
|||
/**
|
||||
* Returns the number of results.
|
||||
*
|
||||
* @param boolean $genuineTotal make the function return the `hits.total`
|
||||
* value of the search result in all cases, instead of limiting it to the
|
||||
* `size` request parameter.
|
||||
* If genuineTotal is provided as true, total hits is returned from the
|
||||
* hits.total value from the search results instead of just returning
|
||||
* the requested size.
|
||||
*
|
||||
* @param boolean $genuineTotal
|
||||
*
|
||||
* @return integer The number of results.
|
||||
*/
|
||||
public function getTotalHits($genuineTotal = false)
|
||||
{
|
||||
if ( ! isset($this->totalHits)) {
|
||||
if (! isset($this->totalHits)) {
|
||||
$this->totalHits = $this->searchable->search($this->query)->getTotalHits();
|
||||
}
|
||||
|
||||
|
@ -123,13 +130,13 @@ class RawPaginatorAdapter implements PaginatorAdapterInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns Facets
|
||||
* Returns Facets.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFacets()
|
||||
{
|
||||
if ( ! isset($this->facets)) {
|
||||
if (! isset($this->facets)) {
|
||||
$this->facets = $this->searchable->search($this->query)->getFacets();
|
||||
}
|
||||
|
||||
|
@ -137,11 +144,12 @@ class RawPaginatorAdapter implements PaginatorAdapterInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns Aggregations
|
||||
* Returns Aggregations.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAggregations() {
|
||||
public function getAggregations()
|
||||
{
|
||||
if (!isset($this->aggregations)) {
|
||||
$this->aggregations = $this->searchable->search($this->query)->getAggregations();
|
||||
}
|
||||
|
@ -150,7 +158,7 @@ class RawPaginatorAdapter implements PaginatorAdapterInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the Query
|
||||
* Returns the Query.
|
||||
*
|
||||
* @return Query the search query
|
||||
*/
|
||||
|
|
|
@ -6,7 +6,7 @@ use Elastica\ResultSet;
|
|||
use Elastica\Result;
|
||||
|
||||
/**
|
||||
* Raw partial results transforms to a simple array
|
||||
* Raw partial results transforms to a simple array.
|
||||
*/
|
||||
class RawPartialResults implements PartialResultsInterface
|
||||
{
|
||||
|
@ -25,7 +25,7 @@ class RawPartialResults implements PartialResultsInterface
|
|||
*/
|
||||
public function toArray()
|
||||
{
|
||||
return array_map(function(Result $result) {
|
||||
return array_map(function (Result $result) {
|
||||
return $result->getSource();
|
||||
}, $this->resultSet->getResults());
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ class RawPartialResults implements PartialResultsInterface
|
|||
return $this->resultSet->getFacets();
|
||||
}
|
||||
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -59,6 +59,6 @@ class RawPartialResults implements PartialResultsInterface
|
|||
return $this->resultSet->getAggregations();
|
||||
}
|
||||
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,15 +7,15 @@ use Elastica\SearchableInterface;
|
|||
use Elastica\Query;
|
||||
|
||||
/**
|
||||
* Allows pagination of \Elastica\Query
|
||||
* Allows pagination of \Elastica\Query.
|
||||
*/
|
||||
class TransformedPaginatorAdapter extends RawPaginatorAdapter
|
||||
{
|
||||
private $transformer;
|
||||
|
||||
/**
|
||||
* @param SearchableInterface $searchable the object to search in
|
||||
* @param Query $query the query to search
|
||||
* @param SearchableInterface $searchable the object to search in
|
||||
* @param Query $query the query to search
|
||||
* @param array $options
|
||||
* @param ElasticaToModelTransformerInterface $transformer the transformer for fetching the results
|
||||
*/
|
||||
|
|
|
@ -6,14 +6,14 @@ use FOS\ElasticaBundle\Transformer\ElasticaToModelTransformerInterface;
|
|||
use Elastica\ResultSet;
|
||||
|
||||
/**
|
||||
* Partial transformed result set
|
||||
* Partial transformed result set.
|
||||
*/
|
||||
class TransformedPartialResults extends RawPartialResults
|
||||
{
|
||||
protected $transformer;
|
||||
|
||||
/**
|
||||
* @param ResultSet $resultSet
|
||||
* @param ResultSet $resultSet
|
||||
* @param \FOS\ElasticaBundle\Transformer\ElasticaToModelTransformerInterface $transformer
|
||||
*/
|
||||
public function __construct(ResultSet $resultSet, ElasticaToModelTransformerInterface $transformer)
|
||||
|
|
|
@ -10,7 +10,7 @@ use Elastica\Document;
|
|||
|
||||
/**
|
||||
* Inserts, replaces and deletes single documents in an elastica type
|
||||
* Accepts domain model objects and converts them to elastica documents
|
||||
* Accepts domain model objects and converts them to elastica documents.
|
||||
*
|
||||
* @author Thibault Duplessis <thibault.duplessis@gmail.com>
|
||||
*/
|
||||
|
@ -34,6 +34,7 @@ class ObjectPersister implements ObjectPersisterInterface
|
|||
* If the ObjectPersister handles a given object.
|
||||
*
|
||||
* @param object $object
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function handlesObject($object)
|
||||
|
@ -41,17 +42,20 @@ class ObjectPersister implements ObjectPersisterInterface
|
|||
return $object instanceof $this->objectClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param LoggerInterface $logger
|
||||
*/
|
||||
public function setLogger(LoggerInterface $logger)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log exception if logger defined for persister belonging to the current listener, otherwise re-throw
|
||||
* Log exception if logger defined for persister belonging to the current listener, otherwise re-throw.
|
||||
*
|
||||
* @param BulkException $e
|
||||
*
|
||||
* @throws BulkException
|
||||
* @return null
|
||||
*/
|
||||
private function log(BulkException $e)
|
||||
{
|
||||
|
@ -64,7 +68,7 @@ class ObjectPersister implements ObjectPersisterInterface
|
|||
|
||||
/**
|
||||
* Insert one object into the type
|
||||
* The object will be transformed to an elastica document
|
||||
* The object will be transformed to an elastica document.
|
||||
*
|
||||
* @param object $object
|
||||
*/
|
||||
|
@ -74,10 +78,9 @@ class ObjectPersister implements ObjectPersisterInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Replaces one object in the type
|
||||
* Replaces one object in the type.
|
||||
*
|
||||
* @param object $object
|
||||
* @return null
|
||||
**/
|
||||
public function replaceOne($object)
|
||||
{
|
||||
|
@ -85,10 +88,9 @@ class ObjectPersister implements ObjectPersisterInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Deletes one object in the type
|
||||
* Deletes one object in the type.
|
||||
*
|
||||
* @param object $object
|
||||
* @return null
|
||||
**/
|
||||
public function deleteOne($object)
|
||||
{
|
||||
|
@ -96,11 +98,9 @@ class ObjectPersister implements ObjectPersisterInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Deletes one object in the type by id
|
||||
* Deletes one object in the type by id.
|
||||
*
|
||||
* @param mixed $id
|
||||
*
|
||||
* @return null
|
||||
**/
|
||||
public function deleteById($id)
|
||||
{
|
||||
|
@ -108,7 +108,7 @@ class ObjectPersister implements ObjectPersisterInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Bulk insert an array of objects in the type for the given method
|
||||
* Bulk insert an array of objects in the type for the given method.
|
||||
*
|
||||
* @param array $objects array of domain model objects
|
||||
* @param string Method to call
|
||||
|
@ -148,7 +148,7 @@ class ObjectPersister implements ObjectPersisterInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Bulk deletes an array of objects in the type
|
||||
* Bulk deletes an array of objects in the type.
|
||||
*
|
||||
* @param array $objects array of domain model objects
|
||||
*/
|
||||
|
@ -166,7 +166,7 @@ class ObjectPersister implements ObjectPersisterInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Bulk deletes records from an array of identifiers
|
||||
* Bulk deletes records from an array of identifiers.
|
||||
*
|
||||
* @param array $identifiers array of domain model object identifiers
|
||||
*/
|
||||
|
@ -180,9 +180,10 @@ class ObjectPersister implements ObjectPersisterInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Transforms an object to an elastica document
|
||||
* Transforms an object to an elastica document.
|
||||
*
|
||||
* @param object $object
|
||||
*
|
||||
* @return Document the elastica document
|
||||
*/
|
||||
public function transformToElasticaDocument($object)
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace FOS\ElasticaBundle\Persister;
|
|||
|
||||
/**
|
||||
* Inserts, replaces and deletes single documents in an elastica type
|
||||
* Accepts domain model objects and converts them to elastica documents
|
||||
* Accepts domain model objects and converts them to elastica documents.
|
||||
*
|
||||
* @author Thibault Duplessis <thibault.duplessis@gmail.com>
|
||||
*/
|
||||
|
@ -12,58 +12,56 @@ interface ObjectPersisterInterface
|
|||
{
|
||||
/**
|
||||
* Insert one object into the type
|
||||
* The object will be transformed to an elastica document
|
||||
* The object will be transformed to an elastica document.
|
||||
*
|
||||
* @param object $object
|
||||
*/
|
||||
function insertOne($object);
|
||||
public function insertOne($object);
|
||||
|
||||
/**
|
||||
* Replaces one object in the type
|
||||
* Replaces one object in the type.
|
||||
*
|
||||
* @param object $object
|
||||
**/
|
||||
function replaceOne($object);
|
||||
public function replaceOne($object);
|
||||
|
||||
/**
|
||||
* Deletes one object in the type
|
||||
* Deletes one object in the type.
|
||||
*
|
||||
* @param object $object
|
||||
**/
|
||||
function deleteOne($object);
|
||||
public function deleteOne($object);
|
||||
|
||||
/**
|
||||
* Deletes one object in the type by id
|
||||
* Deletes one object in the type by id.
|
||||
*
|
||||
* @param mixed $id
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
function deleteById($id);
|
||||
public function deleteById($id);
|
||||
|
||||
/**
|
||||
* Bulk inserts an array of objects in the type
|
||||
* Bulk inserts an array of objects in the type.
|
||||
*
|
||||
* @param array $objects array of domain model objects
|
||||
*/
|
||||
function insertMany(array $objects);
|
||||
public function insertMany(array $objects);
|
||||
|
||||
/**
|
||||
* Bulk updates an array of objects in the type
|
||||
* Bulk updates an array of objects in the type.
|
||||
*
|
||||
* @param array $objects array of domain model objects
|
||||
*/
|
||||
function replaceMany(array $objects);
|
||||
public function replaceMany(array $objects);
|
||||
|
||||
/**
|
||||
* Bulk deletes an array of objects in the type
|
||||
* Bulk deletes an array of objects in the type.
|
||||
*
|
||||
* @param array $objects array of domain model objects
|
||||
*/
|
||||
function deleteMany(array $objects);
|
||||
public function deleteMany(array $objects);
|
||||
|
||||
/**
|
||||
* Bulk deletes records from an array of identifiers
|
||||
* Bulk deletes records from an array of identifiers.
|
||||
*
|
||||
* @param array $identifiers array of domain model object identifiers
|
||||
*/
|
||||
|
@ -73,6 +71,7 @@ interface ObjectPersisterInterface
|
|||
* If the object persister handles the given object.
|
||||
*
|
||||
* @param object $object
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function handlesObject($object);
|
||||
|
|
|
@ -9,7 +9,7 @@ use FOS\ElasticaBundle\Transformer\ModelToElasticaTransformerInterface;
|
|||
/**
|
||||
* Inserts, replaces and deletes single objects in an elastica type, making use
|
||||
* of elastica's serializer support to convert objects in to elastica documents.
|
||||
* Accepts domain model objects and passes them directly to elastica
|
||||
* Accepts domain model objects and passes them directly to elastica.
|
||||
*
|
||||
* @author Lea Haensenberber <lea.haensenberger@gmail.com>
|
||||
*/
|
||||
|
@ -28,9 +28,10 @@ class ObjectSerializerPersister extends ObjectPersister
|
|||
|
||||
/**
|
||||
* Transforms an object to an elastica document
|
||||
* with just the identifier set
|
||||
* with just the identifier set.
|
||||
*
|
||||
* @param object $object
|
||||
*
|
||||
* @return Document the elastica document
|
||||
*/
|
||||
public function transformToElasticaDocument($object)
|
||||
|
|
|
@ -44,7 +44,7 @@ class ElasticaToModelTransformer implements ElasticaToModelTransformerInterface
|
|||
* Constructor.
|
||||
*
|
||||
* @param string $objectClass
|
||||
* @param array $options
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct($objectClass, array $options = array())
|
||||
{
|
||||
|
@ -67,6 +67,7 @@ class ElasticaToModelTransformer implements ElasticaToModelTransformerInterface
|
|||
* fetched from the database.
|
||||
*
|
||||
* @param array $elasticaObjects
|
||||
*
|
||||
* @return array|\ArrayObject
|
||||
*/
|
||||
public function transform(array $elasticaObjects)
|
||||
|
@ -83,7 +84,7 @@ class ElasticaToModelTransformer implements ElasticaToModelTransformerInterface
|
|||
$identifier = $this->options['identifier'];
|
||||
$propertyAccessor = $this->propertyAccessor;
|
||||
|
||||
$sortCallback = function($a, $b) use ($idPos, $identifier, $propertyAccessor) {
|
||||
$sortCallback = function ($a, $b) use ($idPos, $identifier, $propertyAccessor) {
|
||||
return $idPos[$propertyAccessor->getValue($a, $identifier)] > $idPos[$propertyAccessor->getValue($b, $identifier)];
|
||||
};
|
||||
|
||||
|
@ -135,6 +136,7 @@ class ElasticaToModelTransformer implements ElasticaToModelTransformerInterface
|
|||
*
|
||||
* @param array $identifierValues Identifier values
|
||||
* @param boolean $hydrate Whether or not to hydrate the results
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function findByIdentifiers(array $identifierValues, $hydrate)
|
||||
|
@ -145,7 +147,7 @@ class ElasticaToModelTransformer implements ElasticaToModelTransformerInterface
|
|||
|
||||
$query = $this->createQuery($this->objectClass, $this->options['identifier'], $identifierValues);
|
||||
|
||||
if ( ! $hydrate) {
|
||||
if (! $hydrate) {
|
||||
return $query->toArray();
|
||||
}
|
||||
|
||||
|
@ -158,6 +160,7 @@ class ElasticaToModelTransformer implements ElasticaToModelTransformerInterface
|
|||
* @param string $class Propel model class
|
||||
* @param string $identifierField Identifier field name (e.g. "id")
|
||||
* @param array $identifierValues Identifier values
|
||||
*
|
||||
* @return \ModelCriteria
|
||||
*/
|
||||
protected function createQuery($class, $identifierField, array $identifierValues)
|
||||
|
@ -170,6 +173,7 @@ class ElasticaToModelTransformer implements ElasticaToModelTransformerInterface
|
|||
|
||||
/**
|
||||
* @see https://github.com/doctrine/common/blob/master/lib/Doctrine/Common/Util/Inflector.php
|
||||
*
|
||||
* @param string $str
|
||||
*/
|
||||
private function camelize($str)
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace FOS\ElasticaBundle\Propel;
|
|||
use FOS\ElasticaBundle\Provider\AbstractProvider;
|
||||
|
||||
/**
|
||||
* Propel provider
|
||||
* Propel provider.
|
||||
*
|
||||
* @author William Durand <william.durand1@gmail.com>
|
||||
*/
|
||||
|
@ -16,7 +16,7 @@ class Provider extends AbstractProvider
|
|||
*/
|
||||
public function populate(\Closure $loggerClosure = null, array $options = array())
|
||||
{
|
||||
$queryClass = $this->objectClass . 'Query';
|
||||
$queryClass = $this->objectClass.'Query';
|
||||
$nbObjects = $queryClass::create()->count();
|
||||
$offset = isset($options['offset']) ? intval($options['offset']) : 0;
|
||||
$sleep = isset($options['sleep']) ? intval($options['sleep']) : 0;
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace FOS\ElasticaBundle\Provider;
|
|||
use FOS\ElasticaBundle\Persister\ObjectPersisterInterface;
|
||||
|
||||
/**
|
||||
* AbstractProvider
|
||||
* AbstractProvider.
|
||||
*/
|
||||
abstract class AbstractProvider implements ProviderInterface
|
||||
{
|
||||
|
@ -33,9 +33,9 @@ abstract class AbstractProvider implements ProviderInterface
|
|||
* Constructor.
|
||||
*
|
||||
* @param ObjectPersisterInterface $objectPersister
|
||||
* @param IndexableInterface $indexable
|
||||
* @param string $objectClass
|
||||
* @param array $options
|
||||
* @param IndexableInterface $indexable
|
||||
* @param string $objectClass
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct(
|
||||
ObjectPersisterInterface $objectPersister,
|
||||
|
@ -56,6 +56,7 @@ abstract class AbstractProvider implements ProviderInterface
|
|||
* Checks if a given object should be indexed or not.
|
||||
*
|
||||
* @param object $object
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isObjectIndexable($object)
|
||||
|
@ -68,9 +69,10 @@ abstract class AbstractProvider implements ProviderInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Get string with RAM usage information (current and peak)
|
||||
* Get string with RAM usage information (current and peak).
|
||||
*
|
||||
* @deprecated To be removed in 4.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getMemoryUsage()
|
||||
|
|
|
@ -33,7 +33,7 @@ class Indexable implements IndexableInterface
|
|||
private $container;
|
||||
|
||||
/**
|
||||
* An instance of ExpressionLanguage
|
||||
* An instance of ExpressionLanguage.
|
||||
*
|
||||
* @var ExpressionLanguage
|
||||
*/
|
||||
|
@ -47,7 +47,7 @@ class Indexable implements IndexableInterface
|
|||
private $initialisedCallbacks = array();
|
||||
|
||||
/**
|
||||
* PropertyAccessor instance
|
||||
* PropertyAccessor instance.
|
||||
*
|
||||
* @var PropertyAccessorInterface
|
||||
*/
|
||||
|
@ -68,7 +68,8 @@ class Indexable implements IndexableInterface
|
|||
*
|
||||
* @param string $indexName
|
||||
* @param string $typeName
|
||||
* @param mixed $object
|
||||
* @param mixed $object
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isObjectIndexable($indexName, $typeName, $object)
|
||||
|
@ -82,7 +83,7 @@ class Indexable implements IndexableInterface
|
|||
if ($callback instanceof Expression) {
|
||||
return $this->getExpressionLanguage()->evaluate($callback, array(
|
||||
'object' => $object,
|
||||
$this->getExpressionVar($object) => $object
|
||||
$this->getExpressionVar($object) => $object,
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -96,12 +97,13 @@ class Indexable implements IndexableInterface
|
|||
*
|
||||
* @param string $type
|
||||
* @param object $object
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function buildCallback($type, $object)
|
||||
{
|
||||
if (!array_key_exists($type, $this->callbacks)) {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
$callback = $this->callbacks[$type];
|
||||
|
@ -148,6 +150,7 @@ class Indexable implements IndexableInterface
|
|||
*
|
||||
* @param string $type
|
||||
* @param object $object
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function getCallback($type, $object)
|
||||
|
@ -177,6 +180,7 @@ class Indexable implements IndexableInterface
|
|||
|
||||
/**
|
||||
* @param mixed $object
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getExpressionVar($object = null)
|
||||
|
|
|
@ -18,7 +18,8 @@ interface IndexableInterface
|
|||
*
|
||||
* @param string $indexName
|
||||
* @param string $typeName
|
||||
* @param mixed $object
|
||||
* @param mixed $object
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isObjectIndexable($indexName, $typeName, $object);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace FOS\ElasticaBundle\Provider;
|
||||
|
||||
/**
|
||||
* Insert application domain objects into elastica types
|
||||
* Insert application domain objects into elastica types.
|
||||
*
|
||||
* @author Thibault Duplessis <thibault.duplessis@gmail.com>
|
||||
*/
|
||||
|
@ -19,7 +19,8 @@ interface ProviderInterface
|
|||
*
|
||||
* @param \Closure $loggerClosure
|
||||
* @param array $options
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
function populate(\Closure $loggerClosure = null, array $options = array());
|
||||
public function populate(\Closure $loggerClosure = null, array $options = array());
|
||||
}
|
||||
|
|
|
@ -57,8 +57,10 @@ class ProviderRegistry implements ContainerAwareInterface
|
|||
*
|
||||
* Providers will be indexed by "type" strings in the returned array.
|
||||
*
|
||||
* @param string $index
|
||||
* @param string $index
|
||||
*
|
||||
* @return ProviderInterface[]
|
||||
*
|
||||
* @throws \InvalidArgumentException if no providers were registered for the index
|
||||
*/
|
||||
public function getIndexProviders($index)
|
||||
|
@ -81,7 +83,9 @@ class ProviderRegistry implements ContainerAwareInterface
|
|||
*
|
||||
* @param string $index
|
||||
* @param string $type
|
||||
*
|
||||
* @return ProviderInterface
|
||||
*
|
||||
* @throws \InvalidArgumentException if no provider was registered for the index and type
|
||||
*/
|
||||
public function getProvider($index, $type)
|
||||
|
|
|
@ -20,9 +20,10 @@ class Repository
|
|||
}
|
||||
|
||||
/**
|
||||
* @param mixed $query
|
||||
* @param mixed $query
|
||||
* @param integer $limit
|
||||
* @param array $options
|
||||
* @param array $options
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function find($query, $limit = null, $options = array())
|
||||
|
@ -31,9 +32,10 @@ class Repository
|
|||
}
|
||||
|
||||
/**
|
||||
* @param mixed $query
|
||||
* @param mixed $query
|
||||
* @param integer $limit
|
||||
* @param array $options
|
||||
* @param array $options
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function findHybrid($query, $limit = null, $options = array())
|
||||
|
@ -44,6 +46,7 @@ class Repository
|
|||
/**
|
||||
* @param mixed $query
|
||||
* @param array $options
|
||||
*
|
||||
* @return \Pagerfanta\Pagerfanta
|
||||
*/
|
||||
public function findPaginated($query, $options = array())
|
||||
|
@ -53,7 +56,8 @@ class Repository
|
|||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param array $options
|
||||
* @param array $options
|
||||
*
|
||||
* @return Paginator\PaginatorAdapterInterface
|
||||
*/
|
||||
public function createPaginatorAdapter($query, $options = array())
|
||||
|
|
|
@ -42,7 +42,7 @@ class PaginateElasticaQuerySubscriber implements EventSubscriberInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Adds knp paging sort to query
|
||||
* Adds knp paging sort to query.
|
||||
*
|
||||
* @param ItemsEvent $event
|
||||
*/
|
||||
|
@ -74,7 +74,7 @@ class PaginateElasticaQuerySubscriber implements EventSubscriberInterface
|
|||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
'knp_pager.items' => array('items', 1)
|
||||
'knp_pager.items' => array('items', 1),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace FOS\ElasticaBundle\Tests\Command;
|
||||
|
||||
|
||||
use FOS\ElasticaBundle\Command\ResetCommand;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Output\NullOutput;
|
||||
|
|
|
@ -6,7 +6,7 @@ use FOS\ElasticaBundle\DependencyInjection\Configuration;
|
|||
use Symfony\Component\Config\Definition\Processor;
|
||||
|
||||
/**
|
||||
* ConfigurationTest
|
||||
* ConfigurationTest.
|
||||
*/
|
||||
class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
@ -34,7 +34,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertSame(array(
|
||||
'clients' => array(),
|
||||
'indexes' => array(),
|
||||
'default_manager' => 'orm'
|
||||
'default_manager' => 'orm',
|
||||
), $configuration);
|
||||
}
|
||||
|
||||
|
@ -50,18 +50,18 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
|||
array(
|
||||
'url' => 'http://es1:9200',
|
||||
'headers' => array(
|
||||
'Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=='
|
||||
)
|
||||
'Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'url' => 'http://es2:9200',
|
||||
'headers' => array(
|
||||
'Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=='
|
||||
)
|
||||
'Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==',
|
||||
),
|
||||
),
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
$this->assertCount(2, $configuration['clients']);
|
||||
|
@ -91,9 +91,9 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
|||
),
|
||||
'logging_custom' => array(
|
||||
'url' => 'http://localhost:9200',
|
||||
'logger' => 'custom.service'
|
||||
'logger' => 'custom.service',
|
||||
),
|
||||
)
|
||||
),
|
||||
));
|
||||
|
||||
$this->assertCount(4, $configuration['clients']);
|
||||
|
@ -131,8 +131,8 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
|||
),
|
||||
'serializer' => array(
|
||||
'groups' => array('Search'),
|
||||
'version' => 1
|
||||
)
|
||||
'version' => 1,
|
||||
),
|
||||
),
|
||||
'types' => array(
|
||||
'test' => array(
|
||||
|
@ -144,20 +144,20 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
|||
'persistence' => array(
|
||||
'listener' => array(
|
||||
'logger' => true,
|
||||
)
|
||||
)
|
||||
),
|
||||
),
|
||||
),
|
||||
'test2' => array(
|
||||
'mappings' => array(
|
||||
'title' => null,
|
||||
'children' => array(
|
||||
'type' => 'nested',
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -169,7 +169,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
|||
'host' => 'localhost',
|
||||
'port' => 9200,
|
||||
),
|
||||
)
|
||||
),
|
||||
));
|
||||
|
||||
$this->assertTrue(empty($configuration['clients']['default']['connections'][0]['url']));
|
||||
|
@ -189,11 +189,11 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
|||
'title' => array(),
|
||||
'published' => array('type' => 'datetime'),
|
||||
'body' => null,
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
$this->assertCount(3, $configuration['indexes']['test']['types']['test']['properties']);
|
||||
|
@ -208,10 +208,10 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
|||
'indexes' => array(
|
||||
'test' => array(
|
||||
'types' => array(
|
||||
'test' => null
|
||||
)
|
||||
)
|
||||
)
|
||||
'test' => null,
|
||||
),
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
$this->assertArrayHasKey('properties', $configuration['indexes']['test']['types']['test']);
|
||||
|
@ -243,23 +243,23 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
|||
'type' => 'nested',
|
||||
'properties' => array(
|
||||
'nested_field1' => array(
|
||||
'type' => 'integer'
|
||||
'type' => 'integer',
|
||||
),
|
||||
'nested_field2' => array(
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'id' => array(
|
||||
'type' => 'integer'
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
'type' => 'integer',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,10 +12,10 @@ class FOSElasticaExtensionTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
$config = Yaml::parse(file_get_contents(__DIR__.'/fixtures/config.yml'));
|
||||
|
||||
$containerBuilder = new ContainerBuilder;
|
||||
$containerBuilder = new ContainerBuilder();
|
||||
$containerBuilder->setParameter('kernel.debug', true);
|
||||
|
||||
$extension = new FOSElasticaExtension;
|
||||
$extension = new FOSElasticaExtension();
|
||||
|
||||
$extension->load($config, $containerBuilder);
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ class AbstractElasticaToModelTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
protected $objectClass = 'stdClass';
|
||||
|
||||
/**
|
||||
* Tests if ignore_missing option is properly handled in transformHybrid() method
|
||||
* Tests if ignore_missing option is properly handled in transformHybrid() method.
|
||||
*/
|
||||
public function testIgnoreMissingOptionDuringTransformHybrid()
|
||||
{
|
||||
|
@ -55,10 +55,6 @@ class AbstractElasticaToModelTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
protected function setUp()
|
||||
{
|
||||
if (!interface_exists('Doctrine\Common\Persistence\ManagerRegistry')) {
|
||||
$this->markTestSkipped('Doctrine Common is not present');
|
||||
}
|
||||
|
||||
$this->registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace FOS\ElasticaBundle\Tests\Doctrine;
|
||||
|
||||
/**
|
||||
* See concrete MongoDB/ORM instances of this abstract test
|
||||
* See concrete MongoDB/ORM instances of this abstract test.
|
||||
*
|
||||
* @author Richard Miller <info@limethinking.co.uk>
|
||||
*/
|
||||
|
@ -213,8 +213,8 @@ abstract class ListenerTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
/**
|
||||
* @param Listener\Entity $object
|
||||
* @param string $indexName
|
||||
* @param string $typeName
|
||||
* @param string $indexName
|
||||
* @param string $typeName
|
||||
*/
|
||||
private function getMockPersister($object, $indexName, $typeName)
|
||||
{
|
||||
|
@ -247,10 +247,10 @@ abstract class ListenerTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $indexName
|
||||
* @param string $typeName
|
||||
* @param string $indexName
|
||||
* @param string $typeName
|
||||
* @param Listener\Entity $object
|
||||
* @param boolean $return
|
||||
* @param boolean $return
|
||||
*/
|
||||
private function getMockIndexable($indexName, $typeName, $object, $return = null)
|
||||
{
|
||||
|
@ -286,4 +286,3 @@ class Entity
|
|||
return $this->id;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,13 +17,9 @@ class AbstractProviderTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
public function setUp()
|
||||
{
|
||||
if (!interface_exists('Doctrine\Common\Persistence\ManagerRegistry')) {
|
||||
$this->markTestSkipped('Doctrine Common is not available.');
|
||||
}
|
||||
|
||||
$this->objectClass = 'objectClass';
|
||||
$this->options = array('debug_logging' => true, 'indexName' => 'index', 'typeName' => 'type');
|
||||
|
||||
<
|
||||
$this->objectPersister = $this->getMockObjectPersister();
|
||||
$this->managerRegistry = $this->getMockManagerRegistry();
|
||||
$this->objectManager = $this->getMockObjectManager();
|
||||
|
@ -135,7 +131,7 @@ class AbstractProviderTest extends \PHPUnit_Framework_TestCase
|
|||
return array(
|
||||
array(
|
||||
100,
|
||||
array(range(1,100)),
|
||||
array(range(1, 100)),
|
||||
100,
|
||||
),
|
||||
array(
|
||||
|
@ -283,7 +279,6 @@ class AbstractProviderTest extends \PHPUnit_Framework_TestCase
|
|||
->with('index', 'type', 2)
|
||||
->will($this->returnValue(true));
|
||||
|
||||
|
||||
$this->objectPersister->expects($this->once())
|
||||
->method('insertMany')
|
||||
->with(array(1 => 2));
|
||||
|
@ -314,7 +309,7 @@ class AbstractProviderTest extends \PHPUnit_Framework_TestCase
|
|||
private function getMockBulkResponseException()
|
||||
{
|
||||
return $this->getMock('Elastica\Exception\Bulk\ResponseException', null, array(
|
||||
new ResponseSet(new Response(array()), array())
|
||||
new ResponseSet(new Response(array()), array()),
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -331,7 +326,7 @@ class AbstractProviderTest extends \PHPUnit_Framework_TestCase
|
|||
*/
|
||||
private function getMockObjectManager()
|
||||
{
|
||||
$mock = $this->getMock(__NAMESPACE__ . '\ObjectManager');
|
||||
$mock = $this->getMock(__NAMESPACE__.'\ObjectManager');
|
||||
|
||||
$mock->expects($this->any())
|
||||
->method('getClassMetadata')
|
||||
|
@ -375,7 +370,7 @@ class AbstractProviderTest extends \PHPUnit_Framework_TestCase
|
|||
*/
|
||||
interface ObjectManager
|
||||
{
|
||||
function clear();
|
||||
function getClassMetadata();
|
||||
function getIdentifierFieldNames();
|
||||
public function clear();
|
||||
public function getClassMetadata();
|
||||
public function getIdentifierFieldNames();
|
||||
}
|
||||
|
|
|
@ -82,13 +82,6 @@ class ElasticaToModelTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
protected function setUp()
|
||||
{
|
||||
if (!interface_exists('Doctrine\Common\Persistence\ManagerRegistry')) {
|
||||
$this->markTestSkipped('Doctrine Common is not present');
|
||||
}
|
||||
if (!class_exists('Doctrine\ORM\EntityManager')) {
|
||||
$this->markTestSkipped('Doctrine Common is not present');
|
||||
}
|
||||
|
||||
$this->registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
@ -109,7 +102,7 @@ class ElasticaToModelTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
'findAll',
|
||||
'findBy',
|
||||
'findOneBy',
|
||||
'getClassName'
|
||||
'getClassName',
|
||||
));
|
||||
|
||||
$this->manager->expects($this->any())
|
||||
|
|
|
@ -6,13 +6,6 @@ use FOS\ElasticaBundle\Tests\Doctrine\ListenerTest as BaseListenerTest;
|
|||
|
||||
class ListenerTest extends BaseListenerTest
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
if (!class_exists('Doctrine\ORM\EntityManager')) {
|
||||
$this->markTestSkipped('Doctrine ORM is not available.');
|
||||
}
|
||||
}
|
||||
|
||||
protected function getClassMetadataClass()
|
||||
{
|
||||
return 'Doctrine\ORM\Mapping\ClassMetadata';
|
||||
|
|
|
@ -4,22 +4,19 @@ namespace FOS\ElasticaBundle\Tests\Doctrine;
|
|||
|
||||
use FOS\ElasticaBundle\Doctrine\RepositoryManager;
|
||||
|
||||
class CustomRepository{}
|
||||
class CustomRepository
|
||||
{
|
||||
}
|
||||
|
||||
class Entity{}
|
||||
class Entity
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Richard Miller <info@limethinking.co.uk>
|
||||
*/
|
||||
class RepositoryManagerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
if (!interface_exists('Doctrine\Common\Persistence\ManagerRegistry')) {
|
||||
$this->markTestSkipped('Doctrine Common is not available.');
|
||||
}
|
||||
}
|
||||
|
||||
public function testThatGetRepositoryReturnsDefaultRepository()
|
||||
{
|
||||
/** @var $finderMock \PHPUnit_Framework_MockObject_MockObject|\FOS\ElasticaBundle\Finder\TransformedFinder */
|
||||
|
|
|
@ -5,11 +5,11 @@ namespace FOS\ElasticaBundle\Tests\Client;
|
|||
use Elastica\Request;
|
||||
use Elastica\Transport\Null as NullTransport;
|
||||
|
||||
class LoggingClientTest extends \PHPUnit_Framework_TestCase
|
||||
class ClientTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testRequestsAreLogged()
|
||||
{
|
||||
$transport = new NullTransport;
|
||||
$transport = new NullTransport();
|
||||
|
||||
$connection = $this->getMock('Elastica\Connection');
|
||||
$connection->expects($this->any())->method('getTransportObject')->will($this->returnValue($transport));
|
||||
|
|
|
@ -16,7 +16,6 @@ class FOSElasticaBundleTest extends \PHPUnit_Framework_TestCase
|
|||
->method('addCompilerPass')
|
||||
->with($this->isInstanceOf('Symfony\\Component\\DependencyInjection\\Compiler\\CompilerPassInterface'));
|
||||
|
||||
|
||||
$bundle = new FOSElasticaBundle();
|
||||
$bundle->build($container);
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ class ConfigurationManagerTest extends WebTestCase
|
|||
|
||||
/**
|
||||
* @param Client $client
|
||||
*
|
||||
* @return \FOS\ElasticaBundle\Configuration\ConfigManager
|
||||
*/
|
||||
private function getManager(Client $client)
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace FOS\ElasticaBundle\Tests\Functional;
|
|||
class IndexableCallbackTest extends WebTestCase
|
||||
{
|
||||
/**
|
||||
* 2 reasons for this test:
|
||||
* 2 reasons for this test:.
|
||||
*
|
||||
* 1) To test that the configuration rename from is_indexable_callback under the listener
|
||||
* key is respected, and
|
||||
|
|
|
@ -103,6 +103,7 @@ class MappingToElasticaTest extends WebTestCase
|
|||
|
||||
/**
|
||||
* @param Client $client
|
||||
*
|
||||
* @return \FOS\ElasticaBundle\Resetter $resetter
|
||||
*/
|
||||
private function getResetter(Client $client)
|
||||
|
@ -113,11 +114,12 @@ class MappingToElasticaTest extends WebTestCase
|
|||
/**
|
||||
* @param Client $client
|
||||
* @param string $type
|
||||
*
|
||||
* @return \Elastica\Type
|
||||
*/
|
||||
private function getType(Client $client, $type = 'type')
|
||||
{
|
||||
return $client->getContainer()->get('fos_elastica.index.index.' . $type);
|
||||
return $client->getContainer()->get('fos_elastica.index.index.'.$type);
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
|
|
|
@ -47,4 +47,3 @@ fos_elastica:
|
|||
serializer:
|
||||
groups: ['search', 'Default']
|
||||
version: 1.1
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@ class IndexManagerTest extends \PHPUnit_Framework_TestCase
|
|||
*/
|
||||
private $indexManager;
|
||||
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
foreach (array('index1', 'index2', 'index3') as $indexName) {
|
||||
|
|
|
@ -8,10 +8,8 @@
|
|||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
|
||||
namespace FOS\ElasticaBundle\Tests\Integration;
|
||||
|
||||
|
||||
class MappingTest {
|
||||
|
||||
class MappingTest
|
||||
{
|
||||
}
|
|
@ -22,7 +22,8 @@ class ElasticaLoggerTest extends \PHPUnit_Framework_TestCase
|
|||
/**
|
||||
* @param string $level
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @param array $context
|
||||
*
|
||||
* @return ElasticaLogger
|
||||
*/
|
||||
private function getMockLoggerForLevelMessageAndContext($level, $message, $context)
|
||||
|
@ -45,7 +46,7 @@ class ElasticaLoggerTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
public function testGetZeroIfNoQueriesAdded()
|
||||
{
|
||||
$elasticaLogger = new ElasticaLogger;
|
||||
$elasticaLogger = new ElasticaLogger();
|
||||
$this->assertEquals(0, $elasticaLogger->getNbQueries());
|
||||
}
|
||||
|
||||
|
|
|
@ -4,16 +4,19 @@ namespace FOS\ElasticaBundle\Tests\Manager;
|
|||
|
||||
use FOS\ElasticaBundle\Manager\RepositoryManager;
|
||||
|
||||
class CustomRepository{}
|
||||
class CustomRepository
|
||||
{
|
||||
}
|
||||
|
||||
class Entity{}
|
||||
class Entity
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Richard Miller <info@limethinking.co.uk>
|
||||
*/
|
||||
class RepositoryManagerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testThatGetRepositoryReturnsDefaultRepository()
|
||||
{
|
||||
/** @var $finderMock \PHPUnit_Framework_MockObject_MockObject|\FOS\ElasticaBundle\Finder\TransformedFinder */
|
||||
|
|
|
@ -31,13 +31,6 @@ class InvalidObjectPersister extends ObjectPersister
|
|||
|
||||
class ObjectPersisterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
if (!class_exists('Elastica\Type')) {
|
||||
$this->markTestSkipped('The Elastica library classes are not available');
|
||||
}
|
||||
}
|
||||
|
||||
public function testThatCanReplaceObject()
|
||||
{
|
||||
$transformer = $this->getTransformer();
|
||||
|
|
|
@ -24,13 +24,6 @@ class POPO
|
|||
|
||||
class ObjectSerializerPersisterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
if (!class_exists('Elastica\Type')) {
|
||||
$this->markTestSkipped('The Elastica library classes are not available');
|
||||
}
|
||||
}
|
||||
|
||||
public function testThatCanReplaceObject()
|
||||
{
|
||||
$transformer = $this->getTransformer();
|
||||
|
|
|
@ -21,7 +21,7 @@ class IndexableTest extends \PHPUnit_Framework_TestCase
|
|||
public function testIndexableUnknown()
|
||||
{
|
||||
$indexable = new Indexable(array(), $this->container);
|
||||
$index = $indexable->isObjectIndexable('index', 'type', new Entity);
|
||||
$index = $indexable->isObjectIndexable('index', 'type', new Entity());
|
||||
|
||||
$this->assertTrue($index);
|
||||
}
|
||||
|
@ -32,9 +32,9 @@ class IndexableTest extends \PHPUnit_Framework_TestCase
|
|||
public function testValidIndexableCallbacks($callback, $return)
|
||||
{
|
||||
$indexable = new Indexable(array(
|
||||
'index/type' => $callback
|
||||
'index/type' => $callback,
|
||||
), $this->container);
|
||||
$index = $indexable->isObjectIndexable('index', 'type', new Entity);
|
||||
$index = $indexable->isObjectIndexable('index', 'type', new Entity());
|
||||
|
||||
$this->assertEquals($return, $index);
|
||||
}
|
||||
|
@ -46,9 +46,9 @@ class IndexableTest extends \PHPUnit_Framework_TestCase
|
|||
public function testInvalidIsIndexableCallbacks($callback)
|
||||
{
|
||||
$indexable = new Indexable(array(
|
||||
'index/type' => $callback
|
||||
'index/type' => $callback,
|
||||
), $this->container);
|
||||
$indexable->isObjectIndexable('index', 'type', new Entity);
|
||||
$indexable->isObjectIndexable('index', 'type', new Entity());
|
||||
}
|
||||
|
||||
public function provideInvalidIsIndexableCallbacks()
|
||||
|
@ -67,7 +67,7 @@ class IndexableTest extends \PHPUnit_Framework_TestCase
|
|||
array('isIndexable', false),
|
||||
array(array(new IndexableDecider(), 'isIndexable'), true),
|
||||
array(array('@indexableService', 'isIndexable'), true),
|
||||
array(function(Entity $entity) { return $entity->maybeIndex(); }, true),
|
||||
array(function (Entity $entity) { return $entity->maybeIndex(); }, true),
|
||||
array('entity.maybeIndex()', true),
|
||||
array('!object.isIndexable() && entity.property == "abc"', true),
|
||||
array('entity.property != "abc"', false),
|
||||
|
|
|
@ -13,14 +13,7 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
$testQuery = 'Test Query';
|
||||
|
||||
/** @var $typeMock \PHPUnit_Framework_MockObject_MockObject|\FOS\ElasticaBundle\Finder\TransformedFinder */
|
||||
$finderMock = $this->getMockBuilder('FOS\ElasticaBundle\Finder\TransformedFinder')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$finderMock->expects($this->once())
|
||||
->method('find')
|
||||
->with($this->equalTo($testQuery));
|
||||
|
||||
$finderMock = $this->getFinderMock($testQuery);
|
||||
$repository = new Repository($finderMock);
|
||||
$repository->find($testQuery);
|
||||
}
|
||||
|
@ -30,14 +23,7 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase
|
|||
$testQuery = 'Test Query';
|
||||
$testLimit = 20;
|
||||
|
||||
/** @var $typeMock \PHPUnit_Framework_MockObject_MockObject|\FOS\ElasticaBundle\Finder\TransformedFinder */
|
||||
$finderMock = $this->getMockBuilder('FOS\ElasticaBundle\Finder\TransformedFinder')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$finderMock->expects($this->once())
|
||||
->method('find')
|
||||
->with($this->equalTo($testQuery), $this->equalTo($testLimit));
|
||||
|
||||
$finderMock = $this->getFinderMock($testQuery, $testLimit);
|
||||
$repository = new Repository($finderMock);
|
||||
$repository->find($testQuery, $testLimit);
|
||||
}
|
||||
|
@ -46,14 +32,7 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
$testQuery = 'Test Query';
|
||||
|
||||
/** @var $typeMock \PHPUnit_Framework_MockObject_MockObject|\FOS\ElasticaBundle\Finder\TransformedFinder */
|
||||
$finderMock = $this->getMockBuilder('FOS\ElasticaBundle\Finder\TransformedFinder')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$finderMock->expects($this->once())
|
||||
->method('findPaginated')
|
||||
->with($this->equalTo($testQuery));
|
||||
|
||||
$finderMock = $this->getFinderMock($testQuery, array(), 'findPaginated');
|
||||
$repository = new Repository($finderMock);
|
||||
$repository->findPaginated($testQuery);
|
||||
}
|
||||
|
@ -62,14 +41,7 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
$testQuery = 'Test Query';
|
||||
|
||||
/** @var $typeMock \PHPUnit_Framework_MockObject_MockObject|\FOS\ElasticaBundle\Finder\TransformedFinder */
|
||||
$finderMock = $this->getMockBuilder('FOS\ElasticaBundle\Finder\TransformedFinder')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$finderMock->expects($this->once())
|
||||
->method('createPaginatorAdapter')
|
||||
->with($this->equalTo($testQuery));
|
||||
|
||||
$finderMock = $this->getFinderMock($testQuery, array(), 'createPaginatorAdapter');
|
||||
$repository = new Repository($finderMock);
|
||||
$repository->createPaginatorAdapter($testQuery);
|
||||
}
|
||||
|
@ -77,17 +49,28 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase
|
|||
public function testThatFindHybridCallsFindHybridOnFinder()
|
||||
{
|
||||
$testQuery = 'Test Query';
|
||||
$testLimit = 20;
|
||||
|
||||
/** @var $typeMock \PHPUnit_Framework_MockObject_MockObject|\FOS\ElasticaBundle\Finder\TransformedFinder */
|
||||
$finderMock = $this->getFinderMock($testQuery, null, 'findHybrid');
|
||||
$repository = new Repository($finderMock);
|
||||
$repository->findHybrid($testQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $testQuery
|
||||
* @param int $testLimit
|
||||
* @param string $method
|
||||
*
|
||||
* @return \FOS\ElasticaBundle\Finder\TransformedFinder|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private function getFinderMock($testQuery, $testLimit = null, $method = 'find')
|
||||
{
|
||||
$finderMock = $this->getMockBuilder('FOS\ElasticaBundle\Finder\TransformedFinder')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$finderMock->expects($this->once())
|
||||
->method('findHybrid')
|
||||
->method($method)
|
||||
->with($this->equalTo($testQuery), $this->equalTo($testLimit));
|
||||
|
||||
$repository = new Repository($finderMock);
|
||||
$repository->findHybrid($testQuery, $testLimit);
|
||||
return $finderMock;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ class ElasticaToModelTransformerCollectionTest extends \PHPUnit_Framework_TestCa
|
|||
$objectClasses = $this->collection->getObjectClass();
|
||||
$this->assertEquals(array(
|
||||
'type1' => 'FOS\ElasticaBundle\Tests\Transformer\POPO',
|
||||
'type2' => 'FOS\ElasticaBundle\Tests\Transformer\POPO2'
|
||||
'type2' => 'FOS\ElasticaBundle\Tests\Transformer\POPO2',
|
||||
), $objectClasses);
|
||||
}
|
||||
|
||||
|
@ -89,8 +89,8 @@ class ElasticaToModelTransformerCollectionTest extends \PHPUnit_Framework_TestCa
|
|||
|
||||
$this->transformers['type1']->expects($this->once())
|
||||
->method('transform')
|
||||
->with(array($document1,$document2))
|
||||
->will($this->returnValue(array($result1,$result2)));
|
||||
->with(array($document1, $document2))
|
||||
->will($this->returnValue(array($result1, $result2)));
|
||||
|
||||
$results = $this->collection->transform(array($document1, $document2));
|
||||
|
||||
|
@ -120,8 +120,8 @@ class ElasticaToModelTransformerCollectionTest extends \PHPUnit_Framework_TestCa
|
|||
|
||||
return array(
|
||||
array(
|
||||
$result, $transformedObject
|
||||
)
|
||||
$result, $transformedObject,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,8 +22,8 @@ class POPO
|
|||
public function __construct()
|
||||
{
|
||||
$this->date = new \DateTime('1979-05-05');
|
||||
$this->file = new \SplFileInfo(__DIR__ . '/../fixtures/attachment.odt');
|
||||
$this->fileContents = file_get_contents(__DIR__ . '/../fixtures/attachment.odt');
|
||||
$this->file = new \SplFileInfo(__DIR__.'/../fixtures/attachment.odt');
|
||||
$this->fileContents = file_get_contents(__DIR__.'/../fixtures/attachment.odt');
|
||||
}
|
||||
|
||||
public function getId()
|
||||
|
@ -48,7 +48,7 @@ class POPO
|
|||
{
|
||||
return array(
|
||||
'key1' => 'value1',
|
||||
'key2' => 'value2'
|
||||
'key2' => 'value2',
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -110,7 +110,7 @@ class POPO
|
|||
|
||||
public function getNestedObject()
|
||||
{
|
||||
return array('key1' => (object)array('id' => 1, 'key1sub1' => 'value1sub1', 'key1sub2' => 'value1sub2'));
|
||||
return array('key1' => (object) array('id' => 1, 'key1sub1' => 'value1sub1', 'key1sub2' => 'value1sub2'));
|
||||
}
|
||||
|
||||
public function getUpper()
|
||||
|
@ -126,13 +126,6 @@ class POPO
|
|||
|
||||
class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
if (!class_exists('Elastica\Document')) {
|
||||
$this->markTestSkipped('The Elastica library classes are not available');
|
||||
}
|
||||
}
|
||||
|
||||
public function testTransformerDispatches()
|
||||
{
|
||||
$dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')
|
||||
|
@ -182,7 +175,7 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
'float' => array(),
|
||||
'bool' => array(),
|
||||
'date' => array(),
|
||||
'falseBool' => array()
|
||||
'falseBool' => array(),
|
||||
)
|
||||
);
|
||||
$data = $document->getData();
|
||||
|
@ -215,7 +208,7 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(
|
||||
array(
|
||||
'key1' => 'value1',
|
||||
'key2' => 'value2'
|
||||
'key2' => 'value2',
|
||||
), $data['array']
|
||||
);
|
||||
}
|
||||
|
@ -260,7 +253,7 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
$document = $transformer->transform(new POPO(), array('file' => array('type' => 'attachment')));
|
||||
$data = $document->getData();
|
||||
|
||||
$this->assertEquals(base64_encode(file_get_contents(__DIR__ . '/../fixtures/attachment.odt')), $data['file']);
|
||||
$this->assertEquals(base64_encode(file_get_contents(__DIR__.'/../fixtures/attachment.odt')), $data['file']);
|
||||
}
|
||||
|
||||
public function testFileContentsAddedForAttachmentMapping()
|
||||
|
@ -270,7 +263,7 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
$data = $document->getData();
|
||||
|
||||
$this->assertEquals(
|
||||
base64_encode(file_get_contents(__DIR__ . '/../fixtures/attachment.odt')), $data['fileContents']
|
||||
base64_encode(file_get_contents(__DIR__.'/../fixtures/attachment.odt')), $data['fileContents']
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -278,18 +271,18 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
$transformer = $this->getTransformer();
|
||||
$document = $transformer->transform(new POPO(), array(
|
||||
'sub' => array(
|
||||
'type' => 'nested',
|
||||
'properties' => array('foo' => array())
|
||||
)
|
||||
));
|
||||
'sub' => array(
|
||||
'type' => 'nested',
|
||||
'properties' => array('foo' => array()),
|
||||
),
|
||||
));
|
||||
$data = $document->getData();
|
||||
|
||||
$this->assertTrue(array_key_exists('sub', $data));
|
||||
$this->assertInternalType('array', $data['sub']);
|
||||
$this->assertEquals(array(
|
||||
array('foo' => 'foo'),
|
||||
array('foo' => 'bar')
|
||||
array('foo' => 'bar'),
|
||||
), $data['sub']);
|
||||
}
|
||||
|
||||
|
@ -299,8 +292,8 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
$document = $transformer->transform(new POPO(), array(
|
||||
'sub' => array(
|
||||
'type' => 'object',
|
||||
'properties' => array('bar')
|
||||
)
|
||||
'properties' => array('bar'),
|
||||
),
|
||||
));
|
||||
$data = $document->getData();
|
||||
|
||||
|
@ -308,7 +301,7 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInternalType('array', $data['sub']);
|
||||
$this->assertEquals(array(
|
||||
array('bar' => 'foo'),
|
||||
array('bar' => 'bar')
|
||||
array('bar' => 'bar'),
|
||||
), $data['sub']);
|
||||
}
|
||||
|
||||
|
@ -317,8 +310,8 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
$transformer = $this->getTransformer();
|
||||
$document = $transformer->transform(new POPO(), array(
|
||||
'obj' => array(
|
||||
'type' => 'object'
|
||||
)
|
||||
'type' => 'object',
|
||||
),
|
||||
));
|
||||
$data = $document->getData();
|
||||
|
||||
|
@ -327,8 +320,8 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(array(
|
||||
'foo' => 'foo',
|
||||
'bar' => 'foo',
|
||||
'id' => 1
|
||||
), $data['obj']);
|
||||
'id' => 1,
|
||||
), $data['obj']);
|
||||
}
|
||||
|
||||
public function testObjectsMappingOfAtLeastOneAutoMappedObjectAndAtLeastOneManuallyMappedObject()
|
||||
|
@ -343,14 +336,14 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
'properties' => array(
|
||||
'key1sub1' => array(
|
||||
'type' => 'string',
|
||||
'properties' => array()
|
||||
'properties' => array(),
|
||||
),
|
||||
'key1sub2' => array(
|
||||
'type' => 'string',
|
||||
'properties' => array()
|
||||
)
|
||||
)
|
||||
)
|
||||
'properties' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
$data = $document->getData();
|
||||
|
@ -363,14 +356,14 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
array(
|
||||
'foo' => 'foo',
|
||||
'bar' => 'foo',
|
||||
'id' => 1
|
||||
'id' => 1,
|
||||
),
|
||||
$data['obj']
|
||||
);
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'key1sub1' => 'value1sub1',
|
||||
'key1sub2' => 'value1sub2'
|
||||
'key1sub2' => 'value1sub2',
|
||||
),
|
||||
$data['nestedObject'][0]
|
||||
);
|
||||
|
@ -380,7 +373,7 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
$transformer = $this->getTransformer();
|
||||
$document = $transformer->transform(new POPO(), array(
|
||||
'_parent' => array('type' => 'upper', 'property'=>'upper', 'identifier' => 'id'),
|
||||
'_parent' => array('type' => 'upper', 'property' => 'upper', 'identifier' => 'id'),
|
||||
));
|
||||
|
||||
$this->assertEquals("parent", $document->getParent());
|
||||
|
@ -390,7 +383,7 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
$transformer = $this->getTransformer();
|
||||
$document = $transformer->transform(new POPO(), array(
|
||||
'_parent' => array('type' => 'upper', 'property'=>'upper', 'identifier' => 'name'),
|
||||
'_parent' => array('type' => 'upper', 'property' => 'upper', 'identifier' => 'name'),
|
||||
));
|
||||
|
||||
$this->assertEquals("a random name", $document->getParent());
|
||||
|
@ -400,7 +393,7 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
$transformer = $this->getTransformer();
|
||||
$document = $transformer->transform(new POPO(), array(
|
||||
'_parent' => array('type' => 'upper', 'property'=>null, 'identifier' => 'id'),
|
||||
'_parent' => array('type' => 'upper', 'property' => null, 'identifier' => 'id'),
|
||||
));
|
||||
|
||||
$this->assertEquals("parent", $document->getParent());
|
||||
|
@ -410,7 +403,7 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
$transformer = $this->getTransformer();
|
||||
$document = $transformer->transform(new POPO(), array(
|
||||
'_parent' => array('type' => 'upper', 'property'=>'upperAlias', 'identifier' => 'id'),
|
||||
'_parent' => array('type' => 'upper', 'property' => 'upperAlias', 'identifier' => 'id'),
|
||||
));
|
||||
|
||||
$this->assertEquals("parent", $document->getParent());
|
||||
|
@ -418,6 +411,7 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
/**
|
||||
* @param null|\Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher
|
||||
*
|
||||
* @return ModelToElasticaAutoTransformer
|
||||
*/
|
||||
private function getTransformer($dispatcher = null)
|
||||
|
|
|
@ -23,13 +23,6 @@ class POPO
|
|||
|
||||
class ModelToElasticaIdentifierTransformerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
if (!class_exists('Elastica\Document')) {
|
||||
$this->markTestSkipped('The Elastica library classes are not available');
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetDocumentWithIdentifierOnly()
|
||||
{
|
||||
$transformer = $this->getTransformer();
|
||||
|
|
|
@ -41,6 +41,7 @@ class ElasticaToModelTransformerCollection implements ElasticaToModelTransformer
|
|||
|
||||
/**
|
||||
* @param Document[] $elasticaObjects
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function transform(array $elasticaObjects)
|
||||
|
@ -51,12 +52,12 @@ class ElasticaToModelTransformerCollection implements ElasticaToModelTransformer
|
|||
}
|
||||
|
||||
$transformed = array();
|
||||
foreach ($sorted AS $type => $objects) {
|
||||
foreach ($sorted as $type => $objects) {
|
||||
$transformedObjects = $this->transformers[$type]->transform($objects);
|
||||
$identifierGetter = 'get' . ucfirst($this->transformers[$type]->getIdentifierField());
|
||||
$identifierGetter = 'get'.ucfirst($this->transformers[$type]->getIdentifierField());
|
||||
$transformed[$type] = array_combine(
|
||||
array_map(
|
||||
function($o) use ($identifierGetter) {
|
||||
function ($o) use ($identifierGetter) {
|
||||
return $o->$identifierGetter();
|
||||
},
|
||||
$transformedObjects
|
||||
|
|
|
@ -3,32 +3,33 @@
|
|||
namespace FOS\ElasticaBundle\Transformer;
|
||||
|
||||
/**
|
||||
* Maps Elastica documents with model objects
|
||||
* Maps Elastica documents with model objects.
|
||||
*/
|
||||
interface ElasticaToModelTransformerInterface
|
||||
{
|
||||
/**
|
||||
* Transforms an array of elastica objects into an array of
|
||||
* model objects fetched from the doctrine repository
|
||||
* model objects fetched from the doctrine repository.
|
||||
*
|
||||
* @param array $elasticaObjects array of elastica objects
|
||||
*
|
||||
* @return array of model objects
|
||||
**/
|
||||
function transform(array $elasticaObjects);
|
||||
public function transform(array $elasticaObjects);
|
||||
|
||||
function hybridTransform(array $elasticaObjects);
|
||||
public function hybridTransform(array $elasticaObjects);
|
||||
|
||||
/**
|
||||
* Returns the object class used by the transformer.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getObjectClass();
|
||||
public function getObjectClass();
|
||||
|
||||
/**
|
||||
* Returns the identifier field from the options
|
||||
* Returns the identifier field from the options.
|
||||
*
|
||||
* @return string the identifier field
|
||||
*/
|
||||
function getIdentifierField();
|
||||
public function getIdentifierField();
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace FOS\ElasticaBundle\Transformer;
|
||||
|
||||
/**
|
||||
* Maps Elastica documents with model objects
|
||||
* Maps Elastica documents with model objects.
|
||||
*/
|
||||
interface HighlightableModelInterface
|
||||
{
|
||||
|
|
|
@ -10,7 +10,7 @@ use Elastica\Document;
|
|||
/**
|
||||
* Maps Elastica documents with Doctrine objects
|
||||
* This mapper assumes an exact match between
|
||||
* elastica documents ids and doctrine object ids
|
||||
* elastica documents ids and doctrine object ids.
|
||||
*/
|
||||
class ModelToElasticaAutoTransformer implements ModelToElasticaTransformerInterface
|
||||
{
|
||||
|
@ -20,25 +20,25 @@ class ModelToElasticaAutoTransformer implements ModelToElasticaTransformerInterf
|
|||
protected $dispatcher;
|
||||
|
||||
/**
|
||||
* Optional parameters
|
||||
* Optional parameters.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array(
|
||||
'identifier' => 'id'
|
||||
'identifier' => 'id',
|
||||
);
|
||||
|
||||
/**
|
||||
* PropertyAccessor instance
|
||||
* PropertyAccessor instance.
|
||||
*
|
||||
* @var PropertyAccessorInterface
|
||||
*/
|
||||
protected $propertyAccessor;
|
||||
|
||||
/**
|
||||
* Instanciates a new Mapper
|
||||
* Instanciates a new Mapper.
|
||||
*
|
||||
* @param array $options
|
||||
* @param array $options
|
||||
* @param EventDispatcherInterface $dispatcher
|
||||
*/
|
||||
public function __construct(array $options = array(), EventDispatcherInterface $dispatcher = null)
|
||||
|
@ -48,7 +48,7 @@ class ModelToElasticaAutoTransformer implements ModelToElasticaTransformerInterf
|
|||
}
|
||||
|
||||
/**
|
||||
* Set the PropertyAccessor
|
||||
* Set the PropertyAccessor.
|
||||
*
|
||||
* @param PropertyAccessorInterface $propertyAccessor
|
||||
*/
|
||||
|
@ -58,7 +58,7 @@ class ModelToElasticaAutoTransformer implements ModelToElasticaTransformerInterf
|
|||
}
|
||||
|
||||
/**
|
||||
* Transforms an object into an elastica object having the required keys
|
||||
* Transforms an object into an elastica object having the required keys.
|
||||
*
|
||||
* @param object $object the object to convert
|
||||
* @param array $fields the keys we want to have in the returned array
|
||||
|
@ -72,7 +72,7 @@ class ModelToElasticaAutoTransformer implements ModelToElasticaTransformerInterf
|
|||
|
||||
foreach ($fields as $key => $mapping) {
|
||||
if ($key == '_parent') {
|
||||
$property = (null !== $mapping['property'])?$mapping['property']:$mapping['type'];
|
||||
$property = (null !== $mapping['property']) ? $mapping['property'] : $mapping['type'];
|
||||
$value = $this->propertyAccessor->getValue($object, $property);
|
||||
$document->setParent($this->propertyAccessor->getValue($value, $mapping['identifier']));
|
||||
|
||||
|
@ -121,10 +121,10 @@ class ModelToElasticaAutoTransformer implements ModelToElasticaTransformerInterf
|
|||
}
|
||||
|
||||
/**
|
||||
* transform a nested document or an object property into an array of ElasticaDocument
|
||||
* transform a nested document or an object property into an array of ElasticaDocument.
|
||||
*
|
||||
* @param array|\Traversable|\ArrayAccess $objects the object to convert
|
||||
* @param array $fields the keys we want to have in the returned array
|
||||
* @param array $fields the keys we want to have in the returned array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
@ -148,7 +148,7 @@ class ModelToElasticaAutoTransformer implements ModelToElasticaTransformerInterf
|
|||
}
|
||||
|
||||
/**
|
||||
* Attempts to convert any type to a string or an array of strings
|
||||
* Attempts to convert any type to a string or an array of strings.
|
||||
*
|
||||
* @param mixed $value
|
||||
*
|
||||
|
@ -156,12 +156,11 @@ class ModelToElasticaAutoTransformer implements ModelToElasticaTransformerInterf
|
|||
*/
|
||||
protected function normalizeValue($value)
|
||||
{
|
||||
$normalizeValue = function(&$v)
|
||||
{
|
||||
$normalizeValue = function (&$v) {
|
||||
if ($v instanceof \DateTime) {
|
||||
$v = $v->format('c');
|
||||
} elseif (!is_scalar($v) && !is_null($v)) {
|
||||
$v = (string)$v;
|
||||
$v = (string) $v;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -6,12 +6,12 @@ use Elastica\Document;
|
|||
|
||||
/**
|
||||
* Creates an Elastica document with the ID of
|
||||
* the Doctrine object as Elastica document ID
|
||||
* the Doctrine object as Elastica document ID.
|
||||
*/
|
||||
class ModelToElasticaIdentifierTransformer extends ModelToElasticaAutoTransformer
|
||||
{
|
||||
/**
|
||||
* Creates an elastica document with the id of the doctrine object as id
|
||||
* Creates an elastica document with the id of the doctrine object as id.
|
||||
*
|
||||
* @param object $object the object to convert
|
||||
* @param array $fields the keys we want to have in the returned array
|
||||
|
|
|
@ -3,16 +3,17 @@
|
|||
namespace FOS\ElasticaBundle\Transformer;
|
||||
|
||||
/**
|
||||
* Maps Elastica documents with model objects
|
||||
* Maps Elastica documents with model objects.
|
||||
*/
|
||||
interface ModelToElasticaTransformerInterface
|
||||
{
|
||||
/**
|
||||
* Transforms an object into an elastica object having the required keys
|
||||
* Transforms an object into an elastica object having the required keys.
|
||||
*
|
||||
* @param object $object the object to convert
|
||||
* @param array $fields the keys we want to have in the returned array
|
||||
* @param array $fields the keys we want to have in the returned array
|
||||
*
|
||||
* @return \Elastica\Document
|
||||
**/
|
||||
function transform($object, array $fields);
|
||||
public function transform($object, array $fields);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue