public function setUp() { $manifest = new Manifest(['models' => [__NAMESPACE__ . '\\TestAsset\\Document' => __DIR__ . '/TestAsset/Document'], 'extension_configs' => ['extension.state' => true, 'extension.odmcore' => true]]); $this->documentManager = $manifest->getServiceManager()->get('modelmanager'); $eventManager = $this->documentManager->getEventManager(); $eventManager->addEventListener(Events::BAD_STATE, $this); }
public function testMultipleConnections() { $manifest1 = new Manifest(['models' => [__NAMESPACE__ . '\\TestAsset\\Document' => __DIR__ . '/TestAsset/Document'], 'extension_configs' => ['extension.odmcore' => ['default_db' => 'shard-phpunit-1']]]); $manifest2 = new Manifest(['models' => [__NAMESPACE__ . '\\TestAsset\\Document' => __DIR__ . '/TestAsset/Document'], 'extension_configs' => ['extension.odmcore' => ['default_db' => 'shard-phpunit-2']]]); $documentManager1 = $manifest1->getServiceManager()->get('modelmanager'); $documentManager2 = $manifest2->getServiceManager()->get('modelmanager'); $album1 = new Album('Ivy and the big apples'); $album2 = new Album('Guide to better living'); $documentManager1->persist($album1); $documentManager2->persist($album2); $documentManager1->flush(); $documentManager2->flush(); $albums1 = $documentManager1->getRepository(get_class($album1))->findAll(); $this->assertCount(1, $albums1); $this->assertEquals('Ivy and the big apples', $albums1[0]->getName()); $albums2 = $documentManager2->getRepository(get_class($album2))->findAll(); $this->assertCount(1, $albums2); $this->assertEquals('Guide to better living', $albums2[0]->getName()); //cleanup $collections = $documentManager1->getConnection()->selectDatabase('shard-phpunit-1')->listCollections(); foreach ($collections as $collection) { $collection->remove(); } $collections = $documentManager2->getConnection()->selectDatabase('shard-phpunit-2')->listCollections(); foreach ($collections as $collection) { $collection->remove(); } }
public function setUp() { $manifest = new Manifest(['models' => [__NAMESPACE__ . '\\TestAsset\\Document' => __DIR__ . '/TestAsset/Document'], 'extension_configs' => ['extension.serializer' => true, 'extension.odmcore' => true]]); $this->documentManager = $manifest->getServiceManager()->get('modelmanager'); $this->serializer = $manifest->getServiceManager()->get('serializer'); $this->unserializer = $manifest->getServiceManager()->get('unserializer'); }
public function testMergedConfig() { $db = 'zoop-shard-test'; $manifest = new Manifest(['extension_configs' => ['extension.serializer' => true, 'extension.odmcore' => ['default_db' => $db]]]); /* @var $core CoreExtension */ $core = $manifest->getServiceManager()->get('extension.odmcore'); $this->assertEquals($db, $core->getDefaultDb()); }
public function setUp() { $manifest = new Manifest(['models' => [__NAMESPACE__ . '\\TestAsset\\Document' => __DIR__ . '/TestAsset/Document'], 'extension_configs' => ['extension.serializer' => ['type_serializers' => ['string' => 'stringTypeSerializer']], 'extension.odmcore' => true]]); $manifest->getServiceManager()->setInvokableClass('stringTypeSerializer', 'Zoop\\Shard\\Test\\Serializer\\TestAsset\\StringSerializer'); $this->documentManager = $manifest->getServiceManager()->get('modelmanager'); $this->serializer = $manifest->getServiceManager()->get('serializer'); $this->unserializer = $manifest->getServiceManager()->get('unserializer'); }
public function setUp() { $manifest = new Manifest(['models' => [__NAMESPACE__ . '\\TestAsset\\Document' => __DIR__ . '/TestAsset/Document'], 'extension_configs' => ['extension.serializer' => true, 'extension.validator' => true, 'extension.odmcore' => true], 'service_manager_config' => ['factories' => ['user' => function () { $user = new User(); return $user; }]]]); $this->documentManager = $manifest->getServiceManager()->get('modelmanager'); }
public function setUp() { $manifest = new Manifest(['models' => [__NAMESPACE__ . '\\TestAsset\\Document' => __DIR__ . '/TestAsset/Document'], 'extension_configs' => ['extension.crypt' => true, 'extension.validator' => true, 'extension.odmcore' => true], 'service_manager_config' => ['invokables' => ['testkey' => 'Zoop\\Shard\\Test\\Crypt\\TestAsset\\Key']]]); $this->documentManager = $manifest->getServiceManager()->get('modelmanager'); $this->blockCipherHelper = $manifest->getServiceManager()->get('crypt.blockcipherhelper'); $eventManager = $this->documentManager->getEventManager(); $eventManager->addEventListener(Events::INVALID_MODEL, $this); $this->calls = []; }
public function setUp() { $manifest = new Manifest(['models' => [__NAMESPACE__ . '\\TestAsset\\Document' => __DIR__ . '/TestAsset/Document'], 'extension_configs' => ['extension.accesscontrol' => true, 'extension.owner' => true, 'extension.odmcore' => true], 'service_manager_config' => ['factories' => ['user' => function () { $user = new RoleAwareUser(); $user->setUsername('toby'); return $user; }]]]); $this->documentManager = $manifest->getServiceManager()->get('modelmanager'); }
public function setUp() { $manifest = new Manifest(['service_manager_config' => ['factories' => ['user' => function () { $user = new RoleAwareUser(); $user->setUsername('toby'); return $user; }]]]); $this->user = $manifest->getServiceManager()->get('user'); }
public function setUp() { $manifest = new Manifest(['models' => [__NAMESPACE__ . '\\TestAsset\\Document' => __DIR__ . '/TestAsset/Document'], 'extension_configs' => ['extension.crypt' => true, 'extension.odmcore' => true], 'service_manager_config' => ['invokables' => ['testkey' => 'Zoop\\Shard\\Test\\Crypt\\TestAsset\\Key'], 'factories' => ['user' => function () { $user = new User(); $user->setUsername('toby'); return $user; }]]]); $this->documentManager = $manifest->getServiceManager()->get('modelmanager'); $this->blockCipherHelper = $manifest->getServiceManager()->get('crypt.blockcipherhelper'); }
protected function getManifestServiceLocator($manifestName, $serviceLocator) { if (!isset($this->manifestSLs[$manifestName])) { $config = $serviceLocator->get('config')['zoop']['shard']['manifest']; if (isset($config[$manifestName])) { $manifestSL = Manifest::createServiceManager($config[$manifestName]['service_manager_config']); $manifest = new Manifest($config[$manifestName]); $manifest->setName($manifestName); $manifest->setServiceManager($manifestSL); $manifestSL->setService('manifest', $manifest); $manifestSL->addPeeringServiceManager($serviceLocator); $this->manifestSLs[$manifestName] = $manifestSL; } else { return null; } } return $this->manifestSLs[$manifestName]; }
public function setUp() { $manifest = new Manifest(['models' => [__NAMESPACE__ . '\\TestAsset\\Document' => __DIR__ . '/TestAsset/Document'], 'extension_configs' => ['extension.validator' => true, 'extension.odmcore' => true]]); $this->documentManager = $manifest->getServiceManager()->get('modelmanager'); $eventManager = $this->documentManager->getEventManager(); $eventManager->addEventListener(Events::INVALID_MODEL, $this); $this->calls = []; $user = new User(); $user->setUsername('josh'); $profile = new Profile('crimson', 'ronin'); $country = new Country('Australia'); $profile->setCountry($country); $user->setProfile($profile); $user->addGroup(new Group('bce')); $user->addGroup(new Group('zoop')); $this->documentManager->persist($user); $this->documentManager->flush(); $this->id = $user->getId(); $this->documentManager->clear(); }
/** * * @param \Zend\ModuleManager\ModuleEvent $event */ public function onConfigMerge(ModuleEvent $event) { $config = $event->getConfigListener()->getMergedConfig(false); foreach ($config['zoop']['shard']['manifest'] as $name => $manifestConfig) { if (!isset($manifestConfig['initalized']) || !$manifestConfig['initalized']) { $modelManager = $manifestConfig['model_manager']; unset($manifestConfig['model_manager']); $manifest = new Manifest($manifestConfig); $manifestConfig = $manifest->toArray(); $manifestConfig['model_manager'] = $modelManager; $config['zoop']['shard']['manifest'][$name] = $manifestConfig; $dmConfig =& $this->getSubConfig($config, $modelManager); //inject filter config $configurationConfig =& $this->getSubConfig($config, $dmConfig['configuration']); foreach ($manifest->getServiceManager()->get('extension.odmcore')->getFilters() as $filterName => $filterClass) { $configurationConfig['filters'][$filterName] = $filterClass; } //inject models $driverConfig =& $this->getSubConfig($config, $configurationConfig['driver']); $count = 0; foreach ($manifest->getModels() as $namespace => $path) { $driverConfig['drivers'][$namespace] = 'doctrine.driver.shard' . $name . $count; $config['doctrine']['driver']['shard' . $name . $count] = ['class' => 'Doctrine\\ODM\\MongoDB\\Mapping\\Driver\\AnnotationDriver', 'paths' => [$path]]; $count++; } //inject subscribers $eventManagerConfig =& $this->getSubConfig($config, $dmConfig['eventmanager']); foreach ($manifest->getSubscribers() as $subscriber) { $eventManagerConfig['subscribers'][] = 'shard.' . $name . '.' . $subscriber; } //make sure the Zoop/Shard/Core/ModuleManagerDelegator gets called $delegatorConfig = ['delegators' => [$modelManager => ['shard.' . $name . '.modelmanager.delegator.factory']]]; if (isset($config['service_manager'])) { $config['service_manager'] = ArrayUtils::merge($config['service_manager'], $delegatorConfig); } else { $config['service_manager'] = $delegatorConfig; } } } $event->getConfigListener()->setMergedConfig($config); }
public function testCustomExtensionLoad() { $manifest = new Manifest(['extension_configs' => ['extension.custom' => true], 'service_manager_config' => ['factories' => ['extension.custom' => 'Zoop\\Shard\\Test\\TestAsset\\CustomExtension\\ExtensionFactory']]]); $extension = $manifest->getServiceManager()->get('extension.custom'); $this->assertEquals('extension loaded', $extension->getMessage()); }
public function setUp() { $manifest = new Manifest(['models' => [__NAMESPACE__ . '\\TestAsset\\Document' => __DIR__ . '/TestAsset/Document'], 'extension_configs' => ['extension.crypt' => true, 'extension.odmcore' => true], 'service_manager_config' => ['invokables' => ['testsalt' => 'Zoop\\Shard\\Test\\Crypt\\TestAsset\\Salt']]]); $this->documentManager = $manifest->getServiceManager()->get('modelmanager'); $this->hashHelper = $manifest->getServiceManager()->get('crypt.hashhelper'); }