Exemplo n.º 1
0
 /**
  * @return string
  */
 public function getPath()
 {
     if ($this->path === null) {
         $this->path = Config::getString('hyperframework.logging.log_path', 'log' . DIRECTORY_SEPARATOR . 'app.log');
     }
     return $this->path;
 }
Exemplo n.º 2
0
 /**
  * @param int $statusCode
  * @param string $statusReasonPhrase
  * @param object $error
  * @param string $outputFormat
  * @return void
  */
 public function render($statusCode, $statusReasonPhrase, $error, $outputFormat = null)
 {
     $rootPath = Config::getString('hyperframework.web.error_view.root_path', '');
     if ($rootPath === '') {
         $rootPath = Config::getString('hyperframework.web.view.root_path', '');
         if ($rootPath === '') {
             $rootPath = 'views' . DIRECTORY_SEPARATOR . '_error';
         } else {
             $rootPath = FilePathCombiner::combine($rootPath, '_error');
         }
     }
     $files = [ViewPathBuilder::build($statusCode, $outputFormat), ViewPathBuilder::build('default', $outputFormat)];
     $rootPath = FileFullPathBuilder::build($rootPath);
     $path = null;
     foreach ($files as $file) {
         $file = FilePathCombiner::combine($rootPath, $file);
         if (file_exists($file)) {
             $path = $file;
             break;
         }
     }
     if ($path === null) {
         Response::setHeader('Content-Type: text/plain; charset=utf-8');
         echo $statusCode;
         if ((string) $statusReasonPhrase !== '') {
             echo ' ', $statusReasonPhrase;
         }
     } else {
         $view = ViewFactory::createView(['status_code' => $statusCode, 'status_reason_pharse' => $statusReasonPhrase, 'error' => $error]);
         $view->render($path);
     }
 }
 /**
  * @return void
  */
 protected function initializeToken()
 {
     $this->setToken($this->generateToken());
     $cookieDomain = Config::getString('hyperframework.web.csrf_protection.cookie_domain', '');
     if ($cookieDomain === '') {
         $cookieDomain = null;
     }
     Response::setCookie($this->getTokenName(), $this->getToken(), ['domain' => $cookieDomain]);
 }
 /**
  * @param string $name
  * @return array
  */
 protected function getConfig($name)
 {
     if ($this->config === null) {
         $this->config = ConfigFileLoader::loadPhp(Config::getString('hyperframework.db.config_path', 'db.php'));
     }
     if (isset($this->config[$name])) {
         return $this->config[$name];
     }
     if ($name === null) {
         return $this->config;
     }
     throw new ConfigException("Database connection config '{$name}' does not exist.");
 }
 /**
  * @return int
  */
 public function getLevel()
 {
     if ($this->level === null) {
         $name = Config::getString('hyperframework.logging.log_level', '');
         if ($name !== '') {
             $level = LogLevel::getCode($name);
             if ($level === null) {
                 throw new ConfigException("Log level '{$name}' is invalid, set using config " . "'hyperframework.logging.log_level'. " . "The available log levels are: " . "DEBUG, INFO, NOTICE, WARNING, ERROR, FATAL, OFF.");
             }
             $this->level = $level;
         } else {
             $this->level = LogLevel::INFO;
         }
     }
     return $this->level;
 }
 /**
  * @param string $name
  * @param string $outputFormat
  * @return string
  */
 public static function build($name, $outputFormat = null)
 {
     $result = str_replace('-', '_', $name);
     if (Config::getBool('hyperframework.web.view.filename.include_output_format', true)) {
         if ($outputFormat === null) {
             $outputFormat = Config::getString('hyperframework.web.view.default_output_format', 'html');
         }
         $outputFormat = (string) $outputFormat;
         if ($outputFormat !== '') {
             $result .= '.' . $outputFormat;
         }
     }
     $format = Config::getString('hyperframework.web.view.format', 'php');
     if ($format !== '') {
         $result .= '.' . $format;
     }
     return $result;
 }
Exemplo n.º 7
0
 public function testGetString()
 {
     $this->mockEngineMethod('getString')->with('name', 'default')->willReturn(true);
     $this->assertTrue(Config::getString('name', 'default'));
 }
 /**
  * @return string
  */
 private function getSubcommandConfigRootPath()
 {
     $folder = Config::getString('hyperframework.cli.subcommand_config_root_path');
     if ($folder === null) {
         $folder = 'subcommands';
     }
     return ConfigFileFullPathBuilder::build($folder);
 }
 /**
  * @param string $name
  * @return void
  */
 public function connect($name = null)
 {
     if ($name === null) {
         if ($this->defaultConnectionName === null) {
             $name = Config::getString('hyperframework.db.default_connection_name');
         } else {
             $name = $this->defaultConnectionName;
         }
     }
     if ($name === null) {
         if ($this->anonymousConnection !== null) {
             $this->connection = $this->anonymousConnection;
             return;
         }
     } else {
         if (isset($this->namedConnections[$name])) {
             $this->connection = $this->namedConnections[$name];
             return;
         }
     }
     $factory = $this->getConnectionFactory();
     $this->connection = $factory->createConnection($name);
     if ($name === null) {
         $this->anonymousConnection = $this->connection;
     } else {
         $this->namedConnections[$name] = $this->connection;
     }
 }
Exemplo n.º 10
0
 /**
  * @return string
  */
 private function getRootPath()
 {
     if ($this->rootPath === null) {
         $path = Config::getString('hyperframework.web.view.root_path', '');
         if ($path === '') {
             $path = 'views';
         }
         $this->rootPath = FileFullPathBuilder::build($path);
     }
     return $this->rootPath;
 }
Exemplo n.º 11
0
 /**
  * @return void
  */
 private function initializeBody()
 {
     $contentType = $this->getHeader('CONTENT_TYPE');
     if ($contentType === null) {
         $contentType = Config::getString('hyperframework.web.default_request_content_type');
     }
     if ($contentType !== null) {
         $contentType = strtolower(trim(explode(';', $contentType, 2)[0]));
         if ($_SERVER['REQUEST_METHOD'] === 'POST') {
             if ($contentType === 'application/x-www-form-urlencoded' || $contentType === 'multipart/form-data') {
                 $this->body = $_POST;
                 return;
             }
         }
         $this->body = $this->getRawBody();
         if ($contentType === 'application/x-www-form-urlencoded') {
             parse_str($this->body, $this->body);
         } elseif ($contentType === 'application/json') {
             $this->body = json_decode($this->body, true, 512, JSON_BIGINT_AS_STRING);
             if ($this->body === null) {
                 throw new BadRequestException('The request body is not a valid json.');
             }
         }
     } else {
         $this->body = $this->getRawBody();
     }
 }