/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp() { $this->metadataFactory = $this->getMock('Doctrine\\Search\\Mapping\\ClassMetadataFactory'); $this->searchClient = $this->getMockBuilder('Doctrine\\Search\\ElasticSearch\\Client')->disableOriginalConstructor()->getMock(); $this->configuration = $this->getMock('Doctrine\\Search\\Configuration'); $this->configuration->expects($this->once())->method('getClassMetadataFactory')->will($this->returnValue($this->metadataFactory)); $this->configuration->expects($this->once())->method('getMetadataCacheImpl')->will($this->returnValue($this->getMock('Doctrine\\Common\\Cache\\ArrayCache'))); $this->evm = new EventManager(); $this->sm = new SearchManager($this->configuration, $this->searchClient, $this->evm); }
/** * Constructor * * @param Configuration $config * @param SearchClientInterface $client * @param EventManager $eventManager */ public function __construct(Configuration $config, SearchClientInterface $client, EventManager $eventManager) { $this->configuration = $config; $this->client = $client; $this->eventManager = $eventManager; $this->metadataFactory = $this->configuration->getClassMetadataFactory(); $this->metadataFactory->setSearchManager($this); $this->metadataFactory->setConfiguration($this->configuration); $this->metadataFactory->setCacheDriver($this->configuration->getMetadataCacheImpl()); $this->serializer = $this->configuration->getEntitySerializer(); $this->entityManager = $this->configuration->getEntityManager(); $this->unitOfWork = new UnitOfWork($this); }
/** * Get the fully qualified class-name from the namespace alias. * * @param string $namespaceAlias * @param string $simpleClassName * * @return string */ protected function getFqcnFromAlias($namespaceAlias, $simpleClassName) { $fullClassName = ''; $namespaces = $this->config->getEntityNamespaces(); if (!empty($namespaces[$namespaceAlias])) { $fullClassName = $namespaces[$namespaceAlias] . '\\Entity\\' . $simpleClassName; } return $fullClassName; }
public static function get() { //Entity loader $entities = Config::getEntityNamespacePath(); //Annotation metadata driver $config = new Configuration(); $md = $config->newDefaultAnnotationDriver(array($entities['path'])); $config->setMetadataDriverImpl($md); $config->setMetadataCacheImpl(new ArrayCache()); //Set and configure preferred serializer for persistence //If using serialaztion groups you can sepcify the names here $config->setEntitySerializer(new JMSSerializer(SerializationContext::create()->setGroups('store'))); //Add event listeners here $eventManager = new EventManager(); //$eventManager->addEventListener('prePersist', $listener); //Create the client $client = new Client(array('connections' => Config::getServers())); //Get the search manager return new SearchManager($config, new ElasticaAdapter($client), $eventManager); }
/** * (non-PHPdoc) * * @see \Zend\ServiceManager\FactoryInterface::createService() * * @return \Doctrine\Search\SearchManager */ public function createService(ServiceLocatorInterface $serviceLocator) { $this->setServiceLocator($serviceLocator); $config = $serviceLocator->get('Config'); $clientConfig = isset($config['elastica']['clients']) ? $config['elastica']['clients'] : []; $entityConfig = isset($config['elastica']['entities']) ? $config['elastica']['entities'] : ['paths' => []]; $indicesConfig = isset($config['elastica']['indices']) ? $config['elastica']['indices'] : []; $serializationGroups = isset($config['elastica']['serialization']['groups']) ? $config['elastica']['serialization']['groups'] : []; $searchConfig = new Configuration(); $md = $searchConfig->newDefaultAnnotationDriver($entityConfig['paths']); $searchConfig->setMetadataDriverImpl($md); $searchConfig->setMetadataCacheImpl(new ArrayCache()); $serializationContext = SerializationContext::create(); $serializationContext->enableMaxDepthChecks()->setGroups($serializationGroups); $searchConfig->setEntitySerializer(new JMSSerializer($serializationContext)); $eventManager = new EventManager(); $searchManager = new SearchManager($searchConfig, new ElasticSearchClient(new ElasticaClient(['connections' => $clientConfig])), $eventManager); try { $client = $searchManager->getClient(); $metadatas = $searchManager->getMetadataFactory()->getAllMetadata(); // Create indexes and types foreach ($metadatas as $metadata) { $config = isset($indicesConfig[$metadata->index]['settings']) ? $indicesConfig[$metadata->index]['settings'] : []; if (!$client->getIndex($metadata->index)->exists()) { $client->createIndex($metadata->index, $config); } $client->createType($metadata); } } catch (\Exception $e) { $this->getFlashMessenger()->addErrorMessage($e->getMessage()); /* @var $logger \Zend\Log\Logger */ $logger = $serviceLocator->get('logger'); $logger->debug($e->getMessage()); } return $searchManager; }
public function testGetClassMetadataFactoryName() { $this->configuration = new Configuration(); $className = $this->configuration->getClassMetadataFactoryName(); $this->assertEquals($className, 'Doctrine\\Search\\Mapping\\ClassMetadataFactory'); }
/** * {@inheritDoc} */ protected function initialize() { $this->driver = $this->config->getMetadataDriverImpl(); $this->evm = $this->sm->getEventManager(); $this->initialized = true; }