Пример #1
0
 /**
  * Return session specific config based on the name.
  * Giving all session config instead if name is not provided.
  *
  * @param mixed $name
  */
 public function getConfig($name = null)
 {
     if (empty($name)) {
         return $this->config;
     }
     return $this->app->arrGet($name, $this->config);
 }
Пример #2
0
 /**
  * @expectedException RuntimeException
  */
 public function testControllerActionLogicException()
 {
     $app = new App(['timezone' => 'UTC'], 'test-action');
     $app->route()->setParam('controller', 'foo');
     $app->route()->setParam('action', '');
     $stub = $this->getMock(Controller::class, ['indexAction', 'controllerAction'], [$app]);
     $stub->method('controllerAction')->willReturn(true);
     $foo = new FooController($app);
     $this->assertEquals($stub->controllerAction(), $foo->testAction());
 }
Пример #3
0
 /**
  * Get the particular token value based on the key.
  * Return all params if key is not provided.
  *
  * @param mixed $key
  */
 public function getParams($key = null)
 {
     if (empty($key)) {
         return $this->params;
     }
     return $this->app->arrGet($key, $this->params, null);
 }
Пример #4
0
 /**
  * Connection class constructor.
  * 
  * @throws \InvalidArgumentException
  */
 public function __construct()
 {
     $this->app = App::getInstance();
     $this->dbConfig = $this->getDatabaseConfig();
     if (empty($this->dbConfig)) {
         throw new \InvalidArgumentException('Database configuration is empty!');
     }
 }
Пример #5
0
 /**
  * Http caching with last modified by providing UNIX timestamp.
  *
  * @param  mixed $timestamp
  * @return \Avenue\Response
  */
 public function withLastModified($timestamp)
 {
     $this->withHeader(['Last-Modified' => $this->getGmtDateTime($timestamp)]);
     $httpIfModifiedSince = $this->app->request()->getHeader('If-Modified-Since');
     if (strtotime($httpIfModifiedSince) === $timestamp) {
         $this->setCacheStatus();
     }
     return $this;
 }
Пример #6
0
 /**
  * Establish database connection via PDO instance with config.
  *
  * @param  array  $config
  * @return object
  */
 public function createPdo(array $config)
 {
     try {
         extract(array_merge($this->config, $config));
         // replace with user's driver option, if any
         $options = array_replace($this->config['options'], $this->app->arrGet('options', $config, []));
         return new PDO($dsn, $username, $password, $options);
     } catch (\PDOException $e) {
         throw new \RuntimeException($e->getMessage(), $e->getCode());
     }
 }
Пример #7
0
 /**
  * Verify cookie signature and return value.
  *
  * @param  mixed $key
  * @param  mixed $value
  * @return mixed
  */
 protected function verify($key, $value)
 {
     if (strpos($value, static::DELIMITER) !== false) {
         list($hashed, $value) = explode(static::DELIMITER, $value, 2);
         // return cookie value if signature is valid
         if ($this->app->hashedCompare($this->hashing($key, $value), $hashed)) {
             return $value;
         }
     }
     // remove the tempered cookie if not valid
     $this->remove($key);
     return null;
 }
Пример #8
0
 /**
  * @expectedException LogicException
  */
 public function testGetConfigInvalidArgumentException()
 {
     $app = new App();
     $app->getConfig();
 }
Пример #9
0
 /**
  * Return requested action.
  */
 public function getAction()
 {
     return $this->app->route()->getParams('action');
 }
Пример #10
0
 /**
  * Get magic method.
  *
  * @param  mixed $key
  * @return mixed
  */
 public function __get($key)
 {
     return $this->app->arrGet($key, $this->params);
 }
Пример #11
0
 /**
  * Return current app ID.
  */
 public function getAppId()
 {
     return $this->app->getId();
 }