CS fixes
This commit is contained in:
parent
cf9f7c6be8
commit
dd388e4b25
|
@ -13,7 +13,7 @@ use FOS\ElasticaBundle\Resetter;
|
||||||
use FOS\ElasticaBundle\Provider\ProviderInterface;
|
use FOS\ElasticaBundle\Provider\ProviderInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Populate the search index
|
* Populate the search index.
|
||||||
*/
|
*/
|
||||||
class PopulateCommand extends ContainerAwareCommand
|
class PopulateCommand extends ContainerAwareCommand
|
||||||
{
|
{
|
||||||
|
@ -118,7 +118,7 @@ class PopulateCommand extends ContainerAwareCommand
|
||||||
$providers = $this->providerRegistry->getIndexProviders($index);
|
$providers = $this->providerRegistry->getIndexProviders($index);
|
||||||
|
|
||||||
foreach ($providers as $type => $provider) {
|
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));
|
$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);
|
$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));
|
$output->writeln(sprintf('<info>Populating</info> %s/%s, %s', $index, $type, $message));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ use FOS\ElasticaBundle\IndexManager;
|
||||||
use FOS\ElasticaBundle\Resetter;
|
use FOS\ElasticaBundle\Resetter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset search indexes
|
* Reset search indexes.
|
||||||
*/
|
*/
|
||||||
class ResetCommand extends ContainerAwareCommand
|
class ResetCommand extends ContainerAwareCommand
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,7 +11,7 @@ use Elastica\Query;
|
||||||
use Elastica\Result;
|
use Elastica\Result;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Searches a type
|
* Searches a type.
|
||||||
*/
|
*/
|
||||||
class SearchCommand extends ContainerAwareCommand
|
class SearchCommand extends ContainerAwareCommand
|
||||||
{
|
{
|
||||||
|
|
|
@ -53,9 +53,9 @@ class IndexConfig
|
||||||
/**
|
/**
|
||||||
* Constructor expects an array as generated by the Container Configuration builder.
|
* Constructor expects an array as generated by the Container Configuration builder.
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param TypeConfig[] $types
|
* @param TypeConfig[] $types
|
||||||
* @param array $config
|
* @param array $config
|
||||||
*/
|
*/
|
||||||
public function __construct($name, array $types, array $config)
|
public function __construct($name, array $types, array $config)
|
||||||
{
|
{
|
||||||
|
@ -92,7 +92,9 @@ class IndexConfig
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $typeName
|
* @param string $typeName
|
||||||
|
*
|
||||||
* @return TypeConfig
|
* @return TypeConfig
|
||||||
|
*
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function getType($typeName)
|
public function getType($typeName)
|
||||||
|
|
|
@ -20,6 +20,7 @@ interface ManagerInterface
|
||||||
* Returns configuration for an index.
|
* Returns configuration for an index.
|
||||||
*
|
*
|
||||||
* @param $index
|
* @param $index
|
||||||
|
*
|
||||||
* @return IndexConfig
|
* @return IndexConfig
|
||||||
*/
|
*/
|
||||||
public function getIndexConfiguration($index);
|
public function getIndexConfiguration($index);
|
||||||
|
@ -36,6 +37,7 @@ interface ManagerInterface
|
||||||
*
|
*
|
||||||
* @param string $index
|
* @param string $index
|
||||||
* @param string $type
|
* @param string $type
|
||||||
|
*
|
||||||
* @return TypeConfig
|
* @return TypeConfig
|
||||||
*/
|
*/
|
||||||
public function getTypeConfiguration($index, $type);
|
public function getTypeConfiguration($index, $type);
|
||||||
|
|
|
@ -17,9 +17,10 @@ use FOS\ElasticaBundle\Annotation\Search as BaseSearch;
|
||||||
* Annotation class for setting search repository.
|
* Annotation class for setting search repository.
|
||||||
*
|
*
|
||||||
* @Annotation
|
* @Annotation
|
||||||
|
*
|
||||||
* @deprecated Use FOS\ElasticaBundle\Annotation\Search instead
|
* @deprecated Use FOS\ElasticaBundle\Annotation\Search instead
|
||||||
* @Target("CLASS")
|
* @Target("CLASS")
|
||||||
*/
|
*/
|
||||||
class Search extends BaseSearch
|
class Search extends BaseSearch
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,7 @@ class ContainerSource implements SourceInterface
|
||||||
* Builds TypeConfig objects for each type.
|
* Builds TypeConfig objects for each type.
|
||||||
*
|
*
|
||||||
* @param array $config
|
* @param array $config
|
||||||
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function getTypes($config)
|
protected function getTypes($config)
|
||||||
|
|
|
@ -23,4 +23,4 @@ interface SourceInterface
|
||||||
* @return \FOS\ElasticaBundle\Configuration\IndexConfig[]
|
* @return \FOS\ElasticaBundle\Configuration\IndexConfig[]
|
||||||
*/
|
*/
|
||||||
public function getConfiguration();
|
public function getConfiguration();
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,4 +33,4 @@ class ConfigSourcePass implements CompilerPassInterface
|
||||||
|
|
||||||
$container->getDefinition('fos_elastica.config_manager')->replaceArgument(0, $sources);
|
$container->getDefinition('fos_elastica.config_manager')->replaceArgument(0, $sources);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,7 @@ class RegisterProvidersPass implements CompilerPassInterface
|
||||||
* Returns whether the class implements ProviderInterface.
|
* Returns whether the class implements ProviderInterface.
|
||||||
*
|
*
|
||||||
* @param string $class
|
* @param string $class
|
||||||
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
private function isProviderImplementation($class)
|
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.');
|
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)
|
private function addClientsSection(ArrayNodeDefinition $rootNode)
|
||||||
{
|
{
|
||||||
|
@ -76,8 +76,8 @@ class Configuration implements ConfigurationInterface
|
||||||
->performNoDeepMerging()
|
->performNoDeepMerging()
|
||||||
// BC - Renaming 'servers' node to 'connections'
|
// BC - Renaming 'servers' node to 'connections'
|
||||||
->beforeNormalization()
|
->beforeNormalization()
|
||||||
->ifTrue(function($v) { return isset($v['servers']); })
|
->ifTrue(function ($v) { return isset($v['servers']); })
|
||||||
->then(function($v) {
|
->then(function ($v) {
|
||||||
$v['connections'] = $v['servers'];
|
$v['connections'] = $v['servers'];
|
||||||
unset($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); })
|
->ifTrue(function ($v) { return is_array($v) && !array_key_exists('connections', $v); })
|
||||||
->then(function ($v) {
|
->then(function ($v) {
|
||||||
return array(
|
return array(
|
||||||
'connections' => array($v)
|
'connections' => array($v),
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
->end()
|
->end()
|
||||||
|
@ -111,8 +111,8 @@ class Configuration implements ConfigurationInterface
|
||||||
->children()
|
->children()
|
||||||
->scalarNode('url')
|
->scalarNode('url')
|
||||||
->validate()
|
->validate()
|
||||||
->ifTrue(function($url) { return $url && substr($url, -1) !== '/'; })
|
->ifTrue(function ($url) { return $url && substr($url, -1) !== '/'; })
|
||||||
->then(function($url) { return $url.'/'; })
|
->then(function ($url) { return $url.'/'; })
|
||||||
->end()
|
->end()
|
||||||
->end()
|
->end()
|
||||||
->scalarNode('host')->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)
|
private function addIndexesSection(ArrayNodeDefinition $rootNode)
|
||||||
{
|
{
|
||||||
|
@ -198,8 +198,8 @@ class Configuration implements ConfigurationInterface
|
||||||
->end()
|
->end()
|
||||||
// BC - Renaming 'mappings' node to 'properties'
|
// BC - Renaming 'mappings' node to 'properties'
|
||||||
->beforeNormalization()
|
->beforeNormalization()
|
||||||
->ifTrue(function($v) { return array_key_exists('mappings', $v); })
|
->ifTrue(function ($v) { return array_key_exists('mappings', $v); })
|
||||||
->then(function($v) {
|
->then(function ($v) {
|
||||||
$v['properties'] = $v['mappings'];
|
$v['properties'] = $v['mappings'];
|
||||||
unset($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()
|
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()
|
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()
|
protected function getTtlNode()
|
||||||
{
|
{
|
||||||
|
@ -488,9 +488,9 @@ class Configuration implements ConfigurationInterface
|
||||||
|
|
||||||
$node
|
$node
|
||||||
->validate()
|
->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')
|
->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')
|
->thenInvalid('Propel doesn\'t support the "repository" parameter')
|
||||||
->end()
|
->end()
|
||||||
->children()
|
->children()
|
||||||
|
|
|
@ -80,8 +80,9 @@ class FOSElasticaExtension extends Extension
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $config
|
* @param array $config
|
||||||
* @param ContainerBuilder $container
|
* @param ContainerBuilder $container
|
||||||
|
*
|
||||||
* @return Configuration
|
* @return Configuration
|
||||||
*/
|
*/
|
||||||
public function getConfiguration(array $config, ContainerBuilder $container)
|
public function getConfiguration(array $config, ContainerBuilder $container)
|
||||||
|
@ -92,8 +93,9 @@ class FOSElasticaExtension extends Extension
|
||||||
/**
|
/**
|
||||||
* Loads the configured clients.
|
* 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
|
* @param ContainerBuilder $container A ContainerBuilder instance
|
||||||
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function loadClients(array $clients, ContainerBuilder $container)
|
private function loadClients(array $clients, ContainerBuilder $container)
|
||||||
|
@ -114,7 +116,7 @@ class FOSElasticaExtension extends Extension
|
||||||
|
|
||||||
$this->clients[$name] = array(
|
$this->clients[$name] = array(
|
||||||
'id' => $clientId,
|
'id' => $clientId,
|
||||||
'reference' => new Reference($clientId)
|
'reference' => new Reference($clientId),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,9 +124,11 @@ class FOSElasticaExtension extends Extension
|
||||||
/**
|
/**
|
||||||
* Loads the configured indexes.
|
* 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
|
* @param ContainerBuilder $container A ContainerBuilder instance
|
||||||
|
*
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function loadIndexes(array $indexes, ContainerBuilder $container)
|
private function loadIndexes(array $indexes, ContainerBuilder $container)
|
||||||
|
@ -133,7 +137,7 @@ class FOSElasticaExtension extends Extension
|
||||||
|
|
||||||
foreach ($indexes as $name => $index) {
|
foreach ($indexes as $name => $index) {
|
||||||
$indexId = sprintf('fos_elastica.index.%s', $name);
|
$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 = new DefinitionDecorator('fos_elastica.index_prototype');
|
||||||
$indexDef->replaceArgument(0, $indexName);
|
$indexDef->replaceArgument(0, $indexName);
|
||||||
|
@ -173,8 +177,9 @@ class FOSElasticaExtension extends Extension
|
||||||
* Loads the configured index finders.
|
* Loads the configured index finders.
|
||||||
*
|
*
|
||||||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
||||||
* @param string $name The index name
|
* @param string $name The index name
|
||||||
* @param Reference $index Reference to the related index
|
* @param Reference $index Reference to the related index
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function loadIndexFinder(ContainerBuilder $container, $name, Reference $index)
|
private function loadIndexFinder(ContainerBuilder $container, $name, Reference $index)
|
||||||
|
@ -197,10 +202,10 @@ class FOSElasticaExtension extends Extension
|
||||||
/**
|
/**
|
||||||
* Loads the configured types.
|
* Loads the configured types.
|
||||||
*
|
*
|
||||||
* @param array $types
|
* @param array $types
|
||||||
* @param ContainerBuilder $container
|
* @param ContainerBuilder $container
|
||||||
* @param array $indexConfig
|
* @param array $indexConfig
|
||||||
* @param array $indexableCallbacks
|
* @param array $indexableCallbacks
|
||||||
*/
|
*/
|
||||||
private function loadTypes(array $types, ContainerBuilder $container, array $indexConfig, 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 ContainerBuilder $container
|
||||||
* @param Reference $typeRef
|
* @param Reference $typeRef
|
||||||
* @param string $indexName
|
* @param string $indexName
|
||||||
* @param string $typeName
|
* @param string $typeName
|
||||||
*/
|
*/
|
||||||
private function loadTypePersistenceIntegration(array $typeConfig, ContainerBuilder $container, Reference $typeRef, $indexName, $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.
|
* Creates and loads an ElasticaToModelTransformer.
|
||||||
*
|
*
|
||||||
* @param array $typeConfig
|
* @param array $typeConfig
|
||||||
* @param ContainerBuilder $container
|
* @param ContainerBuilder $container
|
||||||
* @param string $indexName
|
* @param string $indexName
|
||||||
* @param string $typeName
|
* @param string $typeName
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function loadElasticaToModelTransformer(array $typeConfig, ContainerBuilder $container, $indexName, $typeName)
|
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.
|
* Creates and loads a ModelToElasticaTransformer for an index/type.
|
||||||
*
|
*
|
||||||
* @param array $typeConfig
|
* @param array $typeConfig
|
||||||
* @param ContainerBuilder $container
|
* @param ContainerBuilder $container
|
||||||
* @param string $indexName
|
* @param string $indexName
|
||||||
* @param string $typeName
|
* @param string $typeName
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function loadModelToElasticaTransformer(array $typeConfig, ContainerBuilder $container, $indexName, $typeName)
|
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);
|
$serviceId = sprintf('fos_elastica.model_to_elastica_transformer.%s.%s', $indexName, $typeName);
|
||||||
$serviceDef = new DefinitionDecorator($abstractId);
|
$serviceDef = new DefinitionDecorator($abstractId);
|
||||||
$serviceDef->replaceArgument(0, array(
|
$serviceDef->replaceArgument(0, array(
|
||||||
'identifier' => $typeConfig['identifier']
|
'identifier' => $typeConfig['identifier'],
|
||||||
));
|
));
|
||||||
$container->setDefinition($serviceId, $serviceDef);
|
$container->setDefinition($serviceId, $serviceDef);
|
||||||
|
|
||||||
|
@ -371,12 +378,13 @@ class FOSElasticaExtension extends Extension
|
||||||
/**
|
/**
|
||||||
* Creates and loads an object persister for a type.
|
* Creates and loads an object persister for a type.
|
||||||
*
|
*
|
||||||
* @param array $typeConfig
|
* @param array $typeConfig
|
||||||
* @param Reference $typeRef
|
* @param Reference $typeRef
|
||||||
* @param ContainerBuilder $container
|
* @param ContainerBuilder $container
|
||||||
* @param string $indexName
|
* @param string $indexName
|
||||||
* @param string $typeName
|
* @param string $typeName
|
||||||
* @param string $transformerId
|
* @param string $transformerId
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function loadObjectPersister(array $typeConfig, Reference $typeRef, ContainerBuilder $container, $indexName, $typeName, $transformerId)
|
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';
|
$abstractId = 'fos_elastica.object_persister';
|
||||||
$mapping = $this->indexConfigs[$indexName]['types'][$typeName]['mapping'];
|
$mapping = $this->indexConfigs[$indexName]['types'][$typeName]['mapping'];
|
||||||
$argument = $mapping['properties'];
|
$argument = $mapping['properties'];
|
||||||
if(isset($mapping['_parent'])){
|
if (isset($mapping['_parent'])) {
|
||||||
$argument['_parent'] = $mapping['_parent'];
|
$argument['_parent'] = $mapping['_parent'];
|
||||||
}
|
}
|
||||||
$arguments[] = $argument;
|
$arguments[] = $argument;
|
||||||
|
@ -415,11 +423,12 @@ class FOSElasticaExtension extends Extension
|
||||||
/**
|
/**
|
||||||
* Loads a provider for a type.
|
* Loads a provider for a type.
|
||||||
*
|
*
|
||||||
* @param array $typeConfig
|
* @param array $typeConfig
|
||||||
* @param ContainerBuilder $container
|
* @param ContainerBuilder $container
|
||||||
* @param string $objectPersisterId
|
* @param string $objectPersisterId
|
||||||
* @param string $indexName
|
* @param string $indexName
|
||||||
* @param string $typeName
|
* @param string $typeName
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function loadTypeProvider(array $typeConfig, ContainerBuilder $container, $objectPersisterId, $indexName, $typeName)
|
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.
|
* index and type names were "prototype" and a driver, respectively.
|
||||||
*/
|
*/
|
||||||
$providerId = sprintf('fos_elastica.provider.%s.%s', $indexName, $typeName);
|
$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->addTag('fos_elastica.provider', array('index' => $indexName, 'type' => $typeName));
|
||||||
$providerDef->replaceArgument(0, new Reference($objectPersisterId));
|
$providerDef->replaceArgument(0, new Reference($objectPersisterId));
|
||||||
$providerDef->replaceArgument(2, $typeConfig['model']);
|
$providerDef->replaceArgument(2, $typeConfig['model']);
|
||||||
|
@ -449,11 +458,12 @@ class FOSElasticaExtension extends Extension
|
||||||
/**
|
/**
|
||||||
* Loads doctrine listeners to handle indexing of new or updated objects.
|
* Loads doctrine listeners to handle indexing of new or updated objects.
|
||||||
*
|
*
|
||||||
* @param array $typeConfig
|
* @param array $typeConfig
|
||||||
* @param ContainerBuilder $container
|
* @param ContainerBuilder $container
|
||||||
* @param string $objectPersisterId
|
* @param string $objectPersisterId
|
||||||
* @param string $indexName
|
* @param string $indexName
|
||||||
* @param string $typeName
|
* @param string $typeName
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function loadTypeListener(array $typeConfig, ContainerBuilder $container, $objectPersisterId, $indexName, $typeName)
|
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)
|
private function getDoctrineEvents(array $typeConfig)
|
||||||
{
|
{
|
||||||
|
@ -511,7 +521,7 @@ class FOSElasticaExtension extends Extension
|
||||||
'insert' => array(constant($eventsClass.'::postPersist')),
|
'insert' => array(constant($eventsClass.'::postPersist')),
|
||||||
'update' => array(constant($eventsClass.'::postUpdate')),
|
'update' => array(constant($eventsClass.'::postUpdate')),
|
||||||
'delete' => array(constant($eventsClass.'::preRemove')),
|
'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) {
|
foreach ($eventMapping as $event => $doctrineEvents) {
|
||||||
|
@ -526,12 +536,13 @@ class FOSElasticaExtension extends Extension
|
||||||
/**
|
/**
|
||||||
* Loads a Type specific Finder.
|
* Loads a Type specific Finder.
|
||||||
*
|
*
|
||||||
* @param array $typeConfig
|
* @param array $typeConfig
|
||||||
* @param ContainerBuilder $container
|
* @param ContainerBuilder $container
|
||||||
* @param string $elasticaToModelId
|
* @param string $elasticaToModelId
|
||||||
* @param Reference $typeRef
|
* @param Reference $typeRef
|
||||||
* @param string $indexName
|
* @param string $indexName
|
||||||
* @param string $typeName
|
* @param string $typeName
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function loadTypeFinder(array $typeConfig, ContainerBuilder $container, $elasticaToModelId, Reference $typeRef, $indexName, $typeName)
|
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
|
* @param ContainerBuilder $container
|
||||||
**/
|
**/
|
||||||
|
@ -576,7 +587,7 @@ class FOSElasticaExtension extends Extension
|
||||||
* Makes sure a specific driver has been loaded.
|
* Makes sure a specific driver has been loaded.
|
||||||
*
|
*
|
||||||
* @param ContainerBuilder $container
|
* @param ContainerBuilder $container
|
||||||
* @param string $driver
|
* @param string $driver
|
||||||
*/
|
*/
|
||||||
private function loadDriver(ContainerBuilder $container, $driver)
|
private function loadDriver(ContainerBuilder $container, $driver)
|
||||||
{
|
{
|
||||||
|
@ -592,7 +603,7 @@ class FOSElasticaExtension extends Extension
|
||||||
/**
|
/**
|
||||||
* Loads and configures the serializer prototype.
|
* Loads and configures the serializer prototype.
|
||||||
*
|
*
|
||||||
* @param array $config
|
* @param array $config
|
||||||
* @param ContainerBuilder $container
|
* @param ContainerBuilder $container
|
||||||
*/
|
*/
|
||||||
private function loadSerializer($config, 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.
|
* Creates a default manager alias for defined default manager or the first loaded driver.
|
||||||
*
|
*
|
||||||
* @param string $defaultManager
|
* @param string $defaultManager
|
||||||
* @param ContainerBuilder $container
|
* @param ContainerBuilder $container
|
||||||
*/
|
*/
|
||||||
private function createDefaultManagerAlias($defaultManager, 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.
|
* Returns a reference to a client given its configured name.
|
||||||
*
|
*
|
||||||
* @param string $clientName
|
* @param string $clientName
|
||||||
|
*
|
||||||
* @return Reference
|
* @return Reference
|
||||||
|
*
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
private function getClient($clientName)
|
private function getClient($clientName)
|
||||||
|
|
|
@ -10,24 +10,24 @@ use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
|
||||||
/**
|
/**
|
||||||
* Maps Elastica documents with Doctrine objects
|
* Maps Elastica documents with Doctrine objects
|
||||||
* This mapper assumes an exact match between
|
* 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
|
abstract class AbstractElasticaToModelTransformer implements ElasticaToModelTransformerInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Manager registry
|
* Manager registry.
|
||||||
*/
|
*/
|
||||||
protected $registry = null;
|
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
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $objectClass = null;
|
protected $objectClass = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optional parameters
|
* Optional parameters.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
|
@ -39,18 +39,18 @@ abstract class AbstractElasticaToModelTransformer implements ElasticaToModelTran
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PropertyAccessor instance
|
* PropertyAccessor instance.
|
||||||
*
|
*
|
||||||
* @var PropertyAccessorInterface
|
* @var PropertyAccessorInterface
|
||||||
*/
|
*/
|
||||||
protected $propertyAccessor;
|
protected $propertyAccessor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new Mapper
|
* Instantiates a new Mapper.
|
||||||
*
|
*
|
||||||
* @param object $registry
|
* @param object $registry
|
||||||
* @param string $objectClass
|
* @param string $objectClass
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*/
|
*/
|
||||||
public function __construct($registry, $objectClass, array $options = array())
|
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
|
* @param PropertyAccessorInterface $propertyAccessor
|
||||||
*/
|
*/
|
||||||
|
@ -81,10 +81,12 @@ abstract class AbstractElasticaToModelTransformer implements ElasticaToModelTran
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transforms an array of elastica objects into an array of
|
* 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
|
* @param array $elasticaObjects of elastica objects
|
||||||
|
*
|
||||||
* @throws \RuntimeException
|
* @throws \RuntimeException
|
||||||
|
*
|
||||||
* @return array
|
* @return array
|
||||||
**/
|
**/
|
||||||
public function transform(array $elasticaObjects)
|
public function transform(array $elasticaObjects)
|
||||||
|
@ -110,8 +112,7 @@ abstract class AbstractElasticaToModelTransformer implements ElasticaToModelTran
|
||||||
$idPos = array_flip($ids);
|
$idPos = array_flip($ids);
|
||||||
$identifier = $this->options['identifier'];
|
$identifier = $this->options['identifier'];
|
||||||
$propertyAccessor = $this->propertyAccessor;
|
$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)];
|
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
|
* @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.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param ObjectPersisterInterface $objectPersister
|
* @param ObjectPersisterInterface $objectPersister
|
||||||
* @param IndexableInterface $indexable
|
* @param IndexableInterface $indexable
|
||||||
* @param string $objectClass
|
* @param string $objectClass
|
||||||
* @param array $options
|
* @param array $options
|
||||||
* @param ManagerRegistry $managerRegistry
|
* @param ManagerRegistry $managerRegistry
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
ObjectPersisterInterface $objectPersister,
|
ObjectPersisterInterface $objectPersister,
|
||||||
|
@ -81,9 +81,9 @@ abstract class AbstractProvider extends BaseAbstractProvider
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
$this->objectPersister->insertMany($objects);
|
$this->objectPersister->insertMany($objects);
|
||||||
} catch(BulkResponseException $e) {
|
} catch (BulkResponseException $e) {
|
||||||
if ($loggerClosure) {
|
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.
|
* Counts objects that would be indexed using the query builder.
|
||||||
*
|
*
|
||||||
* @param object $queryBuilder
|
* @param object $queryBuilder
|
||||||
|
*
|
||||||
* @return integer
|
* @return integer
|
||||||
*/
|
*/
|
||||||
protected abstract function countObjects($queryBuilder);
|
abstract protected function countObjects($queryBuilder);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disables logging and returns the logger that was previously set.
|
* Disables logging and returns the logger that was previously set.
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @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
|
* @param mixed $logger
|
||||||
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
protected abstract function enableLogging($logger);
|
abstract protected function enableLogging($logger);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches a slice of objects using the query builder.
|
* Fetches a slice of objects using the query builder.
|
||||||
|
@ -137,14 +139,15 @@ abstract class AbstractProvider extends BaseAbstractProvider
|
||||||
* @param object $queryBuilder
|
* @param object $queryBuilder
|
||||||
* @param integer $limit
|
* @param integer $limit
|
||||||
* @param integer $offset
|
* @param integer $offset
|
||||||
|
*
|
||||||
* @return array
|
* @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.
|
* Creates the query builder, which will be used to fetch objects to index.
|
||||||
*
|
*
|
||||||
* @return object
|
* @return object
|
||||||
*/
|
*/
|
||||||
protected abstract function createQueryBuilder();
|
abstract protected function createQueryBuilder();
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,39 +17,39 @@ use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
|
||||||
class Listener implements EventSubscriber
|
class Listener implements EventSubscriber
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Object persister
|
* Object persister.
|
||||||
*
|
*
|
||||||
* @var ObjectPersister
|
* @var ObjectPersister
|
||||||
*/
|
*/
|
||||||
protected $objectPersister;
|
protected $objectPersister;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of subscribed events
|
* List of subscribed events.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $events;
|
protected $events;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuration for the listener
|
* Configuration for the listener.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $config;
|
private $config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Objects scheduled for insertion and replacement
|
* Objects scheduled for insertion and replacement.
|
||||||
*/
|
*/
|
||||||
public $scheduledForInsertion = array();
|
public $scheduledForInsertion = array();
|
||||||
public $scheduledForUpdate = array();
|
public $scheduledForUpdate = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IDs of objects scheduled for removal
|
* IDs of objects scheduled for removal.
|
||||||
*/
|
*/
|
||||||
public $scheduledForDeletion = array();
|
public $scheduledForDeletion = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PropertyAccessor instance
|
* PropertyAccessor instance.
|
||||||
*
|
*
|
||||||
* @var PropertyAccessorInterface
|
* @var PropertyAccessorInterface
|
||||||
*/
|
*/
|
||||||
|
@ -64,10 +64,10 @@ class Listener implements EventSubscriber
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param ObjectPersisterInterface $objectPersister
|
* @param ObjectPersisterInterface $objectPersister
|
||||||
* @param array $events
|
* @param array $events
|
||||||
* @param IndexableInterface $indexable
|
* @param IndexableInterface $indexable
|
||||||
* @param array $config
|
* @param array $config
|
||||||
* @param null $logger
|
* @param null $logger
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
ObjectPersisterInterface $objectPersister,
|
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
|
* @param EventArgs $eventArgs
|
||||||
* @return object Entity | Document
|
*
|
||||||
* @throws \RuntimeException if no valid getter is found.
|
* @return object Entity | Document
|
||||||
|
*
|
||||||
|
* @throws \RuntimeException if no valid getter is found.
|
||||||
*/
|
*/
|
||||||
private function getDoctrineObject(EventArgs $eventArgs)
|
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
|
* 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)
|
public function preRemove(EventArgs $eventArgs)
|
||||||
{
|
{
|
||||||
|
@ -155,7 +157,7 @@ class Listener implements EventSubscriber
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Persist scheduled objects to ElasticSearch
|
* 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()
|
private function persistScheduled()
|
||||||
{
|
{
|
||||||
|
@ -210,6 +212,7 @@ class Listener implements EventSubscriber
|
||||||
* Checks if the object is indexable or not.
|
* Checks if the object is indexable or not.
|
||||||
*
|
*
|
||||||
* @param object $object
|
* @param object $object
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function isObjectIndexable($object)
|
private function isObjectIndexable($object)
|
||||||
|
|
|
@ -7,15 +7,16 @@ use FOS\ElasticaBundle\Doctrine\AbstractElasticaToModelTransformer;
|
||||||
/**
|
/**
|
||||||
* Maps Elastica documents with Doctrine objects
|
* Maps Elastica documents with Doctrine objects
|
||||||
* This mapper assumes an exact match between
|
* 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
|
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
|
* @return array of objects or arrays
|
||||||
*/
|
*/
|
||||||
protected function findByIdentifiers(array $identifierValues, $hydrate)
|
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
|
* @param mixed $logger
|
||||||
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
protected function enableLogging($logger)
|
protected function enableLogging($logger)
|
||||||
|
|
|
@ -8,17 +8,18 @@ use Doctrine\ORM\Query;
|
||||||
/**
|
/**
|
||||||
* Maps Elastica documents with Doctrine objects
|
* Maps Elastica documents with Doctrine objects
|
||||||
* This mapper assumes an exact match between
|
* 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
|
class ElasticaToModelTransformer extends AbstractElasticaToModelTransformer
|
||||||
{
|
{
|
||||||
const ENTITY_ALIAS = 'o';
|
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
|
* @return array of objects or arrays
|
||||||
*/
|
*/
|
||||||
protected function findByIdentifiers(array $identifierValues, $hydrate)
|
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
|
* @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
|
* @param mixed $logger
|
||||||
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
protected function enableLogging($logger)
|
protected function enableLogging($logger)
|
||||||
|
@ -76,7 +77,7 @@ class Provider extends AbstractProvider
|
||||||
throw new InvalidArgumentTypeException($queryBuilder, 'Doctrine\ORM\QueryBuilder');
|
throw new InvalidArgumentTypeException($queryBuilder, 'Doctrine\ORM\QueryBuilder');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* An orderBy DQL part is required to avoid feching the same row twice.
|
* 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://stackoverflow.com/questions/6314879/does-limit-offset-length-require-order-by-for-pagination
|
||||||
* @see http://www.postgresql.org/docs/current/static/queries-limit.html
|
* @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 custom repository if one specified otherwise
|
||||||
* returns a basic repository.
|
* returns a basic repository.
|
||||||
|
@ -35,7 +35,7 @@ class RepositoryManager extends BaseManager
|
||||||
$realEntityName = $entityName;
|
$realEntityName = $entityName;
|
||||||
if (strpos($entityName, ':') !== false) {
|
if (strpos($entityName, ':') !== false) {
|
||||||
list($namespaceAlias, $simpleClassName) = explode(':', $entityName);
|
list($namespaceAlias, $simpleClassName) = explode(':', $entityName);
|
||||||
$realEntityName = $this->managerRegistry->getAliasNamespace($namespaceAlias) . '\\' . $simpleClassName;
|
$realEntityName = $this->managerRegistry->getAliasNamespace($namespaceAlias).'\\'.$simpleClassName;
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::getRepository($realEntityName);
|
return parent::getRepository($realEntityName);
|
||||||
|
|
|
@ -23,7 +23,7 @@ class Client extends BaseClient
|
||||||
private $indexCache = array();
|
private $indexCache = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Symfony's debugging Stopwatch
|
* Symfony's debugging Stopwatch.
|
||||||
*
|
*
|
||||||
* @var Stopwatch|null
|
* @var Stopwatch|null
|
||||||
*/
|
*/
|
||||||
|
@ -32,8 +32,9 @@ class Client extends BaseClient
|
||||||
/**
|
/**
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @param string $method
|
* @param string $method
|
||||||
* @param array $data
|
* @param array $data
|
||||||
* @param array $query
|
* @param array $query
|
||||||
|
*
|
||||||
* @return \Elastica\Response
|
* @return \Elastica\Response
|
||||||
*/
|
*/
|
||||||
public function request($path, $method = Request::GET, $data = array(), array $query = array())
|
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 $path
|
||||||
* @param string $method
|
* @param string $method
|
||||||
* @param array $data
|
* @param array $data
|
||||||
* @param array $query
|
* @param array $query
|
||||||
* @param int $start
|
* @param int $start
|
||||||
*/
|
*/
|
||||||
private function logQuery($path, $method, $data, array $query, $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
|
* 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
|
* since it's used for a very specific case and normally should not be used
|
||||||
*
|
*
|
||||||
* @param string $name Index name
|
* @param string $name Index name
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function overrideName($name)
|
public function overrideName($name)
|
||||||
{
|
{
|
||||||
|
|
|
@ -9,4 +9,3 @@ class AliasIsIndexException extends \Exception
|
||||||
parent::__construct(sprintf('Expected alias %s instead of index', $indexName));
|
parent::__construct(sprintf('Expected alias %s instead of index', $indexName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bundle.
|
* Bundle.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
class FOSElasticaBundle extends Bundle
|
class FOSElasticaBundle extends Bundle
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,12 +5,13 @@ namespace FOS\ElasticaBundle\Finder;
|
||||||
interface FinderInterface
|
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 mixed $query Can be a string, an array or an \Elastica\Query object
|
||||||
* @param int $limit How many results to get
|
* @param int $limit How many results to get
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return array results
|
* @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
|
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
|
* @param array $options
|
||||||
|
*
|
||||||
* @return Pagerfanta paginated results
|
* @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 mixed $query
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return PaginatorAdapterInterface
|
* @return PaginatorAdapterInterface
|
||||||
*/
|
*/
|
||||||
function createPaginatorAdapter($query, $options = array());
|
public function createPaginatorAdapter($query, $options = array());
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ use Elastica\SearchableInterface;
|
||||||
use Elastica\Query;
|
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
|
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 integer $limit
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return array of model objects
|
* @return array of model objects
|
||||||
**/
|
**/
|
||||||
public function find($query, $limit = null, $options = array())
|
public function find($query, $limit = null, $options = array())
|
||||||
|
@ -50,8 +51,9 @@ class TransformedFinder implements PaginatedFinderInterface
|
||||||
* Find documents similar to one with passed id.
|
* Find documents similar to one with passed id.
|
||||||
*
|
*
|
||||||
* @param integer $id
|
* @param integer $id
|
||||||
* @param array $params
|
* @param array $params
|
||||||
* @param array $query
|
* @param array $query
|
||||||
|
*
|
||||||
* @return array of model objects
|
* @return array of model objects
|
||||||
**/
|
**/
|
||||||
public function moreLikeThis($id, $params = array(), $query = array())
|
public function moreLikeThis($id, $params = array(), $query = array())
|
||||||
|
@ -65,7 +67,8 @@ class TransformedFinder implements PaginatedFinderInterface
|
||||||
/**
|
/**
|
||||||
* @param $query
|
* @param $query
|
||||||
* @param null|int $limit
|
* @param null|int $limit
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function search($query, $limit = null, $options = 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 string $query
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return Pagerfanta
|
* @return Pagerfanta
|
||||||
*/
|
*/
|
||||||
public function findPaginated($query, $options = array())
|
public function findPaginated($query, $options = array())
|
||||||
|
|
|
@ -24,4 +24,4 @@ class HybridResult
|
||||||
{
|
{
|
||||||
return $this->result;
|
return $this->result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ class AliasProcessor
|
||||||
* Sets the randomised root name for an index.
|
* Sets the randomised root name for an index.
|
||||||
*
|
*
|
||||||
* @param IndexConfig $indexConfig
|
* @param IndexConfig $indexConfig
|
||||||
* @param Index $index
|
* @param Index $index
|
||||||
*/
|
*/
|
||||||
public function setRootName(IndexConfig $indexConfig, 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.
|
* $force will delete an index encountered where an alias is expected.
|
||||||
*
|
*
|
||||||
* @param IndexConfig $indexConfig
|
* @param IndexConfig $indexConfig
|
||||||
* @param Index $index
|
* @param Index $index
|
||||||
* @param bool $force
|
* @param bool $force
|
||||||
|
*
|
||||||
* @throws AliasIsIndexException
|
* @throws AliasIsIndexException
|
||||||
* @throws \RuntimeException
|
* @throws \RuntimeException
|
||||||
*/
|
*/
|
||||||
|
@ -53,7 +54,7 @@ class AliasProcessor
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$aliasedIndexes = $this->getAliasedIndexes($client, $aliasName);
|
$aliasedIndexes = $this->getAliasedIndexes($client, $aliasName);
|
||||||
} catch(AliasIsIndexException $e) {
|
} catch (AliasIsIndexException $e) {
|
||||||
if (!$force) {
|
if (!$force) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
@ -68,7 +69,7 @@ class AliasProcessor
|
||||||
'Alias %s is used for multiple indexes: [%s].
|
'Alias %s is used for multiple indexes: [%s].
|
||||||
Make sure it\'s either not used or is assigned to one index only',
|
Make sure it\'s either not used or is assigned to one index only',
|
||||||
$aliasName,
|
$aliasName,
|
||||||
join(', ', $aliasedIndexes)
|
implode(', ', $aliasedIndexes)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -78,13 +79,13 @@ class AliasProcessor
|
||||||
// if the alias is set - add an action to remove it
|
// if the alias is set - add an action to remove it
|
||||||
$oldIndexName = $aliasedIndexes[0];
|
$oldIndexName = $aliasedIndexes[0];
|
||||||
$aliasUpdateRequest['actions'][] = array(
|
$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
|
// add an action to point the alias to the new index
|
||||||
$aliasUpdateRequest['actions'][] = array(
|
$aliasUpdateRequest['actions'][] = array(
|
||||||
'add' => array('index' => $newIndexName, 'alias' => $aliasName)
|
'add' => array('index' => $newIndexName, 'alias' => $aliasName),
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
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 Client $client
|
||||||
* @param string $aliasName Alias name
|
* @param string $aliasName Alias name
|
||||||
|
*
|
||||||
* @return array
|
* @return array
|
||||||
|
*
|
||||||
* @throws AliasIsIndexException
|
* @throws AliasIsIndexException
|
||||||
*/
|
*/
|
||||||
private function getAliasedIndexes(Client $client, $aliasName)
|
private function getAliasedIndexes(Client $client, $aliasName)
|
||||||
|
@ -159,7 +162,7 @@ class AliasProcessor
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete an index
|
* Delete an index.
|
||||||
*
|
*
|
||||||
* @param Client $client
|
* @param Client $client
|
||||||
* @param string $indexName Index name to delete
|
* @param string $indexName Index name to delete
|
||||||
|
|
|
@ -22,7 +22,7 @@ class IndexManager
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all registered indexes
|
* Gets all registered indexes.
|
||||||
*
|
*
|
||||||
* @return array
|
* @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
|
* @param string $name Index to return, or the default index if null
|
||||||
|
*
|
||||||
* @return Index
|
* @return Index
|
||||||
|
*
|
||||||
* @throws \InvalidArgumentException if no index exists for the given name
|
* @throws \InvalidArgumentException if no index exists for the given name
|
||||||
*/
|
*/
|
||||||
public function getIndex($name = null)
|
public function getIndex($name = null)
|
||||||
|
@ -52,7 +54,7 @@ class IndexManager
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the default index
|
* Gets the default index.
|
||||||
*
|
*
|
||||||
* @return Index
|
* @return Index
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -27,6 +27,7 @@ class MappingBuilder
|
||||||
* Builds mappings for an entire index.
|
* Builds mappings for an entire index.
|
||||||
*
|
*
|
||||||
* @param IndexConfig $indexConfig
|
* @param IndexConfig $indexConfig
|
||||||
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function buildIndexMapping(IndexConfig $indexConfig)
|
public function buildIndexMapping(IndexConfig $indexConfig)
|
||||||
|
@ -54,6 +55,7 @@ class MappingBuilder
|
||||||
* Builds mappings for a single type.
|
* Builds mappings for a single type.
|
||||||
*
|
*
|
||||||
* @param TypeConfig $typeConfig
|
* @param TypeConfig $typeConfig
|
||||||
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function buildTypeMapping(TypeConfig $typeConfig)
|
public function buildTypeMapping(TypeConfig $typeConfig)
|
||||||
|
@ -89,7 +91,7 @@ class MappingBuilder
|
||||||
|
|
||||||
if (!$mapping) {
|
if (!$mapping) {
|
||||||
// Empty mapping, we want it encoded as a {} instead of a []
|
// Empty mapping, we want it encoded as a {} instead of a []
|
||||||
$mapping = new \stdClass;
|
$mapping = new \stdClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $mapping;
|
return $mapping;
|
||||||
|
|
|
@ -8,7 +8,7 @@ use Elastica\Type\Mapping;
|
||||||
use FOS\ElasticaBundle\Configuration\ConfigManager;
|
use FOS\ElasticaBundle\Configuration\ConfigManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes and recreates indexes
|
* Deletes and recreates indexes.
|
||||||
*/
|
*/
|
||||||
class Resetter
|
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)
|
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.
|
* with a randomised name for an alias to be set after population.
|
||||||
*
|
*
|
||||||
* @param string $indexName
|
* @param string $indexName
|
||||||
* @param bool $populating
|
* @param bool $populating
|
||||||
* @param bool $force If index exists with same name as alias, remove it
|
* @param bool $force If index exists with same name as alias, remove it
|
||||||
|
*
|
||||||
* @throws \InvalidArgumentException if no index exists for the given name
|
* @throws \InvalidArgumentException if no index exists for the given name
|
||||||
*/
|
*/
|
||||||
public function resetIndex($indexName, $populating = false, $force = false)
|
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 $indexName
|
||||||
* @param string $typeName
|
* @param string $typeName
|
||||||
|
*
|
||||||
* @throws \InvalidArgumentException if no index or type mapping exists for the given names
|
* @throws \InvalidArgumentException if no index or type mapping exists for the given names
|
||||||
* @throws ResponseException
|
* @throws ResponseException
|
||||||
*/
|
*/
|
||||||
|
@ -97,7 +99,7 @@ class Resetter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$mapping = new Mapping;
|
$mapping = new Mapping();
|
||||||
foreach ($this->mappingBuilder->buildTypeMapping($typeConfig) as $name => $field) {
|
foreach ($this->mappingBuilder->buildTypeMapping($typeConfig) as $name => $field) {
|
||||||
$mapping->setParam($name, $field);
|
$mapping->setParam($name, $field);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,13 +25,13 @@ class RepositoryManager implements RepositoryManagerInterface
|
||||||
|
|
||||||
public function addEntity($entityName, FinderInterface $finder, $repositoryName = null)
|
public function addEntity($entityName, FinderInterface $finder, $repositoryName = null)
|
||||||
{
|
{
|
||||||
$this->entities[$entityName]= array();
|
$this->entities[$entityName] = array();
|
||||||
$this->entities[$entityName]['finder'] = $finder;
|
$this->entities[$entityName]['finder'] = $finder;
|
||||||
$this->entities[$entityName]['repositoryName'] = $repositoryName;
|
$this->entities[$entityName]['repositoryName'] = $repositoryName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return repository for entity
|
* Return repository for entity.
|
||||||
*
|
*
|
||||||
* Returns custom repository if one specified otherwise
|
* Returns custom repository if one specified otherwise
|
||||||
* returns a basic repository.
|
* returns a basic repository.
|
||||||
|
@ -63,6 +63,7 @@ class RepositoryManager implements RepositoryManagerInterface
|
||||||
if ($annotation) {
|
if ($annotation) {
|
||||||
$this->entities[$entityName]['repositoryName']
|
$this->entities[$entityName]['repositoryName']
|
||||||
= $annotation->repositoryClass;
|
= $annotation->repositoryClass;
|
||||||
|
|
||||||
return $annotation->repositoryClass;
|
return $annotation->repositoryClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ use FOS\ElasticaBundle\Finder\FinderInterface;
|
||||||
*/
|
*/
|
||||||
interface RepositoryManagerInterface
|
interface RepositoryManagerInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds entity name and its finder.
|
* Adds entity name and its finder.
|
||||||
* Custom repository class name can also be added.
|
* Custom repository class name can also be added.
|
||||||
|
@ -24,7 +23,7 @@ interface RepositoryManagerInterface
|
||||||
public function addEntity($entityName, FinderInterface $finder, $repositoryName = null);
|
public function addEntity($entityName, FinderInterface $finder, $repositoryName = null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return repository for entity
|
* Return repository for entity.
|
||||||
*
|
*
|
||||||
* Returns custom repository if one specified otherwise
|
* Returns custom repository if one specified otherwise
|
||||||
* returns a basic repository.
|
* returns a basic repository.
|
||||||
|
|
|
@ -29,7 +29,7 @@ class FantaPaginatorAdapter implements AdapterInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns Facets
|
* Returns Facets.
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*
|
*
|
||||||
|
|
|
@ -11,7 +11,7 @@ interface PaginatorAdapterInterface
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
function getTotalHits();
|
public function getTotalHits();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an slice of the results.
|
* Returns an slice of the results.
|
||||||
|
@ -23,12 +23,12 @@ interface PaginatorAdapterInterface
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
function getResults($offset, $length);
|
public function getResults($offset, $length);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns Facets
|
* Returns Facets.
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function getFacets();
|
public function getFacets();
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ interface PartialResultsInterface
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
function toArray();
|
public function toArray();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of results.
|
* Returns the number of results.
|
||||||
|
@ -20,12 +20,12 @@ interface PartialResultsInterface
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
function getTotalHits();
|
public function getTotalHits();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the facets
|
* Returns the facets.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function getFacets();
|
public function getFacets();
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ use Elastica\ResultSet;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows pagination of Elastica\Query. Does not map results
|
* Allows pagination of Elastica\Query. Does not map results.
|
||||||
*/
|
*/
|
||||||
class RawPaginatorAdapter implements PaginatorAdapterInterface
|
class RawPaginatorAdapter implements PaginatorAdapterInterface
|
||||||
{
|
{
|
||||||
|
@ -41,7 +41,7 @@ class RawPaginatorAdapter implements PaginatorAdapterInterface
|
||||||
* @see PaginatorAdapterInterface::__construct
|
* @see PaginatorAdapterInterface::__construct
|
||||||
*
|
*
|
||||||
* @param SearchableInterface $searchable the object to search in
|
* @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
|
* @param array $options
|
||||||
*/
|
*/
|
||||||
public function __construct(SearchableInterface $searchable, Query $query, array $options = array())
|
public function __construct(SearchableInterface $searchable, Query $query, array $options = array())
|
||||||
|
@ -56,7 +56,9 @@ class RawPaginatorAdapter implements PaginatorAdapterInterface
|
||||||
*
|
*
|
||||||
* @param integer $offset
|
* @param integer $offset
|
||||||
* @param integer $itemCountPerPage
|
* @param integer $itemCountPerPage
|
||||||
|
*
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
|
*
|
||||||
* @return ResultSet
|
* @return ResultSet
|
||||||
*/
|
*/
|
||||||
protected function getElasticaResults($offset, $itemCountPerPage)
|
protected function getElasticaResults($offset, $itemCountPerPage)
|
||||||
|
@ -82,6 +84,7 @@ class RawPaginatorAdapter implements PaginatorAdapterInterface
|
||||||
$resultSet = $this->searchable->search($query, $this->options);
|
$resultSet = $this->searchable->search($query, $this->options);
|
||||||
$this->totalHits = $resultSet->getTotalHits();
|
$this->totalHits = $resultSet->getTotalHits();
|
||||||
$this->facets = $resultSet->getFacets();
|
$this->facets = $resultSet->getFacets();
|
||||||
|
|
||||||
return $resultSet;
|
return $resultSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,6 +93,7 @@ class RawPaginatorAdapter implements PaginatorAdapterInterface
|
||||||
*
|
*
|
||||||
* @param int $offset
|
* @param int $offset
|
||||||
* @param int $itemCountPerPage
|
* @param int $itemCountPerPage
|
||||||
|
*
|
||||||
* @return PartialResultsInterface
|
* @return PartialResultsInterface
|
||||||
*/
|
*/
|
||||||
public function getResults($offset, $itemCountPerPage)
|
public function getResults($offset, $itemCountPerPage)
|
||||||
|
@ -104,7 +108,7 @@ class RawPaginatorAdapter implements PaginatorAdapterInterface
|
||||||
*/
|
*/
|
||||||
public function getTotalHits()
|
public function getTotalHits()
|
||||||
{
|
{
|
||||||
if ( ! isset($this->totalHits)) {
|
if (! isset($this->totalHits)) {
|
||||||
$this->totalHits = $this->searchable->search($this->query)->getTotalHits();
|
$this->totalHits = $this->searchable->search($this->query)->getTotalHits();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,13 +118,13 @@ class RawPaginatorAdapter implements PaginatorAdapterInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns Facets
|
* Returns Facets.
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function getFacets()
|
public function getFacets()
|
||||||
{
|
{
|
||||||
if ( ! isset($this->facets)) {
|
if (! isset($this->facets)) {
|
||||||
$this->facets = $this->searchable->search($this->query)->getFacets();
|
$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
|
* @return Query the search query
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -6,7 +6,7 @@ use Elastica\ResultSet;
|
||||||
use Elastica\Result;
|
use Elastica\Result;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Raw partial results transforms to a simple array
|
* Raw partial results transforms to a simple array.
|
||||||
*/
|
*/
|
||||||
class RawPartialResults implements PartialResultsInterface
|
class RawPartialResults implements PartialResultsInterface
|
||||||
{
|
{
|
||||||
|
@ -25,7 +25,7 @@ class RawPartialResults implements PartialResultsInterface
|
||||||
*/
|
*/
|
||||||
public function toArray()
|
public function toArray()
|
||||||
{
|
{
|
||||||
return array_map(function(Result $result) {
|
return array_map(function (Result $result) {
|
||||||
return $result->getSource();
|
return $result->getSource();
|
||||||
}, $this->resultSet->getResults());
|
}, $this->resultSet->getResults());
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,6 @@ class RawPartialResults implements PartialResultsInterface
|
||||||
return $this->resultSet->getFacets();
|
return $this->resultSet->getFacets();
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,15 +7,15 @@ use Elastica\SearchableInterface;
|
||||||
use Elastica\Query;
|
use Elastica\Query;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows pagination of \Elastica\Query
|
* Allows pagination of \Elastica\Query.
|
||||||
*/
|
*/
|
||||||
class TransformedPaginatorAdapter extends RawPaginatorAdapter
|
class TransformedPaginatorAdapter extends RawPaginatorAdapter
|
||||||
{
|
{
|
||||||
private $transformer;
|
private $transformer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param SearchableInterface $searchable the object to search in
|
* @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
|
* @param array $options
|
||||||
* @param ElasticaToModelTransformerInterface $transformer the transformer for fetching the results
|
* @param ElasticaToModelTransformerInterface $transformer the transformer for fetching the results
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -6,14 +6,14 @@ use FOS\ElasticaBundle\Transformer\ElasticaToModelTransformerInterface;
|
||||||
use Elastica\ResultSet;
|
use Elastica\ResultSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Partial transformed result set
|
* Partial transformed result set.
|
||||||
*/
|
*/
|
||||||
class TransformedPartialResults extends RawPartialResults
|
class TransformedPartialResults extends RawPartialResults
|
||||||
{
|
{
|
||||||
protected $transformer;
|
protected $transformer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ResultSet $resultSet
|
* @param ResultSet $resultSet
|
||||||
* @param \FOS\ElasticaBundle\Transformer\ElasticaToModelTransformerInterface $transformer
|
* @param \FOS\ElasticaBundle\Transformer\ElasticaToModelTransformerInterface $transformer
|
||||||
*/
|
*/
|
||||||
public function __construct(ResultSet $resultSet, ElasticaToModelTransformerInterface $transformer)
|
public function __construct(ResultSet $resultSet, ElasticaToModelTransformerInterface $transformer)
|
||||||
|
@ -30,4 +30,4 @@ class TransformedPartialResults extends RawPartialResults
|
||||||
{
|
{
|
||||||
return $this->transformer->transform($this->resultSet->getResults());
|
return $this->transformer->transform($this->resultSet->getResults());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ use Elastica\Document;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inserts, replaces and deletes single documents in an elastica type
|
* 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>
|
* @author Thibault Duplessis <thibault.duplessis@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
@ -34,6 +34,7 @@ class ObjectPersister implements ObjectPersisterInterface
|
||||||
* If the ObjectPersister handles a given object.
|
* If the ObjectPersister handles a given object.
|
||||||
*
|
*
|
||||||
* @param object $object
|
* @param object $object
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function handlesObject($object)
|
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
|
* @param BulkException $e
|
||||||
|
*
|
||||||
* @throws BulkException
|
* @throws BulkException
|
||||||
* @return null
|
|
||||||
*/
|
*/
|
||||||
private function log(BulkException $e)
|
private function log(BulkException $e)
|
||||||
{
|
{
|
||||||
|
@ -64,7 +65,7 @@ class ObjectPersister implements ObjectPersisterInterface
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Insert one object into the type
|
* 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
|
* @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
|
* @param object $object
|
||||||
* @return null
|
|
||||||
**/
|
**/
|
||||||
public function replaceOne($object)
|
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
|
* @param object $object
|
||||||
* @return null
|
|
||||||
**/
|
**/
|
||||||
public function deleteOne($object)
|
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
|
* @param mixed $id
|
||||||
*
|
|
||||||
* @return null
|
|
||||||
**/
|
**/
|
||||||
public function deleteById($id)
|
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 array $objects array of domain model objects
|
||||||
* @param string Method to call
|
* @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
|
* @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
|
* @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
|
* @param object $object
|
||||||
|
*
|
||||||
* @return Document the elastica document
|
* @return Document the elastica document
|
||||||
*/
|
*/
|
||||||
public function transformToElasticaDocument($object)
|
public function transformToElasticaDocument($object)
|
||||||
|
|
|
@ -4,7 +4,7 @@ namespace FOS\ElasticaBundle\Persister;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inserts, replaces and deletes single documents in an elastica type
|
* 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>
|
* @author Thibault Duplessis <thibault.duplessis@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
@ -12,58 +12,56 @@ interface ObjectPersisterInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Insert one object into the type
|
* 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
|
* @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
|
* @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
|
* @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
|
* @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
|
* @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
|
* @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
|
* @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
|
* @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
|
* Inserts, replaces and deletes single objects in an elastica type, making use
|
||||||
* of elastica's serializer support to convert objects in to elastica documents.
|
* 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>
|
* @author Lea Haensenberber <lea.haensenberger@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
@ -28,9 +28,10 @@ class ObjectSerializerPersister extends ObjectPersister
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transforms an object to an elastica document
|
* Transforms an object to an elastica document
|
||||||
* with just the identifier set
|
* with just the identifier set.
|
||||||
*
|
*
|
||||||
* @param object $object
|
* @param object $object
|
||||||
|
*
|
||||||
* @return Document the elastica document
|
* @return Document the elastica document
|
||||||
*/
|
*/
|
||||||
public function transformToElasticaDocument($object)
|
public function transformToElasticaDocument($object)
|
||||||
|
|
|
@ -44,7 +44,7 @@ class ElasticaToModelTransformer implements ElasticaToModelTransformerInterface
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param string $objectClass
|
* @param string $objectClass
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*/
|
*/
|
||||||
public function __construct($objectClass, array $options = array())
|
public function __construct($objectClass, array $options = array())
|
||||||
{
|
{
|
||||||
|
@ -67,6 +67,7 @@ class ElasticaToModelTransformer implements ElasticaToModelTransformerInterface
|
||||||
* fetched from the database.
|
* fetched from the database.
|
||||||
*
|
*
|
||||||
* @param array $elasticaObjects
|
* @param array $elasticaObjects
|
||||||
|
*
|
||||||
* @return array|\ArrayObject
|
* @return array|\ArrayObject
|
||||||
*/
|
*/
|
||||||
public function transform(array $elasticaObjects)
|
public function transform(array $elasticaObjects)
|
||||||
|
@ -83,7 +84,7 @@ class ElasticaToModelTransformer implements ElasticaToModelTransformerInterface
|
||||||
$identifier = $this->options['identifier'];
|
$identifier = $this->options['identifier'];
|
||||||
$propertyAccessor = $this->propertyAccessor;
|
$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)];
|
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 array $identifierValues Identifier values
|
||||||
* @param boolean $hydrate Whether or not to hydrate the results
|
* @param boolean $hydrate Whether or not to hydrate the results
|
||||||
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function findByIdentifiers(array $identifierValues, $hydrate)
|
protected function findByIdentifiers(array $identifierValues, $hydrate)
|
||||||
|
@ -145,7 +147,7 @@ class ElasticaToModelTransformer implements ElasticaToModelTransformerInterface
|
||||||
|
|
||||||
$query = $this->createQuery($this->objectClass, $this->options['identifier'], $identifierValues);
|
$query = $this->createQuery($this->objectClass, $this->options['identifier'], $identifierValues);
|
||||||
|
|
||||||
if ( ! $hydrate) {
|
if (! $hydrate) {
|
||||||
return $query->toArray();
|
return $query->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,6 +160,7 @@ class ElasticaToModelTransformer implements ElasticaToModelTransformerInterface
|
||||||
* @param string $class Propel model class
|
* @param string $class Propel model class
|
||||||
* @param string $identifierField Identifier field name (e.g. "id")
|
* @param string $identifierField Identifier field name (e.g. "id")
|
||||||
* @param array $identifierValues Identifier values
|
* @param array $identifierValues Identifier values
|
||||||
|
*
|
||||||
* @return \ModelCriteria
|
* @return \ModelCriteria
|
||||||
*/
|
*/
|
||||||
protected function createQuery($class, $identifierField, array $identifierValues)
|
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
|
* @see https://github.com/doctrine/common/blob/master/lib/Doctrine/Common/Util/Inflector.php
|
||||||
|
*
|
||||||
* @param string $str
|
* @param string $str
|
||||||
*/
|
*/
|
||||||
private function camelize($str)
|
private function camelize($str)
|
||||||
|
|
|
@ -5,7 +5,7 @@ namespace FOS\ElasticaBundle\Propel;
|
||||||
use FOS\ElasticaBundle\Provider\AbstractProvider;
|
use FOS\ElasticaBundle\Provider\AbstractProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Propel provider
|
* Propel provider.
|
||||||
*
|
*
|
||||||
* @author William Durand <william.durand1@gmail.com>
|
* @author William Durand <william.durand1@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
@ -16,7 +16,7 @@ class Provider extends AbstractProvider
|
||||||
*/
|
*/
|
||||||
public function populate(\Closure $loggerClosure = null, array $options = array())
|
public function populate(\Closure $loggerClosure = null, array $options = array())
|
||||||
{
|
{
|
||||||
$queryClass = $this->objectClass . 'Query';
|
$queryClass = $this->objectClass.'Query';
|
||||||
$nbObjects = $queryClass::create()->count();
|
$nbObjects = $queryClass::create()->count();
|
||||||
$offset = isset($options['offset']) ? intval($options['offset']) : 0;
|
$offset = isset($options['offset']) ? intval($options['offset']) : 0;
|
||||||
$sleep = isset($options['sleep']) ? intval($options['sleep']) : 0;
|
$sleep = isset($options['sleep']) ? intval($options['sleep']) : 0;
|
||||||
|
|
|
@ -5,7 +5,7 @@ namespace FOS\ElasticaBundle\Provider;
|
||||||
use FOS\ElasticaBundle\Persister\ObjectPersisterInterface;
|
use FOS\ElasticaBundle\Persister\ObjectPersisterInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AbstractProvider
|
* AbstractProvider.
|
||||||
*/
|
*/
|
||||||
abstract class AbstractProvider implements ProviderInterface
|
abstract class AbstractProvider implements ProviderInterface
|
||||||
{
|
{
|
||||||
|
@ -33,9 +33,9 @@ abstract class AbstractProvider implements ProviderInterface
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param ObjectPersisterInterface $objectPersister
|
* @param ObjectPersisterInterface $objectPersister
|
||||||
* @param IndexableInterface $indexable
|
* @param IndexableInterface $indexable
|
||||||
* @param string $objectClass
|
* @param string $objectClass
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
ObjectPersisterInterface $objectPersister,
|
ObjectPersisterInterface $objectPersister,
|
||||||
|
@ -56,6 +56,7 @@ abstract class AbstractProvider implements ProviderInterface
|
||||||
* Checks if a given object should be indexed or not.
|
* Checks if a given object should be indexed or not.
|
||||||
*
|
*
|
||||||
* @param object $object
|
* @param object $object
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function isObjectIndexable($object)
|
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
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -33,7 +33,7 @@ class Indexable implements IndexableInterface
|
||||||
private $container;
|
private $container;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An instance of ExpressionLanguage
|
* An instance of ExpressionLanguage.
|
||||||
*
|
*
|
||||||
* @var ExpressionLanguage
|
* @var ExpressionLanguage
|
||||||
*/
|
*/
|
||||||
|
@ -47,7 +47,7 @@ class Indexable implements IndexableInterface
|
||||||
private $initialisedCallbacks = array();
|
private $initialisedCallbacks = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PropertyAccessor instance
|
* PropertyAccessor instance.
|
||||||
*
|
*
|
||||||
* @var PropertyAccessorInterface
|
* @var PropertyAccessorInterface
|
||||||
*/
|
*/
|
||||||
|
@ -68,7 +68,8 @@ class Indexable implements IndexableInterface
|
||||||
*
|
*
|
||||||
* @param string $indexName
|
* @param string $indexName
|
||||||
* @param string $typeName
|
* @param string $typeName
|
||||||
* @param mixed $object
|
* @param mixed $object
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isObjectIndexable($indexName, $typeName, $object)
|
public function isObjectIndexable($indexName, $typeName, $object)
|
||||||
|
@ -82,7 +83,7 @@ class Indexable implements IndexableInterface
|
||||||
if ($callback instanceof Expression) {
|
if ($callback instanceof Expression) {
|
||||||
return $this->getExpressionLanguage()->evaluate($callback, array(
|
return $this->getExpressionLanguage()->evaluate($callback, array(
|
||||||
'object' => $object,
|
'object' => $object,
|
||||||
$this->getExpressionVar($object) => $object
|
$this->getExpressionVar($object) => $object,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,12 +97,13 @@ class Indexable implements IndexableInterface
|
||||||
*
|
*
|
||||||
* @param string $type
|
* @param string $type
|
||||||
* @param object $object
|
* @param object $object
|
||||||
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
private function buildCallback($type, $object)
|
private function buildCallback($type, $object)
|
||||||
{
|
{
|
||||||
if (!array_key_exists($type, $this->callbacks)) {
|
if (!array_key_exists($type, $this->callbacks)) {
|
||||||
return null;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$callback = $this->callbacks[$type];
|
$callback = $this->callbacks[$type];
|
||||||
|
@ -148,6 +150,7 @@ class Indexable implements IndexableInterface
|
||||||
*
|
*
|
||||||
* @param string $type
|
* @param string $type
|
||||||
* @param object $object
|
* @param object $object
|
||||||
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
private function getCallback($type, $object)
|
private function getCallback($type, $object)
|
||||||
|
@ -177,6 +180,7 @@ class Indexable implements IndexableInterface
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed $object
|
* @param mixed $object
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function getExpressionVar($object = null)
|
private function getExpressionVar($object = null)
|
||||||
|
|
|
@ -18,7 +18,8 @@ interface IndexableInterface
|
||||||
*
|
*
|
||||||
* @param string $indexName
|
* @param string $indexName
|
||||||
* @param string $typeName
|
* @param string $typeName
|
||||||
* @param mixed $object
|
* @param mixed $object
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isObjectIndexable($indexName, $typeName, $object);
|
public function isObjectIndexable($indexName, $typeName, $object);
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
namespace FOS\ElasticaBundle\Provider;
|
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>
|
* @author Thibault Duplessis <thibault.duplessis@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
@ -14,7 +14,8 @@ interface ProviderInterface
|
||||||
*
|
*
|
||||||
* @param \Closure $loggerClosure
|
* @param \Closure $loggerClosure
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return
|
* @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.
|
* Providers will be indexed by "type" strings in the returned array.
|
||||||
*
|
*
|
||||||
* @param string $index
|
* @param string $index
|
||||||
|
*
|
||||||
* @return array of ProviderInterface instances
|
* @return array of ProviderInterface instances
|
||||||
|
*
|
||||||
* @throws \InvalidArgumentException if no providers were registered for the index
|
* @throws \InvalidArgumentException if no providers were registered for the index
|
||||||
*/
|
*/
|
||||||
public function getIndexProviders($index)
|
public function getIndexProviders($index)
|
||||||
|
@ -81,7 +83,9 @@ class ProviderRegistry implements ContainerAwareInterface
|
||||||
*
|
*
|
||||||
* @param string $index
|
* @param string $index
|
||||||
* @param string $type
|
* @param string $type
|
||||||
|
*
|
||||||
* @return ProviderInterface
|
* @return ProviderInterface
|
||||||
|
*
|
||||||
* @throws \InvalidArgumentException if no provider was registered for the index and type
|
* @throws \InvalidArgumentException if no provider was registered for the index and type
|
||||||
*/
|
*/
|
||||||
public function getProvider($index, $type)
|
public function getProvider($index, $type)
|
||||||
|
|
|
@ -20,9 +20,10 @@ class Repository
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed $query
|
* @param mixed $query
|
||||||
* @param integer $limit
|
* @param integer $limit
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function find($query, $limit = null, $options = 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 integer $limit
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function findHybrid($query, $limit = null, $options = array())
|
public function findHybrid($query, $limit = null, $options = array())
|
||||||
|
@ -44,6 +46,7 @@ class Repository
|
||||||
/**
|
/**
|
||||||
* @param mixed $query
|
* @param mixed $query
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return \Pagerfanta\Pagerfanta
|
* @return \Pagerfanta\Pagerfanta
|
||||||
*/
|
*/
|
||||||
public function findPaginated($query, $options = array())
|
public function findPaginated($query, $options = array())
|
||||||
|
@ -53,7 +56,8 @@ class Repository
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $query
|
* @param string $query
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return Paginator\PaginatorAdapterInterface
|
* @return Paginator\PaginatorAdapterInterface
|
||||||
*/
|
*/
|
||||||
public function createPaginatorAdapter($query, $options = array())
|
public function createPaginatorAdapter($query, $options = array())
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
<parameter key="fos_elastica.elastica_to_model_transformer.prototype.orm.class">FOS\ElasticaBundle\Doctrine\ORM\ElasticaToModelTransformer</parameter>
|
<parameter key="fos_elastica.elastica_to_model_transformer.prototype.orm.class">FOS\ElasticaBundle\Doctrine\ORM\ElasticaToModelTransformer</parameter>
|
||||||
<parameter key="fos_elastica.manager.orm.class">FOS\ElasticaBundle\Doctrine\RepositoryManager</parameter>
|
<parameter key="fos_elastica.manager.orm.class">FOS\ElasticaBundle\Doctrine\RepositoryManager</parameter>
|
||||||
</parameters>
|
</parameters>
|
||||||
|
|
||||||
<services>
|
<services>
|
||||||
<service id="fos_elastica.provider.prototype.orm" class="%fos_elastica.provider.prototype.orm.class%" public="true" abstract="true">
|
<service id="fos_elastica.provider.prototype.orm" class="%fos_elastica.provider.prototype.orm.class%" public="true" abstract="true">
|
||||||
<argument /> <!-- object persister -->
|
<argument /> <!-- object persister -->
|
||||||
|
|
|
@ -38,7 +38,7 @@ class PaginateElasticaQuerySubscriber implements EventSubscriberInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds knp paging sort to query
|
* Adds knp paging sort to query.
|
||||||
*
|
*
|
||||||
* @param ItemsEvent $event
|
* @param ItemsEvent $event
|
||||||
*/
|
*/
|
||||||
|
@ -70,7 +70,7 @@ class PaginateElasticaQuerySubscriber implements EventSubscriberInterface
|
||||||
public static function getSubscribedEvents()
|
public static function getSubscribedEvents()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'knp_pager.items' => array('items', 1)
|
'knp_pager.items' => array('items', 1),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
namespace FOS\ElasticaBundle\Tests\Command;
|
namespace FOS\ElasticaBundle\Tests\Command;
|
||||||
|
|
||||||
|
|
||||||
use FOS\ElasticaBundle\Command\ResetCommand;
|
use FOS\ElasticaBundle\Command\ResetCommand;
|
||||||
use Symfony\Component\Console\Input\ArrayInput;
|
use Symfony\Component\Console\Input\ArrayInput;
|
||||||
use Symfony\Component\Console\Output\NullOutput;
|
use Symfony\Component\Console\Output\NullOutput;
|
||||||
|
@ -88,4 +87,4 @@ class ResetCommandTest extends \PHPUnit_Framework_TestCase
|
||||||
new NullOutput()
|
new NullOutput()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ use FOS\ElasticaBundle\DependencyInjection\Configuration;
|
||||||
use Symfony\Component\Config\Definition\Processor;
|
use Symfony\Component\Config\Definition\Processor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ConfigurationTest
|
* ConfigurationTest.
|
||||||
*/
|
*/
|
||||||
class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
@ -34,7 +34,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->assertSame(array(
|
$this->assertSame(array(
|
||||||
'clients' => array(),
|
'clients' => array(),
|
||||||
'indexes' => array(),
|
'indexes' => array(),
|
||||||
'default_manager' => 'orm'
|
'default_manager' => 'orm',
|
||||||
), $configuration);
|
), $configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,18 +50,18 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
||||||
array(
|
array(
|
||||||
'url' => 'http://es1:9200',
|
'url' => 'http://es1:9200',
|
||||||
'headers' => array(
|
'headers' => array(
|
||||||
'Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=='
|
'Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==',
|
||||||
)
|
),
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'url' => 'http://es2:9200',
|
'url' => 'http://es2:9200',
|
||||||
'headers' => array(
|
'headers' => array(
|
||||||
'Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=='
|
'Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==',
|
||||||
)
|
),
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->assertCount(2, $configuration['clients']);
|
$this->assertCount(2, $configuration['clients']);
|
||||||
|
@ -91,9 +91,9 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
||||||
),
|
),
|
||||||
'logging_custom' => array(
|
'logging_custom' => array(
|
||||||
'url' => 'http://localhost:9200',
|
'url' => 'http://localhost:9200',
|
||||||
'logger' => 'custom.service'
|
'logger' => 'custom.service',
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->assertCount(4, $configuration['clients']);
|
$this->assertCount(4, $configuration['clients']);
|
||||||
|
@ -131,8 +131,8 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
||||||
),
|
),
|
||||||
'serializer' => array(
|
'serializer' => array(
|
||||||
'groups' => array('Search'),
|
'groups' => array('Search'),
|
||||||
'version' => 1
|
'version' => 1,
|
||||||
)
|
),
|
||||||
),
|
),
|
||||||
'types' => array(
|
'types' => array(
|
||||||
'test' => array(
|
'test' => array(
|
||||||
|
@ -144,20 +144,20 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
||||||
'persistence' => array(
|
'persistence' => array(
|
||||||
'listener' => array(
|
'listener' => array(
|
||||||
'logger' => true,
|
'logger' => true,
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
),
|
),
|
||||||
'test2' => array(
|
'test2' => array(
|
||||||
'mappings' => array(
|
'mappings' => array(
|
||||||
'title' => null,
|
'title' => null,
|
||||||
'children' => array(
|
'children' => array(
|
||||||
'type' => 'nested',
|
'type' => 'nested',
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
||||||
'host' => 'localhost',
|
'host' => 'localhost',
|
||||||
'port' => 9200,
|
'port' => 9200,
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->assertTrue(empty($configuration['clients']['default']['connections'][0]['url']));
|
$this->assertTrue(empty($configuration['clients']['default']['connections'][0]['url']));
|
||||||
|
@ -189,11 +189,11 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
||||||
'title' => array(),
|
'title' => array(),
|
||||||
'published' => array('type' => 'datetime'),
|
'published' => array('type' => 'datetime'),
|
||||||
'body' => null,
|
'body' => null,
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->assertCount(3, $configuration['indexes']['test']['types']['test']['properties']);
|
$this->assertCount(3, $configuration['indexes']['test']['types']['test']['properties']);
|
||||||
|
@ -208,10 +208,10 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
||||||
'indexes' => array(
|
'indexes' => array(
|
||||||
'test' => array(
|
'test' => array(
|
||||||
'types' => array(
|
'types' => array(
|
||||||
'test' => null
|
'test' => null,
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->assertArrayHasKey('properties', $configuration['indexes']['test']['types']['test']);
|
$this->assertArrayHasKey('properties', $configuration['indexes']['test']['types']['test']);
|
||||||
|
@ -243,23 +243,23 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
||||||
'type' => 'nested',
|
'type' => 'nested',
|
||||||
'properties' => array(
|
'properties' => array(
|
||||||
'nested_field1' => array(
|
'nested_field1' => array(
|
||||||
'type' => 'integer'
|
'type' => 'integer',
|
||||||
),
|
),
|
||||||
'nested_field2' => array(
|
'nested_field2' => array(
|
||||||
'type' => 'object',
|
'type' => 'object',
|
||||||
'properties' => array(
|
'properties' => array(
|
||||||
'id' => 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'));
|
$config = Yaml::parse(file_get_contents(__DIR__.'/fixtures/config.yml'));
|
||||||
|
|
||||||
$containerBuilder = new ContainerBuilder;
|
$containerBuilder = new ContainerBuilder();
|
||||||
$containerBuilder->setParameter('kernel.debug', true);
|
$containerBuilder->setParameter('kernel.debug', true);
|
||||||
|
|
||||||
$extension = new FOSElasticaExtension;
|
$extension = new FOSElasticaExtension();
|
||||||
|
|
||||||
$extension->load($config, $containerBuilder);
|
$extension->load($config, $containerBuilder);
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ class AbstractElasticaToModelTransformerTest extends \PHPUnit_Framework_TestCase
|
||||||
protected $objectClass = 'stdClass';
|
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()
|
public function testIgnoreMissingOptionDuringTransformHybrid()
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
namespace FOS\ElasticaBundle\Tests\Doctrine;
|
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>
|
* @author Richard Miller <info@limethinking.co.uk>
|
||||||
*/
|
*/
|
||||||
|
@ -213,8 +213,8 @@ abstract class ListenerTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Listener\Entity $object
|
* @param Listener\Entity $object
|
||||||
* @param string $indexName
|
* @param string $indexName
|
||||||
* @param string $typeName
|
* @param string $typeName
|
||||||
*/
|
*/
|
||||||
private function getMockPersister($object, $indexName, $typeName)
|
private function getMockPersister($object, $indexName, $typeName)
|
||||||
{
|
{
|
||||||
|
@ -247,10 +247,10 @@ abstract class ListenerTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $indexName
|
* @param string $indexName
|
||||||
* @param string $typeName
|
* @param string $typeName
|
||||||
* @param Listener\Entity $object
|
* @param Listener\Entity $object
|
||||||
* @param boolean $return
|
* @param boolean $return
|
||||||
*/
|
*/
|
||||||
private function getMockIndexable($indexName, $typeName, $object, $return = null)
|
private function getMockIndexable($indexName, $typeName, $object, $return = null)
|
||||||
{
|
{
|
||||||
|
@ -286,4 +286,3 @@ class Entity
|
||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,7 @@ class AbstractProviderTest extends \PHPUnit_Framework_TestCase
|
||||||
return array(
|
return array(
|
||||||
array(
|
array(
|
||||||
100,
|
100,
|
||||||
array(range(1,100)),
|
array(range(1, 100)),
|
||||||
100,
|
100,
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
|
@ -231,7 +231,6 @@ class AbstractProviderTest extends \PHPUnit_Framework_TestCase
|
||||||
->with('index', 'type', 2)
|
->with('index', 'type', 2)
|
||||||
->will($this->returnValue(true));
|
->will($this->returnValue(true));
|
||||||
|
|
||||||
|
|
||||||
$this->objectPersister->expects($this->once())
|
$this->objectPersister->expects($this->once())
|
||||||
->method('insertMany')
|
->method('insertMany')
|
||||||
->with(array(1 => 2));
|
->with(array(1 => 2));
|
||||||
|
@ -259,7 +258,7 @@ class AbstractProviderTest extends \PHPUnit_Framework_TestCase
|
||||||
private function getMockBulkResponseException()
|
private function getMockBulkResponseException()
|
||||||
{
|
{
|
||||||
return $this->getMock('Elastica\Exception\Bulk\ResponseException', null, array(
|
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()
|
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
|
interface ObjectManager
|
||||||
{
|
{
|
||||||
function clear();
|
public function clear();
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,7 +109,7 @@ class ElasticaToModelTransformerTest extends \PHPUnit_Framework_TestCase
|
||||||
'findAll',
|
'findAll',
|
||||||
'findBy',
|
'findBy',
|
||||||
'findOneBy',
|
'findOneBy',
|
||||||
'getClassName'
|
'getClassName',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->manager->expects($this->any())
|
$this->manager->expects($this->any())
|
||||||
|
|
|
@ -4,9 +4,13 @@ namespace FOS\ElasticaBundle\Tests\Doctrine;
|
||||||
|
|
||||||
use FOS\ElasticaBundle\Doctrine\RepositoryManager;
|
use FOS\ElasticaBundle\Doctrine\RepositoryManager;
|
||||||
|
|
||||||
class CustomRepository{}
|
class CustomRepository
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
class Entity{}
|
class Entity
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Richard Miller <info@limethinking.co.uk>
|
* @author Richard Miller <info@limethinking.co.uk>
|
||||||
|
|
|
@ -5,11 +5,11 @@ namespace FOS\ElasticaBundle\Tests\Client;
|
||||||
use Elastica\Request;
|
use Elastica\Request;
|
||||||
use Elastica\Transport\Null as NullTransport;
|
use Elastica\Transport\Null as NullTransport;
|
||||||
|
|
||||||
class LoggingClientTest extends \PHPUnit_Framework_TestCase
|
class ClientTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testRequestsAreLogged()
|
public function testRequestsAreLogged()
|
||||||
{
|
{
|
||||||
$transport = new NullTransport;
|
$transport = new NullTransport();
|
||||||
|
|
||||||
$connection = $this->getMock('Elastica\Connection');
|
$connection = $this->getMock('Elastica\Connection');
|
||||||
$connection->expects($this->any())->method('getTransportObject')->will($this->returnValue($transport));
|
$connection->expects($this->any())->method('getTransportObject')->will($this->returnValue($transport));
|
||||||
|
|
|
@ -16,7 +16,6 @@ class FOSElasticaBundleTest extends \PHPUnit_Framework_TestCase
|
||||||
->method('addCompilerPass')
|
->method('addCompilerPass')
|
||||||
->with($this->isInstanceOf('Symfony\\Component\\DependencyInjection\\Compiler\\CompilerPassInterface'));
|
->with($this->isInstanceOf('Symfony\\Component\\DependencyInjection\\Compiler\\CompilerPassInterface'));
|
||||||
|
|
||||||
|
|
||||||
$bundle = new FOSElasticaBundle();
|
$bundle = new FOSElasticaBundle();
|
||||||
$bundle->build($container);
|
$bundle->build($container);
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,7 @@ class ConfigurationManagerTest extends WebTestCase
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Client $client
|
* @param Client $client
|
||||||
|
*
|
||||||
* @return \FOS\ElasticaBundle\Configuration\ConfigManager
|
* @return \FOS\ElasticaBundle\Configuration\ConfigManager
|
||||||
*/
|
*/
|
||||||
private function getManager(Client $client)
|
private function getManager(Client $client)
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace FOS\ElasticaBundle\Tests\Functional;
|
||||||
class IndexableCallbackTest extends WebTestCase
|
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
|
* 1) To test that the configuration rename from is_indexable_callback under the listener
|
||||||
* key is respected, and
|
* key is respected, and
|
||||||
|
|
|
@ -100,6 +100,7 @@ class MappingToElasticaTest extends WebTestCase
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Client $client
|
* @param Client $client
|
||||||
|
*
|
||||||
* @return \FOS\ElasticaBundle\Resetter $resetter
|
* @return \FOS\ElasticaBundle\Resetter $resetter
|
||||||
*/
|
*/
|
||||||
private function getResetter(Client $client)
|
private function getResetter(Client $client)
|
||||||
|
@ -109,11 +110,12 @@ class MappingToElasticaTest extends WebTestCase
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Client $client
|
* @param Client $client
|
||||||
|
*
|
||||||
* @return \Elastica\Type
|
* @return \Elastica\Type
|
||||||
*/
|
*/
|
||||||
private function getType(Client $client, $type = '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()
|
protected function setUp()
|
||||||
|
|
|
@ -115,4 +115,4 @@ class AppKernel extends Kernel
|
||||||
|
|
||||||
return $parameters;
|
return $parameters;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,4 +47,3 @@ fos_elastica:
|
||||||
serializer:
|
serializer:
|
||||||
groups: ['search', 'Default']
|
groups: ['search', 'Default']
|
||||||
version: 1.1
|
version: 1.1
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,6 @@ class IndexManagerTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
private $indexManager;
|
private $indexManager;
|
||||||
|
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
foreach (array('index1', 'index2', 'index3') as $indexName) {
|
foreach (array('index1', 'index2', 'index3') as $indexName) {
|
||||||
|
|
|
@ -8,10 +8,8 @@
|
||||||
* with this source code in the file LICENSE.
|
* with this source code in the file LICENSE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
namespace FOS\ElasticaBundle\Tests\Integration;
|
namespace FOS\ElasticaBundle\Tests\Integration;
|
||||||
|
|
||||||
|
class MappingTest
|
||||||
class MappingTest {
|
{
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -22,7 +22,8 @@ class ElasticaLoggerTest extends \PHPUnit_Framework_TestCase
|
||||||
/**
|
/**
|
||||||
* @param string $level
|
* @param string $level
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param array $context
|
* @param array $context
|
||||||
|
*
|
||||||
* @return ElasticaLogger
|
* @return ElasticaLogger
|
||||||
*/
|
*/
|
||||||
private function getMockLoggerForLevelMessageAndContext($level, $message, $context)
|
private function getMockLoggerForLevelMessageAndContext($level, $message, $context)
|
||||||
|
@ -45,7 +46,7 @@ class ElasticaLoggerTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testGetZeroIfNoQueriesAdded()
|
public function testGetZeroIfNoQueriesAdded()
|
||||||
{
|
{
|
||||||
$elasticaLogger = new ElasticaLogger;
|
$elasticaLogger = new ElasticaLogger();
|
||||||
$this->assertEquals(0, $elasticaLogger->getNbQueries());
|
$this->assertEquals(0, $elasticaLogger->getNbQueries());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,16 +4,19 @@ namespace FOS\ElasticaBundle\Tests\Manager;
|
||||||
|
|
||||||
use FOS\ElasticaBundle\Manager\RepositoryManager;
|
use FOS\ElasticaBundle\Manager\RepositoryManager;
|
||||||
|
|
||||||
class CustomRepository{}
|
class CustomRepository
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
class Entity{}
|
class Entity
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Richard Miller <info@limethinking.co.uk>
|
* @author Richard Miller <info@limethinking.co.uk>
|
||||||
*/
|
*/
|
||||||
class RepositoryManagerTest extends \PHPUnit_Framework_TestCase
|
class RepositoryManagerTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
public function testThatGetRepositoryReturnsDefaultRepository()
|
public function testThatGetRepositoryReturnsDefaultRepository()
|
||||||
{
|
{
|
||||||
/** @var $finderMock \PHPUnit_Framework_MockObject_MockObject|\FOS\ElasticaBundle\Finder\TransformedFinder */
|
/** @var $finderMock \PHPUnit_Framework_MockObject_MockObject|\FOS\ElasticaBundle\Finder\TransformedFinder */
|
||||||
|
|
|
@ -33,9 +33,9 @@ class ObjectPersisterTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
if (!class_exists('Elastica\Type')) {
|
if (!class_exists('Elastica\Type')) {
|
||||||
$this->markTestSkipped('The Elastica library classes are not available');
|
$this->markTestSkipped('The Elastica library classes are not available');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testThatCanReplaceObject()
|
public function testThatCanReplaceObject()
|
||||||
|
|
|
@ -26,9 +26,9 @@ class ObjectSerializerPersisterTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
if (!class_exists('Elastica\Type')) {
|
if (!class_exists('Elastica\Type')) {
|
||||||
$this->markTestSkipped('The Elastica library classes are not available');
|
$this->markTestSkipped('The Elastica library classes are not available');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testThatCanReplaceObject()
|
public function testThatCanReplaceObject()
|
||||||
|
|
|
@ -21,7 +21,7 @@ class IndexableTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testIndexableUnknown()
|
public function testIndexableUnknown()
|
||||||
{
|
{
|
||||||
$indexable = new Indexable(array(), $this->container);
|
$indexable = new Indexable(array(), $this->container);
|
||||||
$index = $indexable->isObjectIndexable('index', 'type', new Entity);
|
$index = $indexable->isObjectIndexable('index', 'type', new Entity());
|
||||||
|
|
||||||
$this->assertTrue($index);
|
$this->assertTrue($index);
|
||||||
}
|
}
|
||||||
|
@ -32,9 +32,9 @@ class IndexableTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testValidIndexableCallbacks($callback, $return)
|
public function testValidIndexableCallbacks($callback, $return)
|
||||||
{
|
{
|
||||||
$indexable = new Indexable(array(
|
$indexable = new Indexable(array(
|
||||||
'index/type' => $callback
|
'index/type' => $callback,
|
||||||
), $this->container);
|
), $this->container);
|
||||||
$index = $indexable->isObjectIndexable('index', 'type', new Entity);
|
$index = $indexable->isObjectIndexable('index', 'type', new Entity());
|
||||||
|
|
||||||
$this->assertEquals($return, $index);
|
$this->assertEquals($return, $index);
|
||||||
}
|
}
|
||||||
|
@ -46,9 +46,9 @@ class IndexableTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testInvalidIsIndexableCallbacks($callback)
|
public function testInvalidIsIndexableCallbacks($callback)
|
||||||
{
|
{
|
||||||
$indexable = new Indexable(array(
|
$indexable = new Indexable(array(
|
||||||
'index/type' => $callback
|
'index/type' => $callback,
|
||||||
), $this->container);
|
), $this->container);
|
||||||
$indexable->isObjectIndexable('index', 'type', new Entity);
|
$indexable->isObjectIndexable('index', 'type', new Entity());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function provideInvalidIsIndexableCallbacks()
|
public function provideInvalidIsIndexableCallbacks()
|
||||||
|
@ -67,7 +67,7 @@ class IndexableTest extends \PHPUnit_Framework_TestCase
|
||||||
array('isIndexable', false),
|
array('isIndexable', false),
|
||||||
array(array(new IndexableDecider(), 'isIndexable'), true),
|
array(array(new IndexableDecider(), 'isIndexable'), true),
|
||||||
array(array('@indexableService', '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('entity.maybeIndex()', true),
|
||||||
array('!object.isIndexable() && entity.property == "abc"', true),
|
array('!object.isIndexable() && entity.property == "abc"', true),
|
||||||
array('entity.property != "abc"', false),
|
array('entity.property != "abc"', false),
|
||||||
|
|
|
@ -13,14 +13,7 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$testQuery = 'Test Query';
|
$testQuery = 'Test Query';
|
||||||
|
|
||||||
/** @var $typeMock \PHPUnit_Framework_MockObject_MockObject|\FOS\ElasticaBundle\Finder\TransformedFinder */
|
$finderMock = $this->getFinderMock($testQuery);
|
||||||
$finderMock = $this->getMockBuilder('FOS\ElasticaBundle\Finder\TransformedFinder')
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
$finderMock->expects($this->once())
|
|
||||||
->method('find')
|
|
||||||
->with($this->equalTo($testQuery));
|
|
||||||
|
|
||||||
$repository = new Repository($finderMock);
|
$repository = new Repository($finderMock);
|
||||||
$repository->find($testQuery);
|
$repository->find($testQuery);
|
||||||
}
|
}
|
||||||
|
@ -30,14 +23,7 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase
|
||||||
$testQuery = 'Test Query';
|
$testQuery = 'Test Query';
|
||||||
$testLimit = 20;
|
$testLimit = 20;
|
||||||
|
|
||||||
/** @var $typeMock \PHPUnit_Framework_MockObject_MockObject|\FOS\ElasticaBundle\Finder\TransformedFinder */
|
$finderMock = $this->getFinderMock($testQuery, $testLimit);
|
||||||
$finderMock = $this->getMockBuilder('FOS\ElasticaBundle\Finder\TransformedFinder')
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
$finderMock->expects($this->once())
|
|
||||||
->method('find')
|
|
||||||
->with($this->equalTo($testQuery), $this->equalTo($testLimit));
|
|
||||||
|
|
||||||
$repository = new Repository($finderMock);
|
$repository = new Repository($finderMock);
|
||||||
$repository->find($testQuery, $testLimit);
|
$repository->find($testQuery, $testLimit);
|
||||||
}
|
}
|
||||||
|
@ -46,14 +32,7 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$testQuery = 'Test Query';
|
$testQuery = 'Test Query';
|
||||||
|
|
||||||
/** @var $typeMock \PHPUnit_Framework_MockObject_MockObject|\FOS\ElasticaBundle\Finder\TransformedFinder */
|
$finderMock = $this->getFinderMock($testQuery, array(), 'findPaginated');
|
||||||
$finderMock = $this->getMockBuilder('FOS\ElasticaBundle\Finder\TransformedFinder')
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
$finderMock->expects($this->once())
|
|
||||||
->method('findPaginated')
|
|
||||||
->with($this->equalTo($testQuery));
|
|
||||||
|
|
||||||
$repository = new Repository($finderMock);
|
$repository = new Repository($finderMock);
|
||||||
$repository->findPaginated($testQuery);
|
$repository->findPaginated($testQuery);
|
||||||
}
|
}
|
||||||
|
@ -62,14 +41,7 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$testQuery = 'Test Query';
|
$testQuery = 'Test Query';
|
||||||
|
|
||||||
/** @var $typeMock \PHPUnit_Framework_MockObject_MockObject|\FOS\ElasticaBundle\Finder\TransformedFinder */
|
$finderMock = $this->getFinderMock($testQuery, array(), 'createPaginatorAdapter');
|
||||||
$finderMock = $this->getMockBuilder('FOS\ElasticaBundle\Finder\TransformedFinder')
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
$finderMock->expects($this->once())
|
|
||||||
->method('createPaginatorAdapter')
|
|
||||||
->with($this->equalTo($testQuery));
|
|
||||||
|
|
||||||
$repository = new Repository($finderMock);
|
$repository = new Repository($finderMock);
|
||||||
$repository->createPaginatorAdapter($testQuery);
|
$repository->createPaginatorAdapter($testQuery);
|
||||||
}
|
}
|
||||||
|
@ -77,17 +49,27 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testThatFindHybridCallsFindHybridOnFinder()
|
public function testThatFindHybridCallsFindHybridOnFinder()
|
||||||
{
|
{
|
||||||
$testQuery = 'Test Query';
|
$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')
|
$finderMock = $this->getMockBuilder('FOS\ElasticaBundle\Finder\TransformedFinder')
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
$finderMock->expects($this->once())
|
$finderMock->expects($this->once())
|
||||||
->method('findHybrid')
|
->method($method)
|
||||||
->with($this->equalTo($testQuery), $this->equalTo($testLimit));
|
->with($this->equalTo($testQuery), $this->equalTo($testLimit));
|
||||||
|
|
||||||
$repository = new Repository($finderMock);
|
return $finderMock;
|
||||||
$repository->findHybrid($testQuery, $testLimit);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ class ElasticaToModelTransformerCollectionTest extends \PHPUnit_Framework_TestCa
|
||||||
$objectClasses = $this->collection->getObjectClass();
|
$objectClasses = $this->collection->getObjectClass();
|
||||||
$this->assertEquals(array(
|
$this->assertEquals(array(
|
||||||
'type1' => 'FOS\ElasticaBundle\Tests\Transformer\POPO',
|
'type1' => 'FOS\ElasticaBundle\Tests\Transformer\POPO',
|
||||||
'type2' => 'FOS\ElasticaBundle\Tests\Transformer\POPO2'
|
'type2' => 'FOS\ElasticaBundle\Tests\Transformer\POPO2',
|
||||||
), $objectClasses);
|
), $objectClasses);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,8 +89,8 @@ class ElasticaToModelTransformerCollectionTest extends \PHPUnit_Framework_TestCa
|
||||||
|
|
||||||
$this->transformers['type1']->expects($this->once())
|
$this->transformers['type1']->expects($this->once())
|
||||||
->method('transform')
|
->method('transform')
|
||||||
->with(array($document1,$document2))
|
->with(array($document1, $document2))
|
||||||
->will($this->returnValue(array($result1,$result2)));
|
->will($this->returnValue(array($result1, $result2)));
|
||||||
|
|
||||||
$results = $this->collection->transform(array($document1, $document2));
|
$results = $this->collection->transform(array($document1, $document2));
|
||||||
|
|
||||||
|
@ -120,8 +120,8 @@ class ElasticaToModelTransformerCollectionTest extends \PHPUnit_Framework_TestCa
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
array(
|
array(
|
||||||
$result, $transformedObject
|
$result, $transformedObject,
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,8 @@ class POPO
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->date = new \DateTime('1979-05-05');
|
$this->date = new \DateTime('1979-05-05');
|
||||||
$this->file = new \SplFileInfo(__DIR__ . '/../fixtures/attachment.odt');
|
$this->file = new \SplFileInfo(__DIR__.'/../fixtures/attachment.odt');
|
||||||
$this->fileContents = file_get_contents(__DIR__ . '/../fixtures/attachment.odt');
|
$this->fileContents = file_get_contents(__DIR__.'/../fixtures/attachment.odt');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getId()
|
public function getId()
|
||||||
|
@ -47,7 +47,7 @@ class POPO
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'key1' => 'value1',
|
'key1' => 'value1',
|
||||||
'key2' => 'value2'
|
'key2' => 'value2',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ class POPO
|
||||||
|
|
||||||
public function getNestedObject()
|
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()
|
public function getUpper()
|
||||||
|
@ -152,7 +152,7 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
||||||
'float' => array(),
|
'float' => array(),
|
||||||
'bool' => array(),
|
'bool' => array(),
|
||||||
'date' => array(),
|
'date' => array(),
|
||||||
'falseBool' => array()
|
'falseBool' => array(),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$data = $document->getData();
|
$data = $document->getData();
|
||||||
|
@ -185,7 +185,7 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array(
|
array(
|
||||||
'key1' => 'value1',
|
'key1' => 'value1',
|
||||||
'key2' => 'value2'
|
'key2' => 'value2',
|
||||||
), $data['array']
|
), $data['array']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -230,7 +230,7 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
||||||
$document = $transformer->transform(new POPO(), array('file' => array('type' => 'attachment')));
|
$document = $transformer->transform(new POPO(), array('file' => array('type' => 'attachment')));
|
||||||
$data = $document->getData();
|
$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()
|
public function testFileContentsAddedForAttachmentMapping()
|
||||||
|
@ -240,7 +240,7 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
||||||
$data = $document->getData();
|
$data = $document->getData();
|
||||||
|
|
||||||
$this->assertEquals(
|
$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(
|
$document = $transformer->transform(new POPO(), array(
|
||||||
'sub' => array(
|
'sub' => array(
|
||||||
'type' => 'nested',
|
'type' => 'nested',
|
||||||
'properties' => array('foo' => '~')
|
'properties' => array('foo' => '~'),
|
||||||
)
|
),
|
||||||
));
|
));
|
||||||
$data = $document->getData();
|
$data = $document->getData();
|
||||||
|
|
||||||
|
@ -259,7 +259,7 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->assertInternalType('array', $data['sub']);
|
$this->assertInternalType('array', $data['sub']);
|
||||||
$this->assertEquals(array(
|
$this->assertEquals(array(
|
||||||
array('foo' => 'foo'),
|
array('foo' => 'foo'),
|
||||||
array('foo' => 'bar')
|
array('foo' => 'bar'),
|
||||||
), $data['sub']);
|
), $data['sub']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,8 +269,8 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
||||||
$document = $transformer->transform(new POPO(), array(
|
$document = $transformer->transform(new POPO(), array(
|
||||||
'sub' => array(
|
'sub' => array(
|
||||||
'type' => 'object',
|
'type' => 'object',
|
||||||
'properties' => array('bar')
|
'properties' => array('bar'),
|
||||||
)
|
),
|
||||||
));
|
));
|
||||||
$data = $document->getData();
|
$data = $document->getData();
|
||||||
|
|
||||||
|
@ -278,7 +278,7 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->assertInternalType('array', $data['sub']);
|
$this->assertInternalType('array', $data['sub']);
|
||||||
$this->assertEquals(array(
|
$this->assertEquals(array(
|
||||||
array('bar' => 'foo'),
|
array('bar' => 'foo'),
|
||||||
array('bar' => 'bar')
|
array('bar' => 'bar'),
|
||||||
), $data['sub']);
|
), $data['sub']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,17 +287,17 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
||||||
$transformer = $this->getTransformer();
|
$transformer = $this->getTransformer();
|
||||||
$document = $transformer->transform(new POPO(), array(
|
$document = $transformer->transform(new POPO(), array(
|
||||||
'obj' => array(
|
'obj' => array(
|
||||||
'type' => 'object'
|
'type' => 'object',
|
||||||
)
|
),
|
||||||
));
|
));
|
||||||
$data = $document->getData();
|
$data = $document->getData();
|
||||||
|
|
||||||
$this->assertTrue(array_key_exists('obj', $data));
|
$this->assertTrue(array_key_exists('obj', $data));
|
||||||
$this->assertInternalType('array', $data['obj']);
|
$this->assertInternalType('array', $data['obj']);
|
||||||
$this->assertEquals(array(
|
$this->assertEquals(array(
|
||||||
'foo' => 'foo',
|
'foo' => 'foo',
|
||||||
'bar' => 'foo',
|
'bar' => 'foo',
|
||||||
'id' => 1
|
'id' => 1,
|
||||||
), $data['obj']);
|
), $data['obj']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,14 +313,14 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
||||||
'properties' => array(
|
'properties' => array(
|
||||||
'key1sub1' => array(
|
'key1sub1' => array(
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
'properties' => array()
|
'properties' => array(),
|
||||||
),
|
),
|
||||||
'key1sub2' => array(
|
'key1sub2' => array(
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
'properties' => array()
|
'properties' => array(),
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$data = $document->getData();
|
$data = $document->getData();
|
||||||
|
@ -333,14 +333,14 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
||||||
array(
|
array(
|
||||||
'foo' => 'foo',
|
'foo' => 'foo',
|
||||||
'bar' => 'foo',
|
'bar' => 'foo',
|
||||||
'id' => 1
|
'id' => 1,
|
||||||
),
|
),
|
||||||
$data['obj']
|
$data['obj']
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array(
|
array(
|
||||||
'key1sub1' => 'value1sub1',
|
'key1sub1' => 'value1sub1',
|
||||||
'key1sub2' => 'value1sub2'
|
'key1sub2' => 'value1sub2',
|
||||||
),
|
),
|
||||||
$data['nestedObject'][0]
|
$data['nestedObject'][0]
|
||||||
);
|
);
|
||||||
|
@ -350,7 +350,7 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$transformer = $this->getTransformer();
|
$transformer = $this->getTransformer();
|
||||||
$document = $transformer->transform(new POPO(), array(
|
$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());
|
$this->assertEquals("parent", $document->getParent());
|
||||||
|
@ -360,7 +360,7 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$transformer = $this->getTransformer();
|
$transformer = $this->getTransformer();
|
||||||
$document = $transformer->transform(new POPO(), array(
|
$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());
|
$this->assertEquals("a random name", $document->getParent());
|
||||||
|
@ -370,7 +370,7 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$transformer = $this->getTransformer();
|
$transformer = $this->getTransformer();
|
||||||
$document = $transformer->transform(new POPO(), array(
|
$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());
|
$this->assertEquals("parent", $document->getParent());
|
||||||
|
@ -380,7 +380,7 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$transformer = $this->getTransformer();
|
$transformer = $this->getTransformer();
|
||||||
$document = $transformer->transform(new POPO(), array(
|
$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());
|
$this->assertEquals("parent", $document->getParent());
|
||||||
|
|
|
@ -41,6 +41,7 @@ class ElasticaToModelTransformerCollection implements ElasticaToModelTransformer
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Document[] $elasticaObjects
|
* @param Document[] $elasticaObjects
|
||||||
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function transform(array $elasticaObjects)
|
public function transform(array $elasticaObjects)
|
||||||
|
@ -51,12 +52,12 @@ class ElasticaToModelTransformerCollection implements ElasticaToModelTransformer
|
||||||
}
|
}
|
||||||
|
|
||||||
$transformed = array();
|
$transformed = array();
|
||||||
foreach ($sorted AS $type => $objects) {
|
foreach ($sorted as $type => $objects) {
|
||||||
$transformedObjects = $this->transformers[$type]->transform($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(
|
$transformed[$type] = array_combine(
|
||||||
array_map(
|
array_map(
|
||||||
function($o) use ($identifierGetter) {
|
function ($o) use ($identifierGetter) {
|
||||||
return $o->$identifierGetter();
|
return $o->$identifierGetter();
|
||||||
},
|
},
|
||||||
$transformedObjects
|
$transformedObjects
|
||||||
|
|
|
@ -3,32 +3,33 @@
|
||||||
namespace FOS\ElasticaBundle\Transformer;
|
namespace FOS\ElasticaBundle\Transformer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maps Elastica documents with model objects
|
* Maps Elastica documents with model objects.
|
||||||
*/
|
*/
|
||||||
interface ElasticaToModelTransformerInterface
|
interface ElasticaToModelTransformerInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Transforms an array of elastica objects into an array of
|
* 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
|
* @param array $elasticaObjects array of elastica objects
|
||||||
|
*
|
||||||
* @return array of model 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.
|
* Returns the object class used by the transformer.
|
||||||
*
|
*
|
||||||
* @return string
|
* @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
|
* @return string the identifier field
|
||||||
*/
|
*/
|
||||||
function getIdentifierField();
|
public function getIdentifierField();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace FOS\ElasticaBundle\Transformer;
|
namespace FOS\ElasticaBundle\Transformer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maps Elastica documents with model objects
|
* Maps Elastica documents with model objects.
|
||||||
*/
|
*/
|
||||||
interface HighlightableModelInterface
|
interface HighlightableModelInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Set ElasticSearch highlight data.
|
* Set ElasticSearch highlight data.
|
||||||
*
|
*
|
||||||
* @param array $highlights array of highlight strings
|
* @param array $highlights array of highlight strings
|
||||||
*/
|
*/
|
||||||
public function setElasticHighlights(array $highlights);
|
public function setElasticHighlights(array $highlights);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,28 +8,28 @@ use Elastica\Document;
|
||||||
/**
|
/**
|
||||||
* Maps Elastica documents with Doctrine objects
|
* Maps Elastica documents with Doctrine objects
|
||||||
* This mapper assumes an exact match between
|
* 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
|
class ModelToElasticaAutoTransformer implements ModelToElasticaTransformerInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Optional parameters
|
* Optional parameters.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $options = array(
|
protected $options = array(
|
||||||
'identifier' => 'id'
|
'identifier' => 'id',
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PropertyAccessor instance
|
* PropertyAccessor instance.
|
||||||
*
|
*
|
||||||
* @var PropertyAccessorInterface
|
* @var PropertyAccessorInterface
|
||||||
*/
|
*/
|
||||||
protected $propertyAccessor;
|
protected $propertyAccessor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instanciates a new Mapper
|
* Instanciates a new Mapper.
|
||||||
*
|
*
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*/
|
*/
|
||||||
|
@ -39,7 +39,7 @@ class ModelToElasticaAutoTransformer implements ModelToElasticaTransformerInterf
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the PropertyAccessor
|
* Set the PropertyAccessor.
|
||||||
*
|
*
|
||||||
* @param PropertyAccessorInterface $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 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
|
||||||
|
@ -63,7 +63,7 @@ class ModelToElasticaAutoTransformer implements ModelToElasticaTransformerInterf
|
||||||
|
|
||||||
foreach ($fields as $key => $mapping) {
|
foreach ($fields as $key => $mapping) {
|
||||||
if ($key == '_parent') {
|
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);
|
$value = $this->propertyAccessor->getValue($object, $property);
|
||||||
$document->setParent($this->propertyAccessor->getValue($value, $mapping['identifier']));
|
$document->setParent($this->propertyAccessor->getValue($value, $mapping['identifier']));
|
||||||
continue;
|
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|\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
|
* @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
|
* @param mixed $value
|
||||||
*
|
*
|
||||||
|
@ -131,12 +131,11 @@ class ModelToElasticaAutoTransformer implements ModelToElasticaTransformerInterf
|
||||||
*/
|
*/
|
||||||
protected function normalizeValue($value)
|
protected function normalizeValue($value)
|
||||||
{
|
{
|
||||||
$normalizeValue = function(&$v)
|
$normalizeValue = function (&$v) {
|
||||||
{
|
|
||||||
if ($v instanceof \DateTime) {
|
if ($v instanceof \DateTime) {
|
||||||
$v = $v->format('c');
|
$v = $v->format('c');
|
||||||
} elseif (!is_scalar($v) && !is_null($v)) {
|
} 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
|
* 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
|
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 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
|
||||||
|
|
|
@ -3,16 +3,17 @@
|
||||||
namespace FOS\ElasticaBundle\Transformer;
|
namespace FOS\ElasticaBundle\Transformer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maps Elastica documents with model objects
|
* Maps Elastica documents with model objects.
|
||||||
*/
|
*/
|
||||||
interface ModelToElasticaTransformerInterface
|
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 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
|
* @return \Elastica\Document
|
||||||
**/
|
**/
|
||||||
function transform($object, array $fields);
|
public function transform($object, array $fields);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue