/**
  * On kernel request action
  *
  * @param GetResponseEvent $event Event object
  *
  * @return void
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     $requester = new Requester($request);
     if ($requester->hasUsername()) {
         $this->blameableListener->setUserValue($requester);
     }
 }
 /**
  * @param EventManager           $manager
  * @param EntityManagerInterface $em
  * @param Reader                 $reader
  */
 public function addSubscribers(EventManager $manager, EntityManagerInterface $em, Reader $reader = null)
 {
     $subscriber = new BlameableListener();
     if ($this->guard->check()) {
         $subscriber->setUserValue($this->guard->user());
     }
     $this->addSubscriber($subscriber, $manager, $reader);
 }
 protected function setUp()
 {
     parent::setUp();
     $evm = new EventManager();
     $blameableListener = new BlameableListener();
     $blameableListener->setUserValue('testuser');
     $evm->addEventSubscriber($blameableListener);
     $this->getMockSqliteEntityManager($evm);
 }
Ejemplo n.º 4
0
 /**
  * Set the username from the security context by listening on core.request
  *
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     if (null === $this->securityContext) {
         return;
     }
     $token = $this->securityContext->getToken();
     if (null !== $token && $this->securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
         $this->blameableListener->setUserValue($token->getUser());
     }
 }
Ejemplo n.º 5
0
 protected function setUp()
 {
     parent::setUp();
     if (version_compare(PHP_VERSION, '5.4.0') < 0) {
         $this->markTestSkipped('PHP >= 5.4 version required for this test.');
     }
     $listener = new BlameableListener();
     $listener->setUserValue('testuser');
     $evm = new EventManager();
     $evm->addEventSubscriber($listener);
     $this->getMockSqliteEntityManager($evm);
 }
 /**
  * Set the username from the security context by listening on core.request
  *
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
         return;
     }
     if (null === $this->tokenStorage || null === $this->authorizationChecker) {
         return;
     }
     $token = $this->tokenStorage->getToken();
     if (null !== $token && $this->authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
         $this->blameableListener->setUserValue($token->getUser());
     }
 }
 protected function setUp()
 {
     parent::setUp();
     $user = new User();
     $user->setUsername(self::TEST_USERNAME);
     $listener = new BlameableListener();
     $listener->setUserValue($user);
     $evm = new EventManager();
     $evm->addEventSubscriber($listener);
     $manager = $this->getMockDocumentManager($evm);
     $manager->persist($user);
     $this->populate();
     $manager->flush();
 }
Ejemplo n.º 8
0
 /**
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     $em = ServiceUtil::get('doctrine.entitymanager');
     try {
         if (\System::isInstalling()) {
             $uid = 2;
         } else {
             $uid = UserUtil::getVar('uid');
         }
         $user = $em->getReference('ZikulaUsersModule:UserEntity', $uid);
         $this->blameableListener->setUserValue($user);
     } catch (\Exception $e) {
         // silently fail - likely installing and tables not available
     }
 }
Ejemplo n.º 9
0
 /**
  * {@inheritDoc}
  */
 public function setUserValue($user)
 {
     if (is_object($user) && $this->getUserClass() && !is_a($user, $this->getUserClass())) {
         throw new InvalidArgumentException(sprintf('User value must be an instance of %s; %s given', $this->getUserClass(), get_class($user)));
     }
     parent::setUserValue($user);
 }
Ejemplo n.º 10
0
 function __construct(AuthenticationService $authService)
 {
     $this->authService = $authService;
     parent::__construct();
 }
Ejemplo n.º 11
0
 /**
  *
  * @return EntityManager
  */
 public function getEntityManager()
 {
     $cache = new DoctrineCache\ArrayCache();
     $annotationReader = new AnnotationReader();
     $cachedAnnotationReader = new CachedReader($annotationReader, $cache);
     // create a driver chain for metadata reading
     $driverChain = new MappingDriverChain();
     // load superclass metadata mapping only, into driver chain
     // also registers Gedmo annotations.NOTE: you can personalize it
     Gedmo\DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($driverChain, $cachedAnnotationReader);
     // now we want to register our application entities,
     // for that we need another metadata driver used for Entity namespace
     $annotationDriver = new AnnotationDriver($cachedAnnotationReader, $this->paths);
     $driverChain->addDriver($annotationDriver, $this->namespace);
     // general ORM configuration
     $isDevMode = $this->env != "production";
     $config = DoctrineSetup::createAnnotationMetadataConfiguration($this->paths, $isDevMode);
     $config->setMetadataCacheImpl($cache);
     $config->setQueryCacheImpl($cache);
     $config->setMetadataDriverImpl($driverChain);
     $config->setProxyDir($this->proxy_path);
     $config->setProxyNamespace($this->namespace . '\\Proxy');
     $config->setAutoGenerateProxyClasses($isDevMode);
     // Third, create event manager and hook prefered extension listeners
     $evm = new EventManager();
     // gedmo extension listeners
     // sluggable
     $sluggableListener = new Gedmo\Sluggable\SluggableListener();
     // you should set the used annotation reader to listener, to avoid creating new one for mapping drivers
     $sluggableListener->setAnnotationReader($cachedAnnotationReader);
     $evm->addEventSubscriber($sluggableListener);
     // tree
     $treeListener = new Gedmo\Tree\TreeListener();
     $treeListener->setAnnotationReader($cachedAnnotationReader);
     $evm->addEventSubscriber($treeListener);
     // loggable, not used in example
     $loggableListener = new Gedmo\Loggable\LoggableListener();
     $loggableListener->setAnnotationReader($cachedAnnotationReader);
     $loggableListener->setUsername('unknown');
     $evm->addEventSubscriber($loggableListener);
     // timestampable
     $timestampableListener = new Gedmo\Timestampable\TimestampableListener();
     $timestampableListener->setAnnotationReader($cachedAnnotationReader);
     $evm->addEventSubscriber($timestampableListener);
     // blameable
     $blameableListener = new Gedmo\Blameable\BlameableListener();
     $blameableListener->setAnnotationReader($cachedAnnotationReader);
     $blameableListener->setUserValue('unknown');
     // determine from your environment
     $evm->addEventSubscriber($blameableListener);
     // translatable - buggy !!!
     /*
     $translatableListener = new Gedmo\Translatable\TranslatableListener();
     // current translation locale should be set from session or hook later into the listener
     // most important, before entity manager is flushed
     $translatableListener->setTranslatableLocale('en');
     $translatableListener->setDefaultLocale('en');
     $translatableListener->setAnnotationReader($cachedAnnotationReader);
     $evm->addEventSubscriber($translatableListener);
     */
     // sortable, not used in example
     $sortableListener = new Gedmo\Sortable\SortableListener();
     $sortableListener->setAnnotationReader($cachedAnnotationReader);
     $evm->addEventSubscriber($sortableListener);
     // mysql set names UTF-8 if required
     $evm->addEventSubscriber(new \Doctrine\DBAL\Event\Listeners\MysqlSessionInit());
     // Finally, create entity manager
     return EntityManager::create($this->dbParams, $config, $evm);
 }