Esempio n. 1
0
 public function hydrate(Jarvis $app)
 {
     $app['doctrine.cache'] = function () {
         return new VoidCache();
     };
     $app['doctrine.annotation.driver'] = function () {
         return new AnnotationDriver(new AnnotationReader());
     };
     $app['entyMgr'] = function (Jarvis $app) : EntityManagerInterface {
         $settings = $app['doctrine.settings'];
         $cache = $app['doctrine.cache'];
         $config = Setup::createConfiguration($settings['debug'], $settings['proxies_dir'], $cache);
         $driver = $app['doctrine.annotation.driver'];
         if (isset($settings['entities_paths'])) {
             $driver->addPaths((array) $settings['entities_paths']);
         }
         AnnotationRegistry::registerLoader('class_exists');
         $config->setMetadataDriverImpl($driver);
         $config->setAutoGenerateProxyClasses($settings['debug']);
         $config->setMetadataCacheImpl($cache);
         $config->setResultCacheImpl($cache);
         $config->setQueryCacheImpl($cache);
         $entyMgr = EntityManager::create($settings['dbal'], $config);
         if (isset($app['doctrine.orm.entyMgr.decorator']) && is_string($fqcn = $app['doctrine.orm.entyMgr.decorator']) && is_subclass_of($fqcn, EntityManagerDecorator::class)) {
             $entyMgr = new $fqcn($entyMgr);
         }
         $entyMgr->getEventManager()->addEventListener([Events::preRemove, Events::postRemove, Events::prePersist, Events::postPersist, Events::preUpdate, Events::postUpdate, Events::postLoad, Events::preFlush, Events::onFlush, Events::postFlush, Events::onClear], new EventListener($app));
         $app->broadcast(DoctrineReadyEvent::READY_EVENT, new DoctrineReadyEvent($entyMgr));
         return $entyMgr;
     };
     $app['db_conn'] = function ($app) {
         $app['entyMgr']->getConnection();
     };
     $app->lock(['entyMgr', 'db_conn', 'doctrine.annotation.driver']);
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function hydrate(Jarvis $app)
 {
     $app['twig'] = function (Jarvis $app) : \Twig_Environment {
         $settings = array_merge(['auto_reload' => true, 'debug' => $app['debug'], 'strict_variables' => true], (array) ($app['twig.settings'] ?? []));
         if (!isset($settings['templates_paths'])) {
             throw new \LogicException('Parameter `templates_paths` is missing to configure Twig.');
         }
         $twig = new \Twig_Environment(new \Twig_Loader_Filesystem($settings['templates_paths']), $settings);
         $app->broadcast(TwigReadyEvent::READY_EVENT, new TwigReadyEvent($twig));
         return $twig;
     };
     $app->lock('twig');
 }
 /**
  * @expectedException \LogicException
  * @expectedMessageException Permanent event cannot be broadcasted multiple times.
  */
 public function testForbidPermanentEventMultiBroadcast()
 {
     $app = new Jarvis();
     $permanentEvent = new PermanentEvent();
     $name = 'permanent.event';
     $app->broadcast($name, $permanentEvent);
     $app->broadcast($name, $permanentEvent);
 }