public function warmUp($cacheDir)
 {
     // we need the directory no matter the hydrator cache generation strategy.
     $hydratorCacheDir = $this->container->getParameter('doctrine_mongodb.odm.hydrator_dir');
     if (!file_exists($hydratorCacheDir)) {
         if (false === @mkdir($hydratorCacheDir, 0777, true)) {
             throw new \RuntimeException(sprintf('Unable to create the Doctrine Hydrator directory (%s)', dirname($hydratorCacheDir)));
         }
     } else {
         if (!is_writable($hydratorCacheDir)) {
             throw new \RuntimeException(sprintf('Doctrine Hydrator directory (%s) is not writable for the current system user.', $hydratorCacheDir));
         }
     }
     // if hydrators are autogenerated we don't need to generate them in the cache warmer.
     if ($this->container->getParameter('doctrine_mongodb.odm.auto_generate_hydrator_classes') === true) {
         return;
     }
     /* @var $registry \Doctrine\Common\Persistence\ManagerRegistry */
     $registry = $this->container->get('doctrine_mongodb');
     foreach ($registry->getManagers() as $dm) {
         /* @var $dm \Doctrine\ODM\MongoDB\DocumentManager */
         $classes = $dm->getMetadataFactory()->getAllMetadata();
         $dm->getHydratorFactory()->generateHydratorClasses($classes);
     }
 }
Пример #2
0
 /**
  * Initialize the router object.
  *
  * @param Container $container
  */
 public function __construct($container)
 {
     $this->container = $container;
     $this->request = new Request($container->get('request'));
     $this->response = new Response($this->request->getCallType(), $this->request->isUpload());
     $this->defaultAccess = $container->getParameter('direct.api.default_access');
     $this->session = $this->container->get('session')->get($container->getParameter('direct.api.session_attribute'));
 }
Пример #3
0
 /**
  * Return the resolved value of the given reference
  * @param  mixed $reference
  * @return mixed
  */
 public function resolve($reference)
 {
     if (!is_string($reference)) {
         return $reference;
     }
     $prefix = substr($reference, 0, 1);
     switch (1) {
         case $prefix === '@':
             return $this->container->get(substr($reference, 1));
         case $prefix === '%':
             return $this->container->getParameter(substr($reference, 1));
         case preg_match(static::CONTAINER_REGEXP, $reference, $matches):
             return $this->container;
         case preg_match(static::ENVIRONMENT_REGEXP, $reference, $matches):
             return getenv($matches[1]);
         case preg_match(static::CONSTANT_REGEXP, $reference, $matches):
             return constant($matches[1]);
         default:
             return $reference;
     }
 }
 /**
  *
  * @param Object $entity The entity
  * @param Blameable $blameable The blameable annotation
  * @param boolean $create
  */
 protected function updateEntity($entity, $blameable, $create = false)
 {
     if ($blameable->getUserClass() === NULL) {
         if ($this->container->hasParameter('pss.blameable.user_class')) {
             $blameable->setUserClass($this->container->getParameter('pss.blameable.user_class'));
         } else {
             throw new \InvalidArgumentException('You must define a "userClass" attribute or "user_class" config.');
         }
     }
     $user = $this->container->get('security.context')->getToken()->getUser();
     if ($user instanceof \Symfony\Component\Security\Core\User\UserInterface) {
         if (method_exists($user, 'getId')) {
             $userId = $user->getId();
         } else {
             $userId = $user->getUsername();
         }
     } else {
         $userId = NULL;
     }
     if ($create) {
         // save user class name?
         // $entity->setUserClass($blameable->getUserClass());
         $creatorSetter = 'set' . $blameable->getCreator();
         // Test to store the object or the id/username
         if ($this->container->getParameter('pss.blameable.store_object')) {
             $entity->{$creatorSetter}($user ? $user : null);
         } else {
             $entity->{$creatorSetter}($userId);
         }
     }
     $updaterSetter = 'set' . $blameable->getUpdater();
     // Test to store the object or the id/username
     if ($this->container->getParameter('pss.blameable.store_object')) {
         $entity->{$updaterSetter}($user ? $user : null);
     } else {
         $entity->{$updaterSetter}($userId);
     }
 }