コード例 #1
0
 /**
  * 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'));
     });
 }
コード例 #4
0
ファイル: d2r.php プロジェクト: opensolutions/doctrine2bridge
/**
 * 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);
}
コード例 #5
0
ファイル: WithPreferences.php プロジェクト: oss2/doctrine2
 /**
  * Delete the named preference
  *
  * WARNING: You need to EntityManager::flush() if the return > 0!
  *
  * @param string $name The named attribute / preference to check for
  * @param int $index default null If an indexed preference then delete a specific index, if null then delete all
  * @return int The number of preferences deleted
  */
 public function deleteAssocPreference($name, $index = null)
 {
     $count = 0;
     foreach ($this->getPreferences() as $pref) {
         if (strpos($pref->getName(), $name) === 0 && ($index === null || $pref->getIx() == $index)) {
             $this->getPreferences()->removeElement($pref);
             \D2EM::remove($pref);
             $count++;
         }
     }
     return $count;
 }