CS fixes
This commit is contained in:
parent
cf9f7c6be8
commit
dd388e4b25
|
@ -13,7 +13,7 @@ use FOS\ElasticaBundle\Resetter;
|
|||
use FOS\ElasticaBundle\Provider\ProviderInterface;
|
||||
|
||||
/**
|
||||
* Populate the search index
|
||||
* Populate the search index.
|
||||
*/
|
||||
class PopulateCommand extends ContainerAwareCommand
|
||||
{
|
||||
|
|
|
@ -10,7 +10,7 @@ use FOS\ElasticaBundle\IndexManager;
|
|||
use FOS\ElasticaBundle\Resetter;
|
||||
|
||||
/**
|
||||
* Reset search indexes
|
||||
* Reset search indexes.
|
||||
*/
|
||||
class ResetCommand extends ContainerAwareCommand
|
||||
{
|
||||
|
|
|
@ -11,7 +11,7 @@ use Elastica\Query;
|
|||
use Elastica\Result;
|
||||
|
||||
/**
|
||||
* Searches a type
|
||||
* Searches a type.
|
||||
*/
|
||||
class SearchCommand extends ContainerAwareCommand
|
||||
{
|
||||
|
|
|
@ -92,7 +92,9 @@ class IndexConfig
|
|||
|
||||
/**
|
||||
* @param string $typeName
|
||||
*
|
||||
* @return TypeConfig
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function getType($typeName)
|
||||
|
|
|
@ -20,6 +20,7 @@ interface ManagerInterface
|
|||
* Returns configuration for an index.
|
||||
*
|
||||
* @param $index
|
||||
*
|
||||
* @return IndexConfig
|
||||
*/
|
||||
public function getIndexConfiguration($index);
|
||||
|
@ -36,6 +37,7 @@ interface ManagerInterface
|
|||
*
|
||||
* @param string $index
|
||||
* @param string $type
|
||||
*
|
||||
* @return TypeConfig
|
||||
*/
|
||||
public function getTypeConfiguration($index, $type);
|
||||
|
|
|
@ -17,6 +17,7 @@ use FOS\ElasticaBundle\Annotation\Search as BaseSearch;
|
|||
* Annotation class for setting search repository.
|
||||
*
|
||||
* @Annotation
|
||||
*
|
||||
* @deprecated Use FOS\ElasticaBundle\Annotation\Search instead
|
||||
* @Target("CLASS")
|
||||
*/
|
||||
|
|
|
@ -57,6 +57,7 @@ class ContainerSource implements SourceInterface
|
|||
* Builds TypeConfig objects for each type.
|
||||
*
|
||||
* @param array $config
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getTypes($config)
|
||||
|
|
|
@ -55,6 +55,7 @@ class RegisterProvidersPass implements CompilerPassInterface
|
|||
* Returns whether the class implements ProviderInterface.
|
||||
*
|
||||
* @param string $class
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private function isProviderImplementation($class)
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
@ -99,7 +99,7 @@ class Configuration implements ConfigurationInterface
|
|||
->ifTrue(function ($v) { return is_array($v) && !array_key_exists('connections', $v); })
|
||||
->then(function ($v) {
|
||||
return array(
|
||||
'connections' => array($v)
|
||||
'connections' => array($v),
|
||||
);
|
||||
})
|
||||
->end()
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -419,7 +419,7 @@ class Configuration implements ConfigurationInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the array node used for "_all"
|
||||
* Returns the array node used for "_all".
|
||||
*/
|
||||
protected function getAllNode()
|
||||
{
|
||||
|
@ -438,7 +438,7 @@ class Configuration implements ConfigurationInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the array node used for "_timestamp"
|
||||
* Returns the array node used for "_timestamp".
|
||||
*/
|
||||
protected function getTimestampNode()
|
||||
{
|
||||
|
@ -459,7 +459,7 @@ class Configuration implements ConfigurationInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the array node used for "_ttl"
|
||||
* Returns the array node used for "_ttl".
|
||||
*/
|
||||
protected function getTtlNode()
|
||||
{
|
||||
|
|
|
@ -82,6 +82,7 @@ class FOSElasticaExtension extends Extension
|
|||
/**
|
||||
* @param array $config
|
||||
* @param ContainerBuilder $container
|
||||
*
|
||||
* @return Configuration
|
||||
*/
|
||||
public function getConfiguration(array $config, ContainerBuilder $container)
|
||||
|
@ -94,6 +95,7 @@ class FOSElasticaExtension extends Extension
|
|||
*
|
||||
* @param array $clients An array of clients configurations
|
||||
* @param ContainerBuilder $container A ContainerBuilder instance
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function loadClients(array $clients, ContainerBuilder $container)
|
||||
|
@ -114,7 +116,7 @@ class FOSElasticaExtension extends Extension
|
|||
|
||||
$this->clients[$name] = array(
|
||||
'id' => $clientId,
|
||||
'reference' => new Reference($clientId)
|
||||
'reference' => new Reference($clientId),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -124,7 +126,9 @@ class FOSElasticaExtension extends Extension
|
|||
*
|
||||
* @param array $indexes An array of indexes configurations
|
||||
* @param ContainerBuilder $container A ContainerBuilder instance
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function loadIndexes(array $indexes, ContainerBuilder $container)
|
||||
|
@ -175,6 +179,7 @@ class FOSElasticaExtension extends Extension
|
|||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
||||
* @param string $name The index name
|
||||
* @param Reference $index Reference to the related index
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function loadIndexFinder(ContainerBuilder $container, $name, Reference $index)
|
||||
|
@ -277,7 +282,7 @@ 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 ContainerBuilder $container
|
||||
|
@ -311,6 +316,7 @@ class FOSElasticaExtension extends Extension
|
|||
* @param ContainerBuilder $container
|
||||
* @param string $indexName
|
||||
* @param string $typeName
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function loadElasticaToModelTransformer(array $typeConfig, ContainerBuilder $container, $indexName, $typeName)
|
||||
|
@ -346,6 +352,7 @@ class FOSElasticaExtension extends Extension
|
|||
* @param ContainerBuilder $container
|
||||
* @param string $indexName
|
||||
* @param string $typeName
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function loadModelToElasticaTransformer(array $typeConfig, ContainerBuilder $container, $indexName, $typeName)
|
||||
|
@ -361,7 +368,7 @@ class FOSElasticaExtension extends Extension
|
|||
$serviceId = sprintf('fos_elastica.model_to_elastica_transformer.%s.%s', $indexName, $typeName);
|
||||
$serviceDef = new DefinitionDecorator($abstractId);
|
||||
$serviceDef->replaceArgument(0, array(
|
||||
'identifier' => $typeConfig['identifier']
|
||||
'identifier' => $typeConfig['identifier'],
|
||||
));
|
||||
$container->setDefinition($serviceId, $serviceDef);
|
||||
|
||||
|
@ -377,6 +384,7 @@ class FOSElasticaExtension extends Extension
|
|||
* @param string $indexName
|
||||
* @param string $typeName
|
||||
* @param string $transformerId
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function loadObjectPersister(array $typeConfig, Reference $typeRef, ContainerBuilder $container, $indexName, $typeName, $transformerId)
|
||||
|
@ -420,6 +428,7 @@ class FOSElasticaExtension extends Extension
|
|||
* @param string $objectPersisterId
|
||||
* @param string $indexName
|
||||
* @param string $typeName
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function loadTypeProvider(array $typeConfig, ContainerBuilder $container, $objectPersisterId, $indexName, $typeName)
|
||||
|
@ -454,6 +463,7 @@ class FOSElasticaExtension extends Extension
|
|||
* @param string $objectPersisterId
|
||||
* @param string $indexName
|
||||
* @param string $typeName
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function loadTypeListener(array $typeConfig, ContainerBuilder $container, $objectPersisterId, $indexName, $typeName)
|
||||
|
@ -490,7 +500,7 @@ class FOSElasticaExtension extends Extension
|
|||
}
|
||||
|
||||
/**
|
||||
* Map Elastica to Doctrine events for the current driver
|
||||
* Map Elastica to Doctrine events for the current driver.
|
||||
*/
|
||||
private function getDoctrineEvents(array $typeConfig)
|
||||
{
|
||||
|
@ -511,7 +521,7 @@ class FOSElasticaExtension extends Extension
|
|||
'insert' => array(constant($eventsClass.'::postPersist')),
|
||||
'update' => array(constant($eventsClass.'::postUpdate')),
|
||||
'delete' => array(constant($eventsClass.'::preRemove')),
|
||||
'flush' => array($typeConfig['listener']['immediate'] ? constant($eventsClass.'::preFlush') : constant($eventsClass.'::postFlush'))
|
||||
'flush' => array($typeConfig['listener']['immediate'] ? constant($eventsClass.'::preFlush') : constant($eventsClass.'::postFlush')),
|
||||
);
|
||||
|
||||
foreach ($eventMapping as $event => $doctrineEvents) {
|
||||
|
@ -532,6 +542,7 @@ class FOSElasticaExtension extends Extension
|
|||
* @param Reference $typeRef
|
||||
* @param string $indexName
|
||||
* @param string $typeName
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function loadTypeFinder(array $typeConfig, ContainerBuilder $container, $elasticaToModelId, Reference $typeRef, $indexName, $typeName)
|
||||
|
@ -558,7 +569,7 @@ class FOSElasticaExtension extends Extension
|
|||
}
|
||||
|
||||
/**
|
||||
* Loads the index manager
|
||||
* Loads the index manager.
|
||||
*
|
||||
* @param ContainerBuilder $container
|
||||
**/
|
||||
|
@ -635,7 +646,9 @@ class FOSElasticaExtension extends Extension
|
|||
* Returns a reference to a client given its configured name.
|
||||
*
|
||||
* @param string $clientName
|
||||
*
|
||||
* @return Reference
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
private function getClient($clientName)
|
||||
|
|
|
@ -10,24 +10,24 @@ use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
|
|||
/**
|
||||
* Maps Elastica documents with Doctrine objects
|
||||
* This mapper assumes an exact match between
|
||||
* elastica documents ids and doctrine object ids
|
||||
* elastica documents ids and doctrine object ids.
|
||||
*/
|
||||
abstract class AbstractElasticaToModelTransformer implements ElasticaToModelTransformerInterface
|
||||
{
|
||||
/**
|
||||
* Manager registry
|
||||
* Manager registry.
|
||||
*/
|
||||
protected $registry = null;
|
||||
|
||||
/**
|
||||
* Class of the model to map to the elastica documents
|
||||
* Class of the model to map to the elastica documents.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $objectClass = null;
|
||||
|
||||
/**
|
||||
* Optional parameters
|
||||
* Optional parameters.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
|
@ -39,14 +39,14 @@ abstract class AbstractElasticaToModelTransformer implements ElasticaToModelTran
|
|||
);
|
||||
|
||||
/**
|
||||
* PropertyAccessor instance
|
||||
* PropertyAccessor instance.
|
||||
*
|
||||
* @var PropertyAccessorInterface
|
||||
*/
|
||||
protected $propertyAccessor;
|
||||
|
||||
/**
|
||||
* Instantiates a new Mapper
|
||||
* Instantiates a new Mapper.
|
||||
*
|
||||
* @param object $registry
|
||||
* @param string $objectClass
|
||||
|
@ -70,7 +70,7 @@ abstract class AbstractElasticaToModelTransformer implements ElasticaToModelTran
|
|||
}
|
||||
|
||||
/**
|
||||
* Set the PropertyAccessor
|
||||
* Set the PropertyAccessor.
|
||||
*
|
||||
* @param PropertyAccessorInterface $propertyAccessor
|
||||
*/
|
||||
|
@ -81,10 +81,12 @@ abstract class AbstractElasticaToModelTransformer implements ElasticaToModelTran
|
|||
|
||||
/**
|
||||
* Transforms an array of elastica objects into an array of
|
||||
* model objects fetched from the doctrine repository
|
||||
* model objects fetched from the doctrine repository.
|
||||
*
|
||||
* @param array $elasticaObjects of elastica objects
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
*
|
||||
* @return array
|
||||
**/
|
||||
public function transform(array $elasticaObjects)
|
||||
|
@ -110,8 +112,7 @@ abstract class AbstractElasticaToModelTransformer implements ElasticaToModelTran
|
|||
$idPos = array_flip($ids);
|
||||
$identifier = $this->options['identifier'];
|
||||
$propertyAccessor = $this->propertyAccessor;
|
||||
usort($objects, function($a, $b) use ($idPos, $identifier, $propertyAccessor)
|
||||
{
|
||||
usort($objects, function ($a, $b) use ($idPos, $identifier, $propertyAccessor) {
|
||||
return $idPos[$propertyAccessor->getValue($a, $identifier)] > $idPos[$propertyAccessor->getValue($b, $identifier)];
|
||||
});
|
||||
|
||||
|
@ -145,11 +146,12 @@ abstract class AbstractElasticaToModelTransformer implements ElasticaToModelTran
|
|||
}
|
||||
|
||||
/**
|
||||
* Fetches objects by theses identifier values
|
||||
* Fetches objects by theses identifier values.
|
||||
*
|
||||
* @param array $identifierValues ids values
|
||||
* @param Boolean $hydrate whether or not to hydrate the objects, false returns arrays
|
||||
*
|
||||
* @return array of objects or arrays
|
||||
*/
|
||||
protected abstract function findByIdentifiers(array $identifierValues, $hydrate);
|
||||
abstract protected function findByIdentifiers(array $identifierValues, $hydrate);
|
||||
}
|
||||
|
|
|
@ -112,24 +112,26 @@ abstract class AbstractProvider extends BaseAbstractProvider
|
|||
* Counts objects that would be indexed using the query builder.
|
||||
*
|
||||
* @param object $queryBuilder
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
protected abstract function countObjects($queryBuilder);
|
||||
abstract protected function countObjects($queryBuilder);
|
||||
|
||||
/**
|
||||
* Disables logging and returns the logger that was previously set.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected abstract function disableLogging();
|
||||
abstract protected function disableLogging();
|
||||
|
||||
/**
|
||||
* Reenables the logger with the previously returned logger from disableLogging();
|
||||
* Reenables the logger with the previously returned logger from disableLogging();.
|
||||
*
|
||||
* @param mixed $logger
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected abstract function enableLogging($logger);
|
||||
abstract protected function enableLogging($logger);
|
||||
|
||||
/**
|
||||
* Fetches a slice of objects using the query builder.
|
||||
|
@ -137,14 +139,15 @@ abstract class AbstractProvider extends BaseAbstractProvider
|
|||
* @param object $queryBuilder
|
||||
* @param integer $limit
|
||||
* @param integer $offset
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected abstract function fetchSlice($queryBuilder, $limit, $offset);
|
||||
abstract protected function fetchSlice($queryBuilder, $limit, $offset);
|
||||
|
||||
/**
|
||||
* Creates the query builder, which will be used to fetch objects to index.
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
protected abstract function createQueryBuilder();
|
||||
abstract protected function createQueryBuilder();
|
||||
}
|
||||
|
|
|
@ -17,39 +17,39 @@ use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
|
|||
class Listener implements EventSubscriber
|
||||
{
|
||||
/**
|
||||
* Object persister
|
||||
* Object persister.
|
||||
*
|
||||
* @var ObjectPersister
|
||||
*/
|
||||
protected $objectPersister;
|
||||
|
||||
/**
|
||||
* List of subscribed events
|
||||
* List of subscribed events.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $events;
|
||||
|
||||
/**
|
||||
* Configuration for the listener
|
||||
* Configuration for the listener.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* Objects scheduled for insertion and replacement
|
||||
* Objects scheduled for insertion and replacement.
|
||||
*/
|
||||
public $scheduledForInsertion = array();
|
||||
public $scheduledForUpdate = array();
|
||||
|
||||
/**
|
||||
* IDs of objects scheduled for removal
|
||||
* IDs of objects scheduled for removal.
|
||||
*/
|
||||
public $scheduledForDeletion = array();
|
||||
|
||||
/**
|
||||
* PropertyAccessor instance
|
||||
* PropertyAccessor instance.
|
||||
*
|
||||
* @var PropertyAccessorInterface
|
||||
*/
|
||||
|
@ -98,10 +98,12 @@ class Listener implements EventSubscriber
|
|||
}
|
||||
|
||||
/**
|
||||
* Provides unified method for retrieving a doctrine object from an EventArgs instance
|
||||
* Provides unified method for retrieving a doctrine object from an EventArgs instance.
|
||||
*
|
||||
* @param EventArgs $eventArgs
|
||||
*
|
||||
* @return object Entity | Document
|
||||
*
|
||||
* @throws \RuntimeException if no valid getter is found.
|
||||
*/
|
||||
private function getDoctrineObject(EventArgs $eventArgs)
|
||||
|
@ -142,7 +144,7 @@ class Listener implements EventSubscriber
|
|||
|
||||
/**
|
||||
* Delete objects preRemove instead of postRemove so that we have access to the id. Because this is called
|
||||
* preRemove, first check that the entity is managed by Doctrine
|
||||
* preRemove, first check that the entity is managed by Doctrine.
|
||||
*/
|
||||
public function preRemove(EventArgs $eventArgs)
|
||||
{
|
||||
|
@ -155,7 +157,7 @@ class Listener implements EventSubscriber
|
|||
|
||||
/**
|
||||
* Persist scheduled objects to ElasticSearch
|
||||
* After persisting, clear the scheduled queue to prevent multiple data updates when using multiple flush calls
|
||||
* After persisting, clear the scheduled queue to prevent multiple data updates when using multiple flush calls.
|
||||
*/
|
||||
private function persistScheduled()
|
||||
{
|
||||
|
@ -210,6 +212,7 @@ class Listener implements EventSubscriber
|
|||
* Checks if the object is indexable or not.
|
||||
*
|
||||
* @param object $object
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isObjectIndexable($object)
|
||||
|
|
|
@ -7,15 +7,16 @@ use FOS\ElasticaBundle\Doctrine\AbstractElasticaToModelTransformer;
|
|||
/**
|
||||
* Maps Elastica documents with Doctrine objects
|
||||
* This mapper assumes an exact match between
|
||||
* elastica documents ids and doctrine object ids
|
||||
* elastica documents ids and doctrine object ids.
|
||||
*/
|
||||
class ElasticaToModelTransformer extends AbstractElasticaToModelTransformer
|
||||
{
|
||||
/**
|
||||
* Fetch objects for theses identifier values
|
||||
* Fetch objects for theses identifier values.
|
||||
*
|
||||
* @param array $identifierValues ids values
|
||||
* @param Boolean $hydrate whether or not to hydrate the objects, false returns arrays
|
||||
*
|
||||
* @return array of objects or arrays
|
||||
*/
|
||||
protected function findByIdentifiers(array $identifierValues, $hydrate)
|
||||
|
|
|
@ -27,9 +27,10 @@ class Provider extends AbstractProvider
|
|||
}
|
||||
|
||||
/**
|
||||
* Reenables the logger with the previously returned logger from disableLogging();
|
||||
* Reenables the logger with the previously returned logger from disableLogging();.
|
||||
*
|
||||
* @param mixed $logger
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function enableLogging($logger)
|
||||
|
|
|
@ -8,17 +8,18 @@ use Doctrine\ORM\Query;
|
|||
/**
|
||||
* Maps Elastica documents with Doctrine objects
|
||||
* This mapper assumes an exact match between
|
||||
* elastica documents ids and doctrine object ids
|
||||
* elastica documents ids and doctrine object ids.
|
||||
*/
|
||||
class ElasticaToModelTransformer extends AbstractElasticaToModelTransformer
|
||||
{
|
||||
const ENTITY_ALIAS = 'o';
|
||||
|
||||
/**
|
||||
* Fetch objects for theses identifier values
|
||||
* Fetch objects for theses identifier values.
|
||||
*
|
||||
* @param array $identifierValues ids values
|
||||
* @param Boolean $hydrate whether or not to hydrate the objects, false returns arrays
|
||||
*
|
||||
* @return array of objects or arrays
|
||||
*/
|
||||
protected function findByIdentifiers(array $identifierValues, $hydrate)
|
||||
|
@ -36,7 +37,7 @@ class ElasticaToModelTransformer extends AbstractElasticaToModelTransformer
|
|||
}
|
||||
|
||||
/**
|
||||
* Retrieves a query builder to be used for querying by identifiers
|
||||
* Retrieves a query builder to be used for querying by identifiers.
|
||||
*
|
||||
* @return \Doctrine\ORM\QueryBuilder
|
||||
*/
|
||||
|
|
|
@ -29,9 +29,10 @@ class Provider extends AbstractProvider
|
|||
}
|
||||
|
||||
/**
|
||||
* Reenables the logger with the previously returned logger from disableLogging();
|
||||
* Reenables the logger with the previously returned logger from disableLogging();.
|
||||
*
|
||||
* @param mixed $logger
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function enableLogging($logger)
|
||||
|
@ -76,7 +77,7 @@ class Provider extends AbstractProvider
|
|||
throw new InvalidArgumentTypeException($queryBuilder, 'Doctrine\ORM\QueryBuilder');
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* An orderBy DQL part is required to avoid feching the same row twice.
|
||||
* @see http://stackoverflow.com/questions/6314879/does-limit-offset-length-require-order-by-for-pagination
|
||||
* @see http://www.postgresql.org/docs/current/static/queries-limit.html
|
||||
|
|
|
@ -25,7 +25,7 @@ class RepositoryManager extends BaseManager
|
|||
}
|
||||
|
||||
/**
|
||||
* Return repository for entity
|
||||
* Return repository for entity.
|
||||
*
|
||||
* Returns custom repository if one specified otherwise
|
||||
* returns a basic repository.
|
||||
|
|
|
@ -23,7 +23,7 @@ class Client extends BaseClient
|
|||
private $indexCache = array();
|
||||
|
||||
/**
|
||||
* Symfony's debugging Stopwatch
|
||||
* Symfony's debugging Stopwatch.
|
||||
*
|
||||
* @var Stopwatch|null
|
||||
*/
|
||||
|
@ -34,6 +34,7 @@ class Client extends BaseClient
|
|||
* @param string $method
|
||||
* @param array $data
|
||||
* @param array $query
|
||||
*
|
||||
* @return \Elastica\Response
|
||||
*/
|
||||
public function request($path, $method = Request::GET, $data = array(), array $query = array())
|
||||
|
|
|
@ -44,14 +44,12 @@ class Index extends BaseIndex
|
|||
}
|
||||
|
||||
/**
|
||||
* Reassign index name
|
||||
* Reassign index name.
|
||||
*
|
||||
* While it's technically a regular setter for name property, it's specifically named overrideName, but not setName
|
||||
* since it's used for a very specific case and normally should not be used
|
||||
*
|
||||
* @param string $name Index name
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function overrideName($name)
|
||||
{
|
||||
|
|
|
@ -9,4 +9,3 @@ class AliasIsIndexException extends \Exception
|
|||
parent::__construct(sprintf('Expected alias %s instead of index', $indexName));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ use Symfony\Component\HttpKernel\Bundle\Bundle;
|
|||
|
||||
/**
|
||||
* Bundle.
|
||||
*
|
||||
*/
|
||||
class FOSElasticaBundle extends Bundle
|
||||
{
|
||||
|
|
|
@ -5,12 +5,13 @@ namespace FOS\ElasticaBundle\Finder;
|
|||
interface FinderInterface
|
||||
{
|
||||
/**
|
||||
* Searches for query results within a given limit
|
||||
* Searches for query results within a given limit.
|
||||
*
|
||||
* @param mixed $query Can be a string, an array or an \Elastica\Query object
|
||||
* @param int $limit How many results to get
|
||||
* @param array $options
|
||||
*
|
||||
* @return array results
|
||||
*/
|
||||
function find($query, $limit = null, $options = array());
|
||||
public function find($query, $limit = null, $options = array());
|
||||
}
|
||||
|
|
|
@ -9,20 +9,22 @@ use Elastica\Query;
|
|||
interface PaginatedFinderInterface extends FinderInterface
|
||||
{
|
||||
/**
|
||||
* Searches for query results and returns them wrapped in a paginator
|
||||
* Searches for query results and returns them wrapped in a paginator.
|
||||
*
|
||||
* @param mixed $query Can be a string, an array or an \Elastica\Query object
|
||||
* @param array $options
|
||||
*
|
||||
* @return Pagerfanta paginated results
|
||||
*/
|
||||
function findPaginated($query, $options = array());
|
||||
public function findPaginated($query, $options = array());
|
||||
|
||||
/**
|
||||
* Creates a paginator adapter for this query
|
||||
* Creates a paginator adapter for this query.
|
||||
*
|
||||
* @param mixed $query
|
||||
* @param array $options
|
||||
*
|
||||
* @return PaginatorAdapterInterface
|
||||
*/
|
||||
function createPaginatorAdapter($query, $options = array());
|
||||
public function createPaginatorAdapter($query, $options = array());
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ use Elastica\SearchableInterface;
|
|||
use Elastica\Query;
|
||||
|
||||
/**
|
||||
* Finds elastica documents and map them to persisted objects
|
||||
* Finds elastica documents and map them to persisted objects.
|
||||
*/
|
||||
class TransformedFinder implements PaginatedFinderInterface
|
||||
{
|
||||
|
@ -25,11 +25,12 @@ class TransformedFinder implements PaginatedFinderInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Search for a query string
|
||||
* Search for a query string.
|
||||
*
|
||||
* @param string $query
|
||||
* @param integer $limit
|
||||
* @param array $options
|
||||
*
|
||||
* @return array of model objects
|
||||
**/
|
||||
public function find($query, $limit = null, $options = array())
|
||||
|
@ -52,6 +53,7 @@ class TransformedFinder implements PaginatedFinderInterface
|
|||
* @param integer $id
|
||||
* @param array $params
|
||||
* @param array $query
|
||||
*
|
||||
* @return array of model objects
|
||||
**/
|
||||
public function moreLikeThis($id, $params = array(), $query = array())
|
||||
|
@ -66,6 +68,7 @@ class TransformedFinder implements PaginatedFinderInterface
|
|||
* @param $query
|
||||
* @param null|int $limit
|
||||
* @param array $options
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function search($query, $limit = null, $options = array())
|
||||
|
@ -80,10 +83,11 @@ class TransformedFinder implements PaginatedFinderInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets a paginator wrapping the result of a search
|
||||
* Gets a paginator wrapping the result of a search.
|
||||
*
|
||||
* @param string $query
|
||||
* @param array $options
|
||||
*
|
||||
* @return Pagerfanta
|
||||
*/
|
||||
public function findPaginated($query, $options = array())
|
||||
|
|
|
@ -40,6 +40,7 @@ class AliasProcessor
|
|||
* @param IndexConfig $indexConfig
|
||||
* @param Index $index
|
||||
* @param bool $force
|
||||
*
|
||||
* @throws AliasIsIndexException
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
|
@ -68,7 +69,7 @@ class AliasProcessor
|
|||
'Alias %s is used for multiple indexes: [%s].
|
||||
Make sure it\'s either not used or is assigned to one index only',
|
||||
$aliasName,
|
||||
join(', ', $aliasedIndexes)
|
||||
implode(', ', $aliasedIndexes)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -78,13 +79,13 @@ class AliasProcessor
|
|||
// if the alias is set - add an action to remove it
|
||||
$oldIndexName = $aliasedIndexes[0];
|
||||
$aliasUpdateRequest['actions'][] = array(
|
||||
'remove' => array('index' => $oldIndexName, 'alias' => $aliasName)
|
||||
'remove' => array('index' => $oldIndexName, 'alias' => $aliasName),
|
||||
);
|
||||
}
|
||||
|
||||
// add an action to point the alias to the new index
|
||||
$aliasUpdateRequest['actions'][] = array(
|
||||
'add' => array('index' => $newIndexName, 'alias' => $aliasName)
|
||||
'add' => array('index' => $newIndexName, 'alias' => $aliasName),
|
||||
);
|
||||
|
||||
try {
|
||||
|
@ -129,11 +130,13 @@ class AliasProcessor
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns array of indexes which are mapped to given alias
|
||||
* Returns array of indexes which are mapped to given alias.
|
||||
*
|
||||
* @param Client $client
|
||||
* @param string $aliasName Alias name
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws AliasIsIndexException
|
||||
*/
|
||||
private function getAliasedIndexes(Client $client, $aliasName)
|
||||
|
@ -159,7 +162,7 @@ class AliasProcessor
|
|||
}
|
||||
|
||||
/**
|
||||
* Delete an index
|
||||
* Delete an index.
|
||||
*
|
||||
* @param Client $client
|
||||
* @param string $indexName Index name to delete
|
||||
|
|
|
@ -22,7 +22,7 @@ class IndexManager
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets all registered indexes
|
||||
* Gets all registered indexes.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
@ -32,10 +32,12 @@ class IndexManager
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets an index by its name
|
||||
* Gets an index by its name.
|
||||
*
|
||||
* @param string $name Index to return, or the default index if null
|
||||
*
|
||||
* @return Index
|
||||
*
|
||||
* @throws \InvalidArgumentException if no index exists for the given name
|
||||
*/
|
||||
public function getIndex($name = null)
|
||||
|
@ -52,7 +54,7 @@ class IndexManager
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets the default index
|
||||
* Gets the default index.
|
||||
*
|
||||
* @return Index
|
||||
*/
|
||||
|
|
|
@ -27,6 +27,7 @@ class MappingBuilder
|
|||
* Builds mappings for an entire index.
|
||||
*
|
||||
* @param IndexConfig $indexConfig
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function buildIndexMapping(IndexConfig $indexConfig)
|
||||
|
@ -54,6 +55,7 @@ class MappingBuilder
|
|||
* Builds mappings for a single type.
|
||||
*
|
||||
* @param TypeConfig $typeConfig
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function buildTypeMapping(TypeConfig $typeConfig)
|
||||
|
@ -89,7 +91,7 @@ class MappingBuilder
|
|||
|
||||
if (!$mapping) {
|
||||
// Empty mapping, we want it encoded as a {} instead of a []
|
||||
$mapping = new \stdClass;
|
||||
$mapping = new \stdClass();
|
||||
}
|
||||
|
||||
return $mapping;
|
||||
|
|
|
@ -8,7 +8,7 @@ use Elastica\Type\Mapping;
|
|||
use FOS\ElasticaBundle\Configuration\ConfigManager;
|
||||
|
||||
/**
|
||||
* Deletes and recreates indexes
|
||||
* Deletes and recreates indexes.
|
||||
*/
|
||||
class Resetter
|
||||
{
|
||||
|
@ -41,7 +41,7 @@ class Resetter
|
|||
}
|
||||
|
||||
/**
|
||||
* Deletes and recreates all indexes
|
||||
* Deletes and recreates all indexes.
|
||||
*/
|
||||
public function resetAllIndexes($populating = false, $force = false)
|
||||
{
|
||||
|
@ -57,6 +57,7 @@ class Resetter
|
|||
* @param string $indexName
|
||||
* @param bool $populating
|
||||
* @param bool $force If index exists with same name as alias, remove it
|
||||
*
|
||||
* @throws \InvalidArgumentException if no index exists for the given name
|
||||
*/
|
||||
public function resetIndex($indexName, $populating = false, $force = false)
|
||||
|
@ -77,10 +78,11 @@ class Resetter
|
|||
}
|
||||
|
||||
/**
|
||||
* Deletes and recreates a mapping type for the named index
|
||||
* Deletes and recreates a mapping type for the named index.
|
||||
*
|
||||
* @param string $indexName
|
||||
* @param string $typeName
|
||||
*
|
||||
* @throws \InvalidArgumentException if no index or type mapping exists for the given names
|
||||
* @throws ResponseException
|
||||
*/
|
||||
|
@ -97,7 +99,7 @@ class Resetter
|
|||
}
|
||||
}
|
||||
|
||||
$mapping = new Mapping;
|
||||
$mapping = new Mapping();
|
||||
foreach ($this->mappingBuilder->buildTypeMapping($typeConfig) as $name => $field) {
|
||||
$mapping->setParam($name, $field);
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ class RepositoryManager implements RepositoryManagerInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Return repository for entity
|
||||
* Return repository for entity.
|
||||
*
|
||||
* Returns custom repository if one specified otherwise
|
||||
* returns a basic repository.
|
||||
|
@ -63,6 +63,7 @@ class RepositoryManager implements RepositoryManagerInterface
|
|||
if ($annotation) {
|
||||
$this->entities[$entityName]['repositoryName']
|
||||
= $annotation->repositoryClass;
|
||||
|
||||
return $annotation->repositoryClass;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ use FOS\ElasticaBundle\Finder\FinderInterface;
|
|||
*/
|
||||
interface RepositoryManagerInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Adds entity name and its finder.
|
||||
* Custom repository class name can also be added.
|
||||
|
@ -24,7 +23,7 @@ interface RepositoryManagerInterface
|
|||
public function addEntity($entityName, FinderInterface $finder, $repositoryName = null);
|
||||
|
||||
/**
|
||||
* Return repository for entity
|
||||
* Return repository for entity.
|
||||
*
|
||||
* Returns custom repository if one specified otherwise
|
||||
* returns a basic repository.
|
||||
|
|
|
@ -29,7 +29,7 @@ class FantaPaginatorAdapter implements AdapterInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns Facets
|
||||
* Returns Facets.
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
|
|
|
@ -11,7 +11,7 @@ interface PaginatorAdapterInterface
|
|||
*
|
||||
* @api
|
||||
*/
|
||||
function getTotalHits();
|
||||
public function getTotalHits();
|
||||
|
||||
/**
|
||||
* Returns an slice of the results.
|
||||
|
@ -23,12 +23,12 @@ interface PaginatorAdapterInterface
|
|||
*
|
||||
* @api
|
||||
*/
|
||||
function getResults($offset, $length);
|
||||
public function getResults($offset, $length);
|
||||
|
||||
/**
|
||||
* Returns Facets
|
||||
* Returns Facets.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function getFacets();
|
||||
public function getFacets();
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ interface PartialResultsInterface
|
|||
*
|
||||
* @api
|
||||
*/
|
||||
function toArray();
|
||||
public function toArray();
|
||||
|
||||
/**
|
||||
* Returns the number of results.
|
||||
|
@ -20,12 +20,12 @@ interface PartialResultsInterface
|
|||
*
|
||||
* @api
|
||||
*/
|
||||
function getTotalHits();
|
||||
public function getTotalHits();
|
||||
|
||||
/**
|
||||
* Returns the facets
|
||||
* Returns the facets.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function getFacets();
|
||||
public function getFacets();
|
||||
}
|
|
@ -8,7 +8,7 @@ use Elastica\ResultSet;
|
|||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Allows pagination of Elastica\Query. Does not map results
|
||||
* Allows pagination of Elastica\Query. Does not map results.
|
||||
*/
|
||||
class RawPaginatorAdapter implements PaginatorAdapterInterface
|
||||
{
|
||||
|
@ -56,7 +56,9 @@ class RawPaginatorAdapter implements PaginatorAdapterInterface
|
|||
*
|
||||
* @param integer $offset
|
||||
* @param integer $itemCountPerPage
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return ResultSet
|
||||
*/
|
||||
protected function getElasticaResults($offset, $itemCountPerPage)
|
||||
|
@ -82,6 +84,7 @@ class RawPaginatorAdapter implements PaginatorAdapterInterface
|
|||
$resultSet = $this->searchable->search($query, $this->options);
|
||||
$this->totalHits = $resultSet->getTotalHits();
|
||||
$this->facets = $resultSet->getFacets();
|
||||
|
||||
return $resultSet;
|
||||
}
|
||||
|
||||
|
@ -90,6 +93,7 @@ class RawPaginatorAdapter implements PaginatorAdapterInterface
|
|||
*
|
||||
* @param int $offset
|
||||
* @param int $itemCountPerPage
|
||||
*
|
||||
* @return PartialResultsInterface
|
||||
*/
|
||||
public function getResults($offset, $itemCountPerPage)
|
||||
|
@ -114,7 +118,7 @@ class RawPaginatorAdapter implements PaginatorAdapterInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns Facets
|
||||
* Returns Facets.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
|
@ -128,7 +132,7 @@ class RawPaginatorAdapter implements PaginatorAdapterInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the Query
|
||||
* Returns the Query.
|
||||
*
|
||||
* @return Query the search query
|
||||
*/
|
||||
|
|
|
@ -6,7 +6,7 @@ use Elastica\ResultSet;
|
|||
use Elastica\Result;
|
||||
|
||||
/**
|
||||
* Raw partial results transforms to a simple array
|
||||
* Raw partial results transforms to a simple array.
|
||||
*/
|
||||
class RawPartialResults implements PartialResultsInterface
|
||||
{
|
||||
|
@ -47,6 +47,6 @@ class RawPartialResults implements PartialResultsInterface
|
|||
return $this->resultSet->getFacets();
|
||||
}
|
||||
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@ use Elastica\SearchableInterface;
|
|||
use Elastica\Query;
|
||||
|
||||
/**
|
||||
* Allows pagination of \Elastica\Query
|
||||
* Allows pagination of \Elastica\Query.
|
||||
*/
|
||||
class TransformedPaginatorAdapter extends RawPaginatorAdapter
|
||||
{
|
||||
|
|
|
@ -6,7 +6,7 @@ use FOS\ElasticaBundle\Transformer\ElasticaToModelTransformerInterface;
|
|||
use Elastica\ResultSet;
|
||||
|
||||
/**
|
||||
* Partial transformed result set
|
||||
* Partial transformed result set.
|
||||
*/
|
||||
class TransformedPartialResults extends RawPartialResults
|
||||
{
|
||||
|
|
|
@ -10,7 +10,7 @@ use Elastica\Document;
|
|||
|
||||
/**
|
||||
* Inserts, replaces and deletes single documents in an elastica type
|
||||
* Accepts domain model objects and converts them to elastica documents
|
||||
* Accepts domain model objects and converts them to elastica documents.
|
||||
*
|
||||
* @author Thibault Duplessis <thibault.duplessis@gmail.com>
|
||||
*/
|
||||
|
@ -34,6 +34,7 @@ class ObjectPersister implements ObjectPersisterInterface
|
|||
* If the ObjectPersister handles a given object.
|
||||
*
|
||||
* @param object $object
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function handlesObject($object)
|
||||
|
@ -47,11 +48,11 @@ class ObjectPersister implements ObjectPersisterInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Log exception if logger defined for persister belonging to the current listener, otherwise re-throw
|
||||
* Log exception if logger defined for persister belonging to the current listener, otherwise re-throw.
|
||||
*
|
||||
* @param BulkException $e
|
||||
*
|
||||
* @throws BulkException
|
||||
* @return null
|
||||
*/
|
||||
private function log(BulkException $e)
|
||||
{
|
||||
|
@ -64,7 +65,7 @@ class ObjectPersister implements ObjectPersisterInterface
|
|||
|
||||
/**
|
||||
* Insert one object into the type
|
||||
* The object will be transformed to an elastica document
|
||||
* The object will be transformed to an elastica document.
|
||||
*
|
||||
* @param object $object
|
||||
*/
|
||||
|
@ -74,10 +75,9 @@ class ObjectPersister implements ObjectPersisterInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Replaces one object in the type
|
||||
* Replaces one object in the type.
|
||||
*
|
||||
* @param object $object
|
||||
* @return null
|
||||
**/
|
||||
public function replaceOne($object)
|
||||
{
|
||||
|
@ -85,10 +85,9 @@ class ObjectPersister implements ObjectPersisterInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Deletes one object in the type
|
||||
* Deletes one object in the type.
|
||||
*
|
||||
* @param object $object
|
||||
* @return null
|
||||
**/
|
||||
public function deleteOne($object)
|
||||
{
|
||||
|
@ -96,11 +95,9 @@ class ObjectPersister implements ObjectPersisterInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Deletes one object in the type by id
|
||||
* Deletes one object in the type by id.
|
||||
*
|
||||
* @param mixed $id
|
||||
*
|
||||
* @return null
|
||||
**/
|
||||
public function deleteById($id)
|
||||
{
|
||||
|
@ -108,7 +105,7 @@ class ObjectPersister implements ObjectPersisterInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Bulk insert an array of objects in the type for the given method
|
||||
* Bulk insert an array of objects in the type for the given method.
|
||||
*
|
||||
* @param array $objects array of domain model objects
|
||||
* @param string Method to call
|
||||
|
@ -148,7 +145,7 @@ class ObjectPersister implements ObjectPersisterInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Bulk deletes an array of objects in the type
|
||||
* Bulk deletes an array of objects in the type.
|
||||
*
|
||||
* @param array $objects array of domain model objects
|
||||
*/
|
||||
|
@ -166,7 +163,7 @@ class ObjectPersister implements ObjectPersisterInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Bulk deletes records from an array of identifiers
|
||||
* Bulk deletes records from an array of identifiers.
|
||||
*
|
||||
* @param array $identifiers array of domain model object identifiers
|
||||
*/
|
||||
|
@ -180,9 +177,10 @@ class ObjectPersister implements ObjectPersisterInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Transforms an object to an elastica document
|
||||
* Transforms an object to an elastica document.
|
||||
*
|
||||
* @param object $object
|
||||
*
|
||||
* @return Document the elastica document
|
||||
*/
|
||||
public function transformToElasticaDocument($object)
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace FOS\ElasticaBundle\Persister;
|
|||
|
||||
/**
|
||||
* Inserts, replaces and deletes single documents in an elastica type
|
||||
* Accepts domain model objects and converts them to elastica documents
|
||||
* Accepts domain model objects and converts them to elastica documents.
|
||||
*
|
||||
* @author Thibault Duplessis <thibault.duplessis@gmail.com>
|
||||
*/
|
||||
|
@ -12,58 +12,56 @@ interface ObjectPersisterInterface
|
|||
{
|
||||
/**
|
||||
* Insert one object into the type
|
||||
* The object will be transformed to an elastica document
|
||||
* The object will be transformed to an elastica document.
|
||||
*
|
||||
* @param object $object
|
||||
*/
|
||||
function insertOne($object);
|
||||
public function insertOne($object);
|
||||
|
||||
/**
|
||||
* Replaces one object in the type
|
||||
* Replaces one object in the type.
|
||||
*
|
||||
* @param object $object
|
||||
**/
|
||||
function replaceOne($object);
|
||||
public function replaceOne($object);
|
||||
|
||||
/**
|
||||
* Deletes one object in the type
|
||||
* Deletes one object in the type.
|
||||
*
|
||||
* @param object $object
|
||||
**/
|
||||
function deleteOne($object);
|
||||
public function deleteOne($object);
|
||||
|
||||
/**
|
||||
* Deletes one object in the type by id
|
||||
* Deletes one object in the type by id.
|
||||
*
|
||||
* @param mixed $id
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
function deleteById($id);
|
||||
public function deleteById($id);
|
||||
|
||||
/**
|
||||
* Bulk inserts an array of objects in the type
|
||||
* Bulk inserts an array of objects in the type.
|
||||
*
|
||||
* @param array $objects array of domain model objects
|
||||
*/
|
||||
function insertMany(array $objects);
|
||||
public function insertMany(array $objects);
|
||||
|
||||
/**
|
||||
* Bulk updates an array of objects in the type
|
||||
* Bulk updates an array of objects in the type.
|
||||
*
|
||||
* @param array $objects array of domain model objects
|
||||
*/
|
||||
function replaceMany(array $objects);
|
||||
public function replaceMany(array $objects);
|
||||
|
||||
/**
|
||||
* Bulk deletes an array of objects in the type
|
||||
* Bulk deletes an array of objects in the type.
|
||||
*
|
||||
* @param array $objects array of domain model objects
|
||||
*/
|
||||
function deleteMany(array $objects);
|
||||
public function deleteMany(array $objects);
|
||||
|
||||
/**
|
||||
* Bulk deletes records from an array of identifiers
|
||||
* Bulk deletes records from an array of identifiers.
|
||||
*
|
||||
* @param array $identifiers array of domain model object identifiers
|
||||
*/
|
||||
|
|
|
@ -9,7 +9,7 @@ use FOS\ElasticaBundle\Transformer\ModelToElasticaTransformerInterface;
|
|||
/**
|
||||
* Inserts, replaces and deletes single objects in an elastica type, making use
|
||||
* of elastica's serializer support to convert objects in to elastica documents.
|
||||
* Accepts domain model objects and passes them directly to elastica
|
||||
* Accepts domain model objects and passes them directly to elastica.
|
||||
*
|
||||
* @author Lea Haensenberber <lea.haensenberger@gmail.com>
|
||||
*/
|
||||
|
@ -28,9 +28,10 @@ class ObjectSerializerPersister extends ObjectPersister
|
|||
|
||||
/**
|
||||
* Transforms an object to an elastica document
|
||||
* with just the identifier set
|
||||
* with just the identifier set.
|
||||
*
|
||||
* @param object $object
|
||||
*
|
||||
* @return Document the elastica document
|
||||
*/
|
||||
public function transformToElasticaDocument($object)
|
||||
|
|
|
@ -67,6 +67,7 @@ class ElasticaToModelTransformer implements ElasticaToModelTransformerInterface
|
|||
* fetched from the database.
|
||||
*
|
||||
* @param array $elasticaObjects
|
||||
*
|
||||
* @return array|\ArrayObject
|
||||
*/
|
||||
public function transform(array $elasticaObjects)
|
||||
|
@ -135,6 +136,7 @@ class ElasticaToModelTransformer implements ElasticaToModelTransformerInterface
|
|||
*
|
||||
* @param array $identifierValues Identifier values
|
||||
* @param boolean $hydrate Whether or not to hydrate the results
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function findByIdentifiers(array $identifierValues, $hydrate)
|
||||
|
@ -158,6 +160,7 @@ class ElasticaToModelTransformer implements ElasticaToModelTransformerInterface
|
|||
* @param string $class Propel model class
|
||||
* @param string $identifierField Identifier field name (e.g. "id")
|
||||
* @param array $identifierValues Identifier values
|
||||
*
|
||||
* @return \ModelCriteria
|
||||
*/
|
||||
protected function createQuery($class, $identifierField, array $identifierValues)
|
||||
|
@ -170,6 +173,7 @@ class ElasticaToModelTransformer implements ElasticaToModelTransformerInterface
|
|||
|
||||
/**
|
||||
* @see https://github.com/doctrine/common/blob/master/lib/Doctrine/Common/Util/Inflector.php
|
||||
*
|
||||
* @param string $str
|
||||
*/
|
||||
private function camelize($str)
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace FOS\ElasticaBundle\Propel;
|
|||
use FOS\ElasticaBundle\Provider\AbstractProvider;
|
||||
|
||||
/**
|
||||
* Propel provider
|
||||
* Propel provider.
|
||||
*
|
||||
* @author William Durand <william.durand1@gmail.com>
|
||||
*/
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace FOS\ElasticaBundle\Provider;
|
|||
use FOS\ElasticaBundle\Persister\ObjectPersisterInterface;
|
||||
|
||||
/**
|
||||
* AbstractProvider
|
||||
* AbstractProvider.
|
||||
*/
|
||||
abstract class AbstractProvider implements ProviderInterface
|
||||
{
|
||||
|
@ -56,6 +56,7 @@ abstract class AbstractProvider implements ProviderInterface
|
|||
* Checks if a given object should be indexed or not.
|
||||
*
|
||||
* @param object $object
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isObjectIndexable($object)
|
||||
|
@ -68,7 +69,7 @@ abstract class AbstractProvider implements ProviderInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Get string with RAM usage information (current and peak)
|
||||
* Get string with RAM usage information (current and peak).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
|
|
|
@ -33,7 +33,7 @@ class Indexable implements IndexableInterface
|
|||
private $container;
|
||||
|
||||
/**
|
||||
* An instance of ExpressionLanguage
|
||||
* An instance of ExpressionLanguage.
|
||||
*
|
||||
* @var ExpressionLanguage
|
||||
*/
|
||||
|
@ -47,7 +47,7 @@ class Indexable implements IndexableInterface
|
|||
private $initialisedCallbacks = array();
|
||||
|
||||
/**
|
||||
* PropertyAccessor instance
|
||||
* PropertyAccessor instance.
|
||||
*
|
||||
* @var PropertyAccessorInterface
|
||||
*/
|
||||
|
@ -69,6 +69,7 @@ class Indexable implements IndexableInterface
|
|||
* @param string $indexName
|
||||
* @param string $typeName
|
||||
* @param mixed $object
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isObjectIndexable($indexName, $typeName, $object)
|
||||
|
@ -82,7 +83,7 @@ class Indexable implements IndexableInterface
|
|||
if ($callback instanceof Expression) {
|
||||
return $this->getExpressionLanguage()->evaluate($callback, array(
|
||||
'object' => $object,
|
||||
$this->getExpressionVar($object) => $object
|
||||
$this->getExpressionVar($object) => $object,
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -96,12 +97,13 @@ class Indexable implements IndexableInterface
|
|||
*
|
||||
* @param string $type
|
||||
* @param object $object
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function buildCallback($type, $object)
|
||||
{
|
||||
if (!array_key_exists($type, $this->callbacks)) {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
$callback = $this->callbacks[$type];
|
||||
|
@ -148,6 +150,7 @@ class Indexable implements IndexableInterface
|
|||
*
|
||||
* @param string $type
|
||||
* @param object $object
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function getCallback($type, $object)
|
||||
|
@ -177,6 +180,7 @@ class Indexable implements IndexableInterface
|
|||
|
||||
/**
|
||||
* @param mixed $object
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getExpressionVar($object = null)
|
||||
|
|
|
@ -19,6 +19,7 @@ interface IndexableInterface
|
|||
* @param string $indexName
|
||||
* @param string $typeName
|
||||
* @param mixed $object
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isObjectIndexable($indexName, $typeName, $object);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace FOS\ElasticaBundle\Provider;
|
||||
|
||||
/**
|
||||
* Insert application domain objects into elastica types
|
||||
* Insert application domain objects into elastica types.
|
||||
*
|
||||
* @author Thibault Duplessis <thibault.duplessis@gmail.com>
|
||||
*/
|
||||
|
@ -14,7 +14,8 @@ interface ProviderInterface
|
|||
*
|
||||
* @param \Closure $loggerClosure
|
||||
* @param array $options
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
function populate(\Closure $loggerClosure = null, array $options = array());
|
||||
public function populate(\Closure $loggerClosure = null, array $options = array());
|
||||
}
|
||||
|
|
|
@ -58,7 +58,9 @@ class ProviderRegistry implements ContainerAwareInterface
|
|||
* Providers will be indexed by "type" strings in the returned array.
|
||||
*
|
||||
* @param string $index
|
||||
*
|
||||
* @return array of ProviderInterface instances
|
||||
*
|
||||
* @throws \InvalidArgumentException if no providers were registered for the index
|
||||
*/
|
||||
public function getIndexProviders($index)
|
||||
|
@ -81,7 +83,9 @@ class ProviderRegistry implements ContainerAwareInterface
|
|||
*
|
||||
* @param string $index
|
||||
* @param string $type
|
||||
*
|
||||
* @return ProviderInterface
|
||||
*
|
||||
* @throws \InvalidArgumentException if no provider was registered for the index and type
|
||||
*/
|
||||
public function getProvider($index, $type)
|
||||
|
|
|
@ -23,6 +23,7 @@ class Repository
|
|||
* @param mixed $query
|
||||
* @param integer $limit
|
||||
* @param array $options
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function find($query, $limit = null, $options = array())
|
||||
|
@ -34,6 +35,7 @@ class Repository
|
|||
* @param mixed $query
|
||||
* @param integer $limit
|
||||
* @param array $options
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function findHybrid($query, $limit = null, $options = array())
|
||||
|
@ -44,6 +46,7 @@ class Repository
|
|||
/**
|
||||
* @param mixed $query
|
||||
* @param array $options
|
||||
*
|
||||
* @return \Pagerfanta\Pagerfanta
|
||||
*/
|
||||
public function findPaginated($query, $options = array())
|
||||
|
@ -54,6 +57,7 @@ class Repository
|
|||
/**
|
||||
* @param string $query
|
||||
* @param array $options
|
||||
*
|
||||
* @return Paginator\PaginatorAdapterInterface
|
||||
*/
|
||||
public function createPaginatorAdapter($query, $options = array())
|
||||
|
|
|
@ -38,7 +38,7 @@ class PaginateElasticaQuerySubscriber implements EventSubscriberInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Adds knp paging sort to query
|
||||
* Adds knp paging sort to query.
|
||||
*
|
||||
* @param ItemsEvent $event
|
||||
*/
|
||||
|
@ -70,7 +70,7 @@ class PaginateElasticaQuerySubscriber implements EventSubscriberInterface
|
|||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
'knp_pager.items' => array('items', 1)
|
||||
'knp_pager.items' => array('items', 1),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace FOS\ElasticaBundle\Tests\Command;
|
||||
|
||||
|
||||
use FOS\ElasticaBundle\Command\ResetCommand;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Output\NullOutput;
|
||||
|
|
|
@ -6,7 +6,7 @@ use FOS\ElasticaBundle\DependencyInjection\Configuration;
|
|||
use Symfony\Component\Config\Definition\Processor;
|
||||
|
||||
/**
|
||||
* ConfigurationTest
|
||||
* ConfigurationTest.
|
||||
*/
|
||||
class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
@ -34,7 +34,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertSame(array(
|
||||
'clients' => array(),
|
||||
'indexes' => array(),
|
||||
'default_manager' => 'orm'
|
||||
'default_manager' => 'orm',
|
||||
), $configuration);
|
||||
}
|
||||
|
||||
|
@ -50,18 +50,18 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
|||
array(
|
||||
'url' => 'http://es1:9200',
|
||||
'headers' => array(
|
||||
'Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=='
|
||||
)
|
||||
'Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'url' => 'http://es2:9200',
|
||||
'headers' => array(
|
||||
'Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=='
|
||||
)
|
||||
'Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
)
|
||||
)
|
||||
));
|
||||
|
||||
$this->assertCount(2, $configuration['clients']);
|
||||
|
@ -91,9 +91,9 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
|||
),
|
||||
'logging_custom' => array(
|
||||
'url' => 'http://localhost:9200',
|
||||
'logger' => 'custom.service'
|
||||
'logger' => 'custom.service',
|
||||
),
|
||||
),
|
||||
)
|
||||
));
|
||||
|
||||
$this->assertCount(4, $configuration['clients']);
|
||||
|
@ -131,8 +131,8 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
|||
),
|
||||
'serializer' => array(
|
||||
'groups' => array('Search'),
|
||||
'version' => 1
|
||||
)
|
||||
'version' => 1,
|
||||
),
|
||||
),
|
||||
'types' => array(
|
||||
'test' => array(
|
||||
|
@ -144,20 +144,20 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
|||
'persistence' => array(
|
||||
'listener' => array(
|
||||
'logger' => true,
|
||||
)
|
||||
)
|
||||
),
|
||||
),
|
||||
),
|
||||
'test2' => array(
|
||||
'mappings' => array(
|
||||
'title' => null,
|
||||
'children' => array(
|
||||
'type' => 'nested',
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -169,7 +169,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
|||
'host' => 'localhost',
|
||||
'port' => 9200,
|
||||
),
|
||||
)
|
||||
),
|
||||
));
|
||||
|
||||
$this->assertTrue(empty($configuration['clients']['default']['connections'][0]['url']));
|
||||
|
@ -189,11 +189,11 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
|||
'title' => array(),
|
||||
'published' => array('type' => 'datetime'),
|
||||
'body' => null,
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
$this->assertCount(3, $configuration['indexes']['test']['types']['test']['properties']);
|
||||
|
@ -208,10 +208,10 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
|||
'indexes' => array(
|
||||
'test' => array(
|
||||
'types' => array(
|
||||
'test' => null
|
||||
)
|
||||
)
|
||||
)
|
||||
'test' => null,
|
||||
),
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
$this->assertArrayHasKey('properties', $configuration['indexes']['test']['types']['test']);
|
||||
|
@ -243,23 +243,23 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
|||
'type' => 'nested',
|
||||
'properties' => array(
|
||||
'nested_field1' => array(
|
||||
'type' => 'integer'
|
||||
'type' => 'integer',
|
||||
),
|
||||
'nested_field2' => array(
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'id' => array(
|
||||
'type' => 'integer'
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
'type' => 'integer',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,10 +12,10 @@ class FOSElasticaExtensionTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
$config = Yaml::parse(file_get_contents(__DIR__.'/fixtures/config.yml'));
|
||||
|
||||
$containerBuilder = new ContainerBuilder;
|
||||
$containerBuilder = new ContainerBuilder();
|
||||
$containerBuilder->setParameter('kernel.debug', true);
|
||||
|
||||
$extension = new FOSElasticaExtension;
|
||||
$extension = new FOSElasticaExtension();
|
||||
|
||||
$extension->load($config, $containerBuilder);
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ class AbstractElasticaToModelTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
protected $objectClass = 'stdClass';
|
||||
|
||||
/**
|
||||
* Tests if ignore_missing option is properly handled in transformHybrid() method
|
||||
* Tests if ignore_missing option is properly handled in transformHybrid() method.
|
||||
*/
|
||||
public function testIgnoreMissingOptionDuringTransformHybrid()
|
||||
{
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace FOS\ElasticaBundle\Tests\Doctrine;
|
||||
|
||||
/**
|
||||
* See concrete MongoDB/ORM instances of this abstract test
|
||||
* See concrete MongoDB/ORM instances of this abstract test.
|
||||
*
|
||||
* @author Richard Miller <info@limethinking.co.uk>
|
||||
*/
|
||||
|
@ -286,4 +286,3 @@ class Entity
|
|||
return $this->id;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -231,7 +231,6 @@ class AbstractProviderTest extends \PHPUnit_Framework_TestCase
|
|||
->with('index', 'type', 2)
|
||||
->will($this->returnValue(true));
|
||||
|
||||
|
||||
$this->objectPersister->expects($this->once())
|
||||
->method('insertMany')
|
||||
->with(array(1 => 2));
|
||||
|
@ -259,7 +258,7 @@ class AbstractProviderTest extends \PHPUnit_Framework_TestCase
|
|||
private function getMockBulkResponseException()
|
||||
{
|
||||
return $this->getMock('Elastica\Exception\Bulk\ResponseException', null, array(
|
||||
new ResponseSet(new Response(array()), array())
|
||||
new ResponseSet(new Response(array()), array()),
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -302,5 +301,5 @@ class AbstractProviderTest extends \PHPUnit_Framework_TestCase
|
|||
*/
|
||||
interface ObjectManager
|
||||
{
|
||||
function clear();
|
||||
public function clear();
|
||||
}
|
||||
|
|
|
@ -109,7 +109,7 @@ class ElasticaToModelTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
'findAll',
|
||||
'findBy',
|
||||
'findOneBy',
|
||||
'getClassName'
|
||||
'getClassName',
|
||||
));
|
||||
|
||||
$this->manager->expects($this->any())
|
||||
|
|
|
@ -4,9 +4,13 @@ namespace FOS\ElasticaBundle\Tests\Doctrine;
|
|||
|
||||
use FOS\ElasticaBundle\Doctrine\RepositoryManager;
|
||||
|
||||
class CustomRepository{}
|
||||
class CustomRepository
|
||||
{
|
||||
}
|
||||
|
||||
class Entity{}
|
||||
class Entity
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Richard Miller <info@limethinking.co.uk>
|
||||
|
|
|
@ -5,11 +5,11 @@ namespace FOS\ElasticaBundle\Tests\Client;
|
|||
use Elastica\Request;
|
||||
use Elastica\Transport\Null as NullTransport;
|
||||
|
||||
class LoggingClientTest extends \PHPUnit_Framework_TestCase
|
||||
class ClientTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testRequestsAreLogged()
|
||||
{
|
||||
$transport = new NullTransport;
|
||||
$transport = new NullTransport();
|
||||
|
||||
$connection = $this->getMock('Elastica\Connection');
|
||||
$connection->expects($this->any())->method('getTransportObject')->will($this->returnValue($transport));
|
||||
|
|
|
@ -16,7 +16,6 @@ class FOSElasticaBundleTest extends \PHPUnit_Framework_TestCase
|
|||
->method('addCompilerPass')
|
||||
->with($this->isInstanceOf('Symfony\\Component\\DependencyInjection\\Compiler\\CompilerPassInterface'));
|
||||
|
||||
|
||||
$bundle = new FOSElasticaBundle();
|
||||
$bundle->build($container);
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ class ConfigurationManagerTest extends WebTestCase
|
|||
|
||||
/**
|
||||
* @param Client $client
|
||||
*
|
||||
* @return \FOS\ElasticaBundle\Configuration\ConfigManager
|
||||
*/
|
||||
private function getManager(Client $client)
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace FOS\ElasticaBundle\Tests\Functional;
|
|||
class IndexableCallbackTest extends WebTestCase
|
||||
{
|
||||
/**
|
||||
* 2 reasons for this test:
|
||||
* 2 reasons for this test:.
|
||||
*
|
||||
* 1) To test that the configuration rename from is_indexable_callback under the listener
|
||||
* key is respected, and
|
||||
|
|
|
@ -100,6 +100,7 @@ class MappingToElasticaTest extends WebTestCase
|
|||
|
||||
/**
|
||||
* @param Client $client
|
||||
*
|
||||
* @return \FOS\ElasticaBundle\Resetter $resetter
|
||||
*/
|
||||
private function getResetter(Client $client)
|
||||
|
@ -109,6 +110,7 @@ class MappingToElasticaTest extends WebTestCase
|
|||
|
||||
/**
|
||||
* @param Client $client
|
||||
*
|
||||
* @return \Elastica\Type
|
||||
*/
|
||||
private function getType(Client $client, $type = 'type')
|
||||
|
|
|
@ -47,4 +47,3 @@ fos_elastica:
|
|||
serializer:
|
||||
groups: ['search', 'Default']
|
||||
version: 1.1
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@ class IndexManagerTest extends \PHPUnit_Framework_TestCase
|
|||
*/
|
||||
private $indexManager;
|
||||
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
foreach (array('index1', 'index2', 'index3') as $indexName) {
|
||||
|
|
|
@ -8,10 +8,8 @@
|
|||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
|
||||
namespace FOS\ElasticaBundle\Tests\Integration;
|
||||
|
||||
|
||||
class MappingTest {
|
||||
|
||||
class MappingTest
|
||||
{
|
||||
}
|
|
@ -23,6 +23,7 @@ class ElasticaLoggerTest extends \PHPUnit_Framework_TestCase
|
|||
* @param string $level
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
*
|
||||
* @return ElasticaLogger
|
||||
*/
|
||||
private function getMockLoggerForLevelMessageAndContext($level, $message, $context)
|
||||
|
@ -45,7 +46,7 @@ class ElasticaLoggerTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
public function testGetZeroIfNoQueriesAdded()
|
||||
{
|
||||
$elasticaLogger = new ElasticaLogger;
|
||||
$elasticaLogger = new ElasticaLogger();
|
||||
$this->assertEquals(0, $elasticaLogger->getNbQueries());
|
||||
}
|
||||
|
||||
|
|
|
@ -4,16 +4,19 @@ namespace FOS\ElasticaBundle\Tests\Manager;
|
|||
|
||||
use FOS\ElasticaBundle\Manager\RepositoryManager;
|
||||
|
||||
class CustomRepository{}
|
||||
class CustomRepository
|
||||
{
|
||||
}
|
||||
|
||||
class Entity{}
|
||||
class Entity
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Richard Miller <info@limethinking.co.uk>
|
||||
*/
|
||||
class RepositoryManagerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testThatGetRepositoryReturnsDefaultRepository()
|
||||
{
|
||||
/** @var $finderMock \PHPUnit_Framework_MockObject_MockObject|\FOS\ElasticaBundle\Finder\TransformedFinder */
|
||||
|
|
|
@ -21,7 +21,7 @@ class IndexableTest extends \PHPUnit_Framework_TestCase
|
|||
public function testIndexableUnknown()
|
||||
{
|
||||
$indexable = new Indexable(array(), $this->container);
|
||||
$index = $indexable->isObjectIndexable('index', 'type', new Entity);
|
||||
$index = $indexable->isObjectIndexable('index', 'type', new Entity());
|
||||
|
||||
$this->assertTrue($index);
|
||||
}
|
||||
|
@ -32,9 +32,9 @@ class IndexableTest extends \PHPUnit_Framework_TestCase
|
|||
public function testValidIndexableCallbacks($callback, $return)
|
||||
{
|
||||
$indexable = new Indexable(array(
|
||||
'index/type' => $callback
|
||||
'index/type' => $callback,
|
||||
), $this->container);
|
||||
$index = $indexable->isObjectIndexable('index', 'type', new Entity);
|
||||
$index = $indexable->isObjectIndexable('index', 'type', new Entity());
|
||||
|
||||
$this->assertEquals($return, $index);
|
||||
}
|
||||
|
@ -46,9 +46,9 @@ class IndexableTest extends \PHPUnit_Framework_TestCase
|
|||
public function testInvalidIsIndexableCallbacks($callback)
|
||||
{
|
||||
$indexable = new Indexable(array(
|
||||
'index/type' => $callback
|
||||
'index/type' => $callback,
|
||||
), $this->container);
|
||||
$indexable->isObjectIndexable('index', 'type', new Entity);
|
||||
$indexable->isObjectIndexable('index', 'type', new Entity());
|
||||
}
|
||||
|
||||
public function provideInvalidIsIndexableCallbacks()
|
||||
|
|
|
@ -13,14 +13,7 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
$testQuery = 'Test Query';
|
||||
|
||||
/** @var $typeMock \PHPUnit_Framework_MockObject_MockObject|\FOS\ElasticaBundle\Finder\TransformedFinder */
|
||||
$finderMock = $this->getMockBuilder('FOS\ElasticaBundle\Finder\TransformedFinder')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$finderMock->expects($this->once())
|
||||
->method('find')
|
||||
->with($this->equalTo($testQuery));
|
||||
|
||||
$finderMock = $this->getFinderMock($testQuery);
|
||||
$repository = new Repository($finderMock);
|
||||
$repository->find($testQuery);
|
||||
}
|
||||
|
@ -30,14 +23,7 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase
|
|||
$testQuery = 'Test Query';
|
||||
$testLimit = 20;
|
||||
|
||||
/** @var $typeMock \PHPUnit_Framework_MockObject_MockObject|\FOS\ElasticaBundle\Finder\TransformedFinder */
|
||||
$finderMock = $this->getMockBuilder('FOS\ElasticaBundle\Finder\TransformedFinder')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$finderMock->expects($this->once())
|
||||
->method('find')
|
||||
->with($this->equalTo($testQuery), $this->equalTo($testLimit));
|
||||
|
||||
$finderMock = $this->getFinderMock($testQuery, $testLimit);
|
||||
$repository = new Repository($finderMock);
|
||||
$repository->find($testQuery, $testLimit);
|
||||
}
|
||||
|
@ -46,14 +32,7 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
$testQuery = 'Test Query';
|
||||
|
||||
/** @var $typeMock \PHPUnit_Framework_MockObject_MockObject|\FOS\ElasticaBundle\Finder\TransformedFinder */
|
||||
$finderMock = $this->getMockBuilder('FOS\ElasticaBundle\Finder\TransformedFinder')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$finderMock->expects($this->once())
|
||||
->method('findPaginated')
|
||||
->with($this->equalTo($testQuery));
|
||||
|
||||
$finderMock = $this->getFinderMock($testQuery, array(), 'findPaginated');
|
||||
$repository = new Repository($finderMock);
|
||||
$repository->findPaginated($testQuery);
|
||||
}
|
||||
|
@ -62,14 +41,7 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
$testQuery = 'Test Query';
|
||||
|
||||
/** @var $typeMock \PHPUnit_Framework_MockObject_MockObject|\FOS\ElasticaBundle\Finder\TransformedFinder */
|
||||
$finderMock = $this->getMockBuilder('FOS\ElasticaBundle\Finder\TransformedFinder')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$finderMock->expects($this->once())
|
||||
->method('createPaginatorAdapter')
|
||||
->with($this->equalTo($testQuery));
|
||||
|
||||
$finderMock = $this->getFinderMock($testQuery, array(), 'createPaginatorAdapter');
|
||||
$repository = new Repository($finderMock);
|
||||
$repository->createPaginatorAdapter($testQuery);
|
||||
}
|
||||
|
@ -77,17 +49,27 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase
|
|||
public function testThatFindHybridCallsFindHybridOnFinder()
|
||||
{
|
||||
$testQuery = 'Test Query';
|
||||
$testLimit = 20;
|
||||
|
||||
/** @var $typeMock \PHPUnit_Framework_MockObject_MockObject|\FOS\ElasticaBundle\Finder\TransformedFinder */
|
||||
$finderMock = $this->getFinderMock($testQuery, null, 'findHybrid');
|
||||
$repository = new Repository($finderMock);
|
||||
$repository->findHybrid($testQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $testQuery
|
||||
* @param int $testLimit
|
||||
* @param string $method
|
||||
* @return \FOS\ElasticaBundle\Finder\TransformedFinder|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private function getFinderMock($testQuery, $testLimit = null, $method = 'find')
|
||||
{
|
||||
$finderMock = $this->getMockBuilder('FOS\ElasticaBundle\Finder\TransformedFinder')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$finderMock->expects($this->once())
|
||||
->method('findHybrid')
|
||||
->method($method)
|
||||
->with($this->equalTo($testQuery), $this->equalTo($testLimit));
|
||||
|
||||
$repository = new Repository($finderMock);
|
||||
$repository->findHybrid($testQuery, $testLimit);
|
||||
return $finderMock;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ class ElasticaToModelTransformerCollectionTest extends \PHPUnit_Framework_TestCa
|
|||
$objectClasses = $this->collection->getObjectClass();
|
||||
$this->assertEquals(array(
|
||||
'type1' => 'FOS\ElasticaBundle\Tests\Transformer\POPO',
|
||||
'type2' => 'FOS\ElasticaBundle\Tests\Transformer\POPO2'
|
||||
'type2' => 'FOS\ElasticaBundle\Tests\Transformer\POPO2',
|
||||
), $objectClasses);
|
||||
}
|
||||
|
||||
|
@ -120,8 +120,8 @@ class ElasticaToModelTransformerCollectionTest extends \PHPUnit_Framework_TestCa
|
|||
|
||||
return array(
|
||||
array(
|
||||
$result, $transformedObject
|
||||
)
|
||||
$result, $transformedObject,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ class POPO
|
|||
{
|
||||
return array(
|
||||
'key1' => 'value1',
|
||||
'key2' => 'value2'
|
||||
'key2' => 'value2',
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -152,7 +152,7 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
'float' => array(),
|
||||
'bool' => array(),
|
||||
'date' => array(),
|
||||
'falseBool' => array()
|
||||
'falseBool' => array(),
|
||||
)
|
||||
);
|
||||
$data = $document->getData();
|
||||
|
@ -185,7 +185,7 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(
|
||||
array(
|
||||
'key1' => 'value1',
|
||||
'key2' => 'value2'
|
||||
'key2' => 'value2',
|
||||
), $data['array']
|
||||
);
|
||||
}
|
||||
|
@ -250,8 +250,8 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
$document = $transformer->transform(new POPO(), array(
|
||||
'sub' => array(
|
||||
'type' => 'nested',
|
||||
'properties' => array('foo' => '~')
|
||||
)
|
||||
'properties' => array('foo' => '~'),
|
||||
),
|
||||
));
|
||||
$data = $document->getData();
|
||||
|
||||
|
@ -259,7 +259,7 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInternalType('array', $data['sub']);
|
||||
$this->assertEquals(array(
|
||||
array('foo' => 'foo'),
|
||||
array('foo' => 'bar')
|
||||
array('foo' => 'bar'),
|
||||
), $data['sub']);
|
||||
}
|
||||
|
||||
|
@ -269,8 +269,8 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
$document = $transformer->transform(new POPO(), array(
|
||||
'sub' => array(
|
||||
'type' => 'object',
|
||||
'properties' => array('bar')
|
||||
)
|
||||
'properties' => array('bar'),
|
||||
),
|
||||
));
|
||||
$data = $document->getData();
|
||||
|
||||
|
@ -278,7 +278,7 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInternalType('array', $data['sub']);
|
||||
$this->assertEquals(array(
|
||||
array('bar' => 'foo'),
|
||||
array('bar' => 'bar')
|
||||
array('bar' => 'bar'),
|
||||
), $data['sub']);
|
||||
}
|
||||
|
||||
|
@ -287,8 +287,8 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
$transformer = $this->getTransformer();
|
||||
$document = $transformer->transform(new POPO(), array(
|
||||
'obj' => array(
|
||||
'type' => 'object'
|
||||
)
|
||||
'type' => 'object',
|
||||
),
|
||||
));
|
||||
$data = $document->getData();
|
||||
|
||||
|
@ -297,7 +297,7 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(array(
|
||||
'foo' => 'foo',
|
||||
'bar' => 'foo',
|
||||
'id' => 1
|
||||
'id' => 1,
|
||||
), $data['obj']);
|
||||
}
|
||||
|
||||
|
@ -313,14 +313,14 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
'properties' => array(
|
||||
'key1sub1' => array(
|
||||
'type' => 'string',
|
||||
'properties' => array()
|
||||
'properties' => array(),
|
||||
),
|
||||
'key1sub2' => array(
|
||||
'type' => 'string',
|
||||
'properties' => array()
|
||||
)
|
||||
)
|
||||
)
|
||||
'properties' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
$data = $document->getData();
|
||||
|
@ -333,14 +333,14 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
array(
|
||||
'foo' => 'foo',
|
||||
'bar' => 'foo',
|
||||
'id' => 1
|
||||
'id' => 1,
|
||||
),
|
||||
$data['obj']
|
||||
);
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'key1sub1' => 'value1sub1',
|
||||
'key1sub2' => 'value1sub2'
|
||||
'key1sub2' => 'value1sub2',
|
||||
),
|
||||
$data['nestedObject'][0]
|
||||
);
|
||||
|
|
|
@ -41,6 +41,7 @@ class ElasticaToModelTransformerCollection implements ElasticaToModelTransformer
|
|||
|
||||
/**
|
||||
* @param Document[] $elasticaObjects
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function transform(array $elasticaObjects)
|
||||
|
@ -51,7 +52,7 @@ class ElasticaToModelTransformerCollection implements ElasticaToModelTransformer
|
|||
}
|
||||
|
||||
$transformed = array();
|
||||
foreach ($sorted AS $type => $objects) {
|
||||
foreach ($sorted as $type => $objects) {
|
||||
$transformedObjects = $this->transformers[$type]->transform($objects);
|
||||
$identifierGetter = 'get'.ucfirst($this->transformers[$type]->getIdentifierField());
|
||||
$transformed[$type] = array_combine(
|
||||
|
|
|
@ -3,32 +3,33 @@
|
|||
namespace FOS\ElasticaBundle\Transformer;
|
||||
|
||||
/**
|
||||
* Maps Elastica documents with model objects
|
||||
* Maps Elastica documents with model objects.
|
||||
*/
|
||||
interface ElasticaToModelTransformerInterface
|
||||
{
|
||||
/**
|
||||
* Transforms an array of elastica objects into an array of
|
||||
* model objects fetched from the doctrine repository
|
||||
* model objects fetched from the doctrine repository.
|
||||
*
|
||||
* @param array $elasticaObjects array of elastica objects
|
||||
*
|
||||
* @return array of model objects
|
||||
**/
|
||||
function transform(array $elasticaObjects);
|
||||
public function transform(array $elasticaObjects);
|
||||
|
||||
function hybridTransform(array $elasticaObjects);
|
||||
public function hybridTransform(array $elasticaObjects);
|
||||
|
||||
/**
|
||||
* Returns the object class used by the transformer.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getObjectClass();
|
||||
public function getObjectClass();
|
||||
|
||||
/**
|
||||
* Returns the identifier field from the options
|
||||
* Returns the identifier field from the options.
|
||||
*
|
||||
* @return string the identifier field
|
||||
*/
|
||||
function getIdentifierField();
|
||||
public function getIdentifierField();
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace FOS\ElasticaBundle\Transformer;
|
||||
|
||||
/**
|
||||
* Maps Elastica documents with model objects
|
||||
* Maps Elastica documents with model objects.
|
||||
*/
|
||||
interface HighlightableModelInterface
|
||||
{
|
||||
|
|
|
@ -8,28 +8,28 @@ use Elastica\Document;
|
|||
/**
|
||||
* Maps Elastica documents with Doctrine objects
|
||||
* This mapper assumes an exact match between
|
||||
* elastica documents ids and doctrine object ids
|
||||
* elastica documents ids and doctrine object ids.
|
||||
*/
|
||||
class ModelToElasticaAutoTransformer implements ModelToElasticaTransformerInterface
|
||||
{
|
||||
/**
|
||||
* Optional parameters
|
||||
* Optional parameters.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array(
|
||||
'identifier' => 'id'
|
||||
'identifier' => 'id',
|
||||
);
|
||||
|
||||
/**
|
||||
* PropertyAccessor instance
|
||||
* PropertyAccessor instance.
|
||||
*
|
||||
* @var PropertyAccessorInterface
|
||||
*/
|
||||
protected $propertyAccessor;
|
||||
|
||||
/**
|
||||
* Instanciates a new Mapper
|
||||
* Instanciates a new Mapper.
|
||||
*
|
||||
* @param array $options
|
||||
*/
|
||||
|
@ -39,7 +39,7 @@ class ModelToElasticaAutoTransformer implements ModelToElasticaTransformerInterf
|
|||
}
|
||||
|
||||
/**
|
||||
* Set the PropertyAccessor
|
||||
* Set the PropertyAccessor.
|
||||
*
|
||||
* @param PropertyAccessorInterface $propertyAccessor
|
||||
*/
|
||||
|
@ -49,7 +49,7 @@ class ModelToElasticaAutoTransformer implements ModelToElasticaTransformerInterf
|
|||
}
|
||||
|
||||
/**
|
||||
* Transforms an object into an elastica object having the required keys
|
||||
* Transforms an object into an elastica object having the required keys.
|
||||
*
|
||||
* @param object $object the object to convert
|
||||
* @param array $fields the keys we want to have in the returned array
|
||||
|
@ -96,7 +96,7 @@ class ModelToElasticaAutoTransformer implements ModelToElasticaTransformerInterf
|
|||
}
|
||||
|
||||
/**
|
||||
* transform a nested document or an object property into an array of ElasticaDocument
|
||||
* transform a nested document or an object property into an array of ElasticaDocument.
|
||||
*
|
||||
* @param array|\Traversable|\ArrayAccess $objects the object to convert
|
||||
* @param array $fields the keys we want to have in the returned array
|
||||
|
@ -123,7 +123,7 @@ class ModelToElasticaAutoTransformer implements ModelToElasticaTransformerInterf
|
|||
}
|
||||
|
||||
/**
|
||||
* Attempts to convert any type to a string or an array of strings
|
||||
* Attempts to convert any type to a string or an array of strings.
|
||||
*
|
||||
* @param mixed $value
|
||||
*
|
||||
|
@ -131,8 +131,7 @@ class ModelToElasticaAutoTransformer implements ModelToElasticaTransformerInterf
|
|||
*/
|
||||
protected function normalizeValue($value)
|
||||
{
|
||||
$normalizeValue = function(&$v)
|
||||
{
|
||||
$normalizeValue = function (&$v) {
|
||||
if ($v instanceof \DateTime) {
|
||||
$v = $v->format('c');
|
||||
} elseif (!is_scalar($v) && !is_null($v)) {
|
||||
|
|
|
@ -6,12 +6,12 @@ use Elastica\Document;
|
|||
|
||||
/**
|
||||
* Creates an Elastica document with the ID of
|
||||
* the Doctrine object as Elastica document ID
|
||||
* the Doctrine object as Elastica document ID.
|
||||
*/
|
||||
class ModelToElasticaIdentifierTransformer extends ModelToElasticaAutoTransformer
|
||||
{
|
||||
/**
|
||||
* Creates an elastica document with the id of the doctrine object as id
|
||||
* Creates an elastica document with the id of the doctrine object as id.
|
||||
*
|
||||
* @param object $object the object to convert
|
||||
* @param array $fields the keys we want to have in the returned array
|
||||
|
|
|
@ -3,16 +3,17 @@
|
|||
namespace FOS\ElasticaBundle\Transformer;
|
||||
|
||||
/**
|
||||
* Maps Elastica documents with model objects
|
||||
* Maps Elastica documents with model objects.
|
||||
*/
|
||||
interface ModelToElasticaTransformerInterface
|
||||
{
|
||||
/**
|
||||
* Transforms an object into an elastica object having the required keys
|
||||
* Transforms an object into an elastica object having the required keys.
|
||||
*
|
||||
* @param object $object the object to convert
|
||||
* @param array $fields the keys we want to have in the returned array
|
||||
*
|
||||
* @return \Elastica\Document
|
||||
**/
|
||||
function transform($object, array $fields);
|
||||
public function transform($object, array $fields);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue