/** * 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); }
/** * @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()); }
/** * 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); }
/** * 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!'); } }
/** * 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; }
/** * 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()); } }
/** * 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; }
/** * @expectedException LogicException */ public function testGetConfigInvalidArgumentException() { $app = new App(); $app->getConfig(); }
/** * Return requested action. */ public function getAction() { return $this->app->route()->getParams('action'); }
/** * Get magic method. * * @param mixed $key * @return mixed */ public function __get($key) { return $this->app->arrGet($key, $this->params); }
/** * Return current app ID. */ public function getAppId() { return $this->app->getId(); }