CS fixes
This commit is contained in:
parent
cf9f7c6be8
commit
dd388e4b25
|
@ -13,7 +13,7 @@ use FOS\ElasticaBundle\Resetter;
|
|||
use FOS\ElasticaBundle\Provider\ProviderInterface;
|
||||
|
||||
/**
|
||||
* Populate the search index
|
||||
* Populate the search index.
|
||||
*/
|
||||
class PopulateCommand extends ContainerAwareCommand
|
||||
{
|
||||
|
@ -118,7 +118,7 @@ class PopulateCommand extends ContainerAwareCommand
|
|||
$providers = $this->providerRegistry->getIndexProviders($index);
|
||||
|
||||
foreach ($providers as $type => $provider) {
|
||||
$loggerClosure = function($message) use ($output, $index, $type) {
|
||||
$loggerClosure = function ($message) use ($output, $index, $type) {
|
||||
$output->writeln(sprintf('<info>Populating</info> %s/%s, %s', $index, $type, $message));
|
||||
};
|
||||
|
||||
|
@ -146,7 +146,7 @@ class PopulateCommand extends ContainerAwareCommand
|
|||
$this->resetter->resetIndexType($index, $type);
|
||||
}
|
||||
|
||||
$loggerClosure = function($message) use ($output, $index, $type) {
|
||||
$loggerClosure = function ($message) use ($output, $index, $type) {
|
||||
$output->writeln(sprintf('<info>Populating</info> %s/%s, %s', $index, $type, $message));
|
||||
};
|
||||
|
||||
|
|
|
@ -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']);
|
||||
|
||||
|
@ -419,7 +419,7 @@ class Configuration implements ConfigurationInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the array node used for "_all"
|
||||
* Returns the array node used for "_all".
|
||||
*/
|
||||
protected function getAllNode()
|
||||
{
|
||||
|
@ -438,7 +438,7 @@ class Configuration implements ConfigurationInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the array node used for "_timestamp"
|
||||
* Returns the array node used for "_timestamp".
|
||||
*/
|
||||
protected function getTimestampNode()
|
||||
{
|
||||
|
@ -459,7 +459,7 @@ class Configuration implements ConfigurationInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the array node used for "_ttl"
|
||||
* Returns the array node used for "_ttl".
|
||||
*/
|
||||
protected function getTtlNode()
|
||||
{
|
||||
|
@ -488,9 +488,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)
|
||||
{
|
||||
|
@ -277,13 +282,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)
|
||||
{
|
||||
|
@ -307,10 +312,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)
|
||||
|
@ -342,10 +348,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)
|
||||
|
@ -361,7 +368,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);
|
||||
|
||||
|
@ -371,12 +378,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)
|
||||
|
@ -395,7 +403,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;
|
||||
|
@ -415,11 +423,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)
|
||||
|
@ -432,7 +441,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']);
|
||||
|
@ -449,11 +458,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)
|
||||
|
@ -490,7 +500,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)
|
||||
{
|
||||
|
@ -511,7 +521,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) {
|
||||
|
@ -526,12 +536,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)
|
||||
|
@ -558,7 +569,7 @@ class FOSElasticaExtension extends Extension
|
|||
}
|
||||
|
||||
/**
|
||||
* Loads the index manager
|
||||
* Loads the index manager.
|
||||
*
|
||||
* @param ContainerBuilder $container
|
||||
**/
|
||||
|
@ -576,7 +587,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)
|
||||
{
|
||||
|
@ -592,7 +603,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)
|
||||
|
@ -611,7 +622,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)
|
||||
|
@ -635,7 +646,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);
|
||||
}
|
||||
|
|
|
@ -16,10 +16,10 @@ abstract class AbstractProvider extends BaseAbstractProvider
|
|||
* Constructor.
|
||||
*
|
||||
* @param ObjectPersisterInterface $objectPersister
|
||||
* @param IndexableInterface $indexable
|
||||
* @param string $objectClass
|
||||
* @param array $options
|
||||
* @param ManagerRegistry $managerRegistry
|
||||
* @param IndexableInterface $indexable
|
||||
* @param string $objectClass
|
||||
* @param array $options
|
||||
* @param ManagerRegistry $managerRegistry
|
||||
*/
|
||||
public function __construct(
|
||||
ObjectPersisterInterface $objectPersister,
|
||||
|
@ -81,9 +81,9 @@ abstract class AbstractProvider extends BaseAbstractProvider
|
|||
} else {
|
||||
try {
|
||||
$this->objectPersister->insertMany($objects);
|
||||
} catch(BulkResponseException $e) {
|
||||
} catch (BulkResponseException $e) {
|
||||
if ($loggerClosure) {
|
||||
$loggerClosure(sprintf('<error>%s</error>',$e->getMessage()));
|
||||
$loggerClosure(sprintf('<error>%s</error>', $e->getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -112,24 +112,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.
|
||||
|
@ -137,14 +139,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();
|
||||
}
|
||||
|
|
|
@ -17,39 +17,39 @@ use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
|
|||
class Listener implements EventSubscriber
|
||||
{
|
||||
/**
|
||||
* Object persister
|
||||
* Object persister.
|
||||
*
|
||||
* @var ObjectPersister
|
||||
*/
|
||||
protected $objectPersister;
|
||||
|
||||
/**
|
||||
* List of subscribed events
|
||||
* List of subscribed events.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $events;
|
||||
|
||||
/**
|
||||
* Configuration for the listener
|
||||
* Configuration for the listener.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* Objects scheduled for insertion and replacement
|
||||
* Objects scheduled for insertion and replacement.
|
||||
*/
|
||||
public $scheduledForInsertion = array();
|
||||
public $scheduledForUpdate = array();
|
||||
|
||||
/**
|
||||
* IDs of objects scheduled for removal
|
||||
* IDs of objects scheduled for removal.
|
||||
*/
|
||||
public $scheduledForDeletion = array();
|
||||
|
||||
/**
|
||||
* PropertyAccessor instance
|
||||
* PropertyAccessor instance.
|
||||
*
|
||||
* @var PropertyAccessorInterface
|
||||
*/
|
||||
|
@ -64,10 +64,10 @@ class Listener implements EventSubscriber
|
|||
* Constructor.
|
||||
*
|
||||
* @param ObjectPersisterInterface $objectPersister
|
||||
* @param array $events
|
||||
* @param IndexableInterface $indexable
|
||||
* @param array $config
|
||||
* @param null $logger
|
||||
* @param array $events
|
||||
* @param IndexableInterface $indexable
|
||||
* @param array $config
|
||||
* @param null $logger
|
||||
*/
|
||||
public function __construct(
|
||||
ObjectPersisterInterface $objectPersister,
|
||||
|
@ -98,11 +98,13 @@ class Listener implements EventSubscriber
|
|||
}
|
||||
|
||||
/**
|
||||
* Provides unified method for retrieving a doctrine object from an EventArgs instance
|
||||
* Provides unified method for retrieving a doctrine object from an EventArgs instance.
|
||||
*
|
||||
* @param EventArgs $eventArgs
|
||||
* @return object Entity | Document
|
||||
* @throws \RuntimeException if no valid getter is found.
|
||||
* @param EventArgs $eventArgs
|
||||
*
|
||||
* @return object Entity | Document
|
||||
*
|
||||
* @throws \RuntimeException if no valid getter is found.
|
||||
*/
|
||||
private function getDoctrineObject(EventArgs $eventArgs)
|
||||
{
|
||||
|
@ -142,7 +144,7 @@ class Listener implements EventSubscriber
|
|||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public function preRemove(EventArgs $eventArgs)
|
||||
{
|
||||
|
@ -155,7 +157,7 @@ class Listener implements EventSubscriber
|
|||
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
|
@ -210,6 +212,7 @@ class Listener implements EventSubscriber
|
|||
* 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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
@ -38,8 +38,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
|
||||
*/
|
||||
|
@ -53,7 +54,7 @@ class AliasProcessor
|
|||
|
||||
try {
|
||||
$aliasedIndexes = $this->getAliasedIndexes($client, $aliasName);
|
||||
} catch(AliasIsIndexException $e) {
|
||||
} catch (AliasIsIndexException $e) {
|
||||
if (!$force) {
|
||||
throw $e;
|
||||
}
|
||||
|
@ -68,7 +69,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)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -78,13 +79,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 {
|
||||
|
@ -129,11 +130,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)
|
||||
|
@ -159,7 +162,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)
|
||||
|
@ -89,7 +91,7 @@ class MappingBuilder
|
|||
|
||||
if (!$mapping) {
|
||||
// Empty mapping, we want it encoded as a {} instead of a []
|
||||
$mapping = new \stdClass;
|
||||
$mapping = new \stdClass();
|
||||
}
|
||||
|
||||
return $mapping;
|
||||
|
|
|
@ -8,7 +8,7 @@ use Elastica\Type\Mapping;
|
|||
use FOS\ElasticaBundle\Configuration\ConfigManager;
|
||||
|
||||
/**
|
||||
* Deletes and recreates indexes
|
||||
* Deletes and recreates indexes.
|
||||
*/
|
||||
class Resetter
|
||||
{
|
||||
|
@ -41,7 +41,7 @@ class Resetter
|
|||
}
|
||||
|
||||
/**
|
||||
* Deletes and recreates all indexes
|
||||
* Deletes and recreates all indexes.
|
||||
*/
|
||||
public function resetAllIndexes($populating = false, $force = false)
|
||||
{
|
||||
|
@ -55,8 +55,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)
|
||||
|
@ -77,10 +78,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
|
||||
*/
|
||||
|
@ -97,7 +99,7 @@ class Resetter
|
|||
}
|
||||
}
|
||||
|
||||
$mapping = new Mapping;
|
||||
$mapping = new Mapping();
|
||||
foreach ($this->mappingBuilder->buildTypeMapping($typeConfig) as $name => $field) {
|
||||
$mapping->setParam($name, $field);
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -29,7 +29,7 @@ class FantaPaginatorAdapter implements AdapterInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns Facets
|
||||
* Returns Facets.
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
|
|
|
@ -11,7 +11,7 @@ interface PaginatorAdapterInterface
|
|||
*
|
||||
* @api
|
||||
*/
|
||||
function getTotalHits();
|
||||
public function getTotalHits();
|
||||
|
||||
/**
|
||||
* Returns an slice of the results.
|
||||
|
@ -23,12 +23,12 @@ interface PaginatorAdapterInterface
|
|||
*
|
||||
* @api
|
||||
*/
|
||||
function getResults($offset, $length);
|
||||
public function getResults($offset, $length);
|
||||
|
||||
/**
|
||||
* Returns Facets
|
||||
* Returns Facets.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function getFacets();
|
||||
public function getFacets();
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ interface PartialResultsInterface
|
|||
*
|
||||
* @api
|
||||
*/
|
||||
function toArray();
|
||||
public function toArray();
|
||||
|
||||
/**
|
||||
* Returns the number of results.
|
||||
|
@ -20,12 +20,12 @@ interface PartialResultsInterface
|
|||
*
|
||||
* @api
|
||||
*/
|
||||
function getTotalHits();
|
||||
public function getTotalHits();
|
||||
|
||||
/**
|
||||
* Returns the facets
|
||||
* Returns the facets.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function getFacets();
|
||||
public function getFacets();
|
||||
}
|
|
@ -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
|
||||
{
|
||||
|
@ -41,7 +41,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())
|
||||
|
@ -56,7 +56,9 @@ class RawPaginatorAdapter implements PaginatorAdapterInterface
|
|||
*
|
||||
* @param integer $offset
|
||||
* @param integer $itemCountPerPage
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return ResultSet
|
||||
*/
|
||||
protected function getElasticaResults($offset, $itemCountPerPage)
|
||||
|
@ -82,6 +84,7 @@ class RawPaginatorAdapter implements PaginatorAdapterInterface
|
|||
$resultSet = $this->searchable->search($query, $this->options);
|
||||
$this->totalHits = $resultSet->getTotalHits();
|
||||
$this->facets = $resultSet->getFacets();
|
||||
|
||||
return $resultSet;
|
||||
}
|
||||
|
||||
|
@ -90,6 +93,7 @@ class RawPaginatorAdapter implements PaginatorAdapterInterface
|
|||
*
|
||||
* @param int $offset
|
||||
* @param int $itemCountPerPage
|
||||
*
|
||||
* @return PartialResultsInterface
|
||||
*/
|
||||
public function getResults($offset, $itemCountPerPage)
|
||||
|
@ -104,7 +108,7 @@ class RawPaginatorAdapter implements PaginatorAdapterInterface
|
|||
*/
|
||||
public function getTotalHits()
|
||||
{
|
||||
if ( ! isset($this->totalHits)) {
|
||||
if (! isset($this->totalHits)) {
|
||||
$this->totalHits = $this->searchable->search($this->query)->getTotalHits();
|
||||
}
|
||||
|
||||
|
@ -114,13 +118,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();
|
||||
}
|
||||
|
||||
|
@ -128,7 +132,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,6 +47,6 @@ class RawPartialResults implements PartialResultsInterface
|
|||
return $this->resultSet->getFacets();
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -47,11 +48,11 @@ class ObjectPersister implements ObjectPersisterInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* 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 +65,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 +75,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 +85,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 +95,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 +105,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 +145,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 +163,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 +177,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
|
||||
*/
|
||||
|
|
|
@ -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,7 +69,7 @@ abstract class AbstractProvider implements ProviderInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Get string with RAM usage information (current and peak)
|
||||
* Get string with RAM usage information (current and peak).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
|
|
|
@ -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>
|
||||
*/
|
||||
|
@ -14,7 +14,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 array of ProviderInterface instances
|
||||
*
|
||||
* @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())
|
||||
|
|
|
@ -38,7 +38,7 @@ class PaginateElasticaQuerySubscriber implements EventSubscriberInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Adds knp paging sort to query
|
||||
* Adds knp paging sort to query.
|
||||
*
|
||||
* @param ItemsEvent $event
|
||||
*/
|
||||
|
@ -70,7 +70,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()
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ class AbstractProviderTest extends \PHPUnit_Framework_TestCase
|
|||
return array(
|
||||
array(
|
||||
100,
|
||||
array(range(1,100)),
|
||||
array(range(1, 100)),
|
||||
100,
|
||||
),
|
||||
array(
|
||||
|
@ -231,7 +231,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));
|
||||
|
@ -259,7 +258,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()),
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -276,7 +275,7 @@ class AbstractProviderTest extends \PHPUnit_Framework_TestCase
|
|||
*/
|
||||
private function getMockObjectManager()
|
||||
{
|
||||
return $this->getMock(__NAMESPACE__ . '\ObjectManager');
|
||||
return $this->getMock(__NAMESPACE__.'\ObjectManager');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -302,5 +301,5 @@ class AbstractProviderTest extends \PHPUnit_Framework_TestCase
|
|||
*/
|
||||
interface ObjectManager
|
||||
{
|
||||
function clear();
|
||||
public function clear();
|
||||
}
|
||||
|
|
|
@ -109,7 +109,7 @@ class ElasticaToModelTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
'findAll',
|
||||
'findBy',
|
||||
'findOneBy',
|
||||
'getClassName'
|
||||
'getClassName',
|
||||
));
|
||||
|
||||
$this->manager->expects($this->any())
|
||||
|
|
|
@ -4,9 +4,13 @@ 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>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -100,6 +100,7 @@ class MappingToElasticaTest extends WebTestCase
|
|||
|
||||
/**
|
||||
* @param Client $client
|
||||
*
|
||||
* @return \FOS\ElasticaBundle\Resetter $resetter
|
||||
*/
|
||||
private function getResetter(Client $client)
|
||||
|
@ -109,11 +110,12 @@ class MappingToElasticaTest extends WebTestCase
|
|||
|
||||
/**
|
||||
* @param Client $client
|
||||
*
|
||||
* @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 */
|
||||
|
|
|
@ -33,9 +33,9 @@ class ObjectPersisterTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
public function setUp()
|
||||
{
|
||||
if (!class_exists('Elastica\Type')) {
|
||||
$this->markTestSkipped('The Elastica library classes are not available');
|
||||
}
|
||||
if (!class_exists('Elastica\Type')) {
|
||||
$this->markTestSkipped('The Elastica library classes are not available');
|
||||
}
|
||||
}
|
||||
|
||||
public function testThatCanReplaceObject()
|
||||
|
|
|
@ -26,9 +26,9 @@ class ObjectSerializerPersisterTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
public function setUp()
|
||||
{
|
||||
if (!class_exists('Elastica\Type')) {
|
||||
$this->markTestSkipped('The Elastica library classes are not available');
|
||||
}
|
||||
if (!class_exists('Elastica\Type')) {
|
||||
$this->markTestSkipped('The Elastica library classes are not available');
|
||||
}
|
||||
}
|
||||
|
||||
public function testThatCanReplaceObject()
|
||||
|
|
|
@ -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,27 @@ 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,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,8 +21,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()
|
||||
|
@ -47,7 +47,7 @@ class POPO
|
|||
{
|
||||
return array(
|
||||
'key1' => 'value1',
|
||||
'key2' => 'value2'
|
||||
'key2' => 'value2',
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -109,7 +109,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()
|
||||
|
@ -152,7 +152,7 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
'float' => array(),
|
||||
'bool' => array(),
|
||||
'date' => array(),
|
||||
'falseBool' => array()
|
||||
'falseBool' => array(),
|
||||
)
|
||||
);
|
||||
$data = $document->getData();
|
||||
|
@ -185,7 +185,7 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(
|
||||
array(
|
||||
'key1' => 'value1',
|
||||
'key2' => 'value2'
|
||||
'key2' => 'value2',
|
||||
), $data['array']
|
||||
);
|
||||
}
|
||||
|
@ -230,7 +230,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()
|
||||
|
@ -240,7 +240,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']
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -250,8 +250,8 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
$document = $transformer->transform(new POPO(), array(
|
||||
'sub' => array(
|
||||
'type' => 'nested',
|
||||
'properties' => array('foo' => '~')
|
||||
)
|
||||
'properties' => array('foo' => '~'),
|
||||
),
|
||||
));
|
||||
$data = $document->getData();
|
||||
|
||||
|
@ -259,7 +259,7 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInternalType('array', $data['sub']);
|
||||
$this->assertEquals(array(
|
||||
array('foo' => 'foo'),
|
||||
array('foo' => 'bar')
|
||||
array('foo' => 'bar'),
|
||||
), $data['sub']);
|
||||
}
|
||||
|
||||
|
@ -269,8 +269,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();
|
||||
|
||||
|
@ -278,7 +278,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']);
|
||||
}
|
||||
|
||||
|
@ -287,8 +287,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();
|
||||
|
||||
|
@ -297,7 +297,7 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(array(
|
||||
'foo' => 'foo',
|
||||
'bar' => 'foo',
|
||||
'id' => 1
|
||||
'id' => 1,
|
||||
), $data['obj']);
|
||||
}
|
||||
|
||||
|
@ -313,14 +313,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();
|
||||
|
@ -333,14 +333,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]
|
||||
);
|
||||
|
@ -350,7 +350,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());
|
||||
|
@ -360,7 +360,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());
|
||||
|
@ -370,7 +370,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());
|
||||
|
@ -380,7 +380,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());
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -8,28 +8,28 @@ 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
|
||||
{
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
@ -39,7 +39,7 @@ class ModelToElasticaAutoTransformer implements ModelToElasticaTransformerInterf
|
|||
}
|
||||
|
||||
/**
|
||||
* Set the PropertyAccessor
|
||||
* Set the PropertyAccessor.
|
||||
*
|
||||
* @param PropertyAccessorInterface $propertyAccessor
|
||||
*/
|
||||
|
@ -49,7 +49,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
|
||||
|
@ -63,7 +63,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']));
|
||||
continue;
|
||||
|
@ -96,10 +96,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
|
||||
*/
|
||||
|
@ -123,7 +123,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
|
||||
*
|
||||
|
@ -131,12 +131,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