Ejemplo n.º 1
0
 /**
  * Gets a cookie from the bag
  *
  * @param string $name
  * @return \Scene\Http\CookieInterface
  * @throws Exception
  */
 public function get($name)
 {
     if (is_string($name) === false) {
         throw new Exception('The cookie name must be string');
     }
     if (isset($this->_cookies[$name])) {
         return $this->_cookies[$name];
     }
     /**
      * Create the cookie if the it does not exist
      */
     $cookie = $this->_dependencyInjector->get("Scene\\Http\\Cookie", [$name]);
     $dependencyInjector = $this->_dependencyInjector;
     if (is_object($dependencyInjector)) {
         /**
          * Pass the DI to created cookies
          */
         $cookie->setDi($dependencyInjector);
         $encryption = $this->_useEncryption;
         /**
          * Enable encryption in the cookie
          */
         if ($encryption) {
             $cookie->useEncryption($encryption);
         }
     }
     $this->_cookies[$name] = $cookie;
     return $cookie;
 }
Ejemplo n.º 2
0
 /**
  * Returns the connection related to a collection
  *
  * @param \Scene\Mvc\CollectionInterface $collection
  * @return \MongoDB\Driver\Manage
  * @throws Exception
  */
 public function getConnection($collection)
 {
     if (!is_object($collection) || $collection instanceof CollectionInterface === false) {
         throw new Exception('A valid collection instance is required');
     }
     $service = 'mongo';
     $connectionService = $this->_connectionServices;
     if (is_array($connectionService)) {
         $entityName = get_class($collection);
         /**
          * Check if the collection has a custom connection service
          */
         if (isset($connectionService[$entityName])) {
             $service = $connectionService[$entityName];
         }
     }
     $dependencyInjector = $this->_dependencyInjector;
     if (!is_object($dependencyInjector)) {
         throw new Exception('A dependency injector container is required to obtain the services related to the ORM');
     }
     /**
      * Request the connection service from the DI
      */
     $connection = $this->_dependencyInjector->getShared($service);
     if (!is_object($connection)) {
         throw new Exception('Invalid injected connection service');
     }
     return $connection;
 }