/** * Bootstrap the application events. * * @return void */ public function boot() { $d2em = $this->app['d2embridge']; $d2cache = $this->app['d2cachebridge']; $d2em->getConfiguration()->setMetadataCacheImpl($d2cache); $d2em->getConfiguration()->setQueryCacheImpl($d2cache); $d2em->getConnection()->getConfiguration()->setResultCacheImpl($d2cache); if (isset($this->d2config['sqllogger']['enabled']) && $this->d2config['sqllogger']['enabled']) { $logger = new Logger\Laravel(); if (isset($this->d2config['sqllogger']['level'])) { $logger->setLevel($this->d2config['sqllogger']['level']); } $d2em->getConnection()->getConfiguration()->setSQLLogger($logger); } if (isset($this->d2config['auth']['enabled']) && $this->d2config['auth']['enabled']) { \Auth::extend('doctrine2bridge', function () { return new \Illuminate\Auth\Guard(new Auth\Doctrine2UserProvider(\D2EM::getRepository($this->d2config['auth']['entity']), new \Illuminate\Hashing\BcryptHasher()), \App::make('session.store')); }); } }
<?php // Assuming we have set the following in app/config/auth.php: // // 'driver' => 'doctrine2bridge' // this assumes no namespace: Auth::extend('doctrine2bridge', function () { return new \Illuminate\Auth\Guard(new \Doctrine2Bridge\Auth\Doctrine2UserProvider(D2EM::getRepository('\\Entities\\User'), new \Illuminate\Hashing\BcryptHasher()), App::make('session.store')); });
/** * Set up Laravel authentication via Doctrine2 provider */ private function setupAuth() { Auth::extend('doctrine2bridge', function () { return new \Illuminate\Auth\Guard(new \Doctrine2Bridge\Auth\Doctrine2UserProvider(\D2EM::getRepository(Config::get('d2bdoctrine.auth.entity')), new \Illuminate\Hashing\BcryptHasher()), \App::make('session.store')); }); }
/** * Convenience function for getting Doctrine2 repository instances * * @param string $entity The name of the entity to load the repository for * @param string $namespace The entities namespace * @return Doctrine\ORM\EntityRepository An instance of the repository */ function D2R($entity, $namespace = 'Entities') { return D2EM::getRepository($namespace . '\\' . $entity); }