Ejemplo n.º 1
0
 /**
  * Prepares the response object to return an HTTP Redirect response to the client.
  *
  * @param string  $route     The redirect destination like controller/action
  * @param boolean $permanent If permanent redirection or not.
  * @param boolean $exit
  */
 public function redirect($route, $permanent = false, $exit = true)
 {
     $url = Url::compute($route);
     Header::clear();
     $permanent === true ? Header::sendMovedPermanently() : Header::sendFound();
     Header::toLocation($url, $exit);
 }
Ejemplo n.º 2
0
 /**
  * Handle an exception and display the exception report.
  *
  * @param \Exception $exception
  * @param Logger     $logger
  * @param boolean    $exit
  */
 public static function exception(\Exception $exception, Logger $logger, $exit = true)
 {
     static::log($exception, $logger);
     ob_get_length() > 0 && ob_get_level() && ob_end_clean();
     if (Config::get('error.debug_info') === true) {
         echo static::format($exception, Sapi::isCli());
         if ($exit) {
             exit;
         }
     }
     if ($exception instanceof \Pimf\Controller\Exception || $exception instanceof \Pimf\Resolver\Exception) {
         Event::first('404', array($exception));
         Header::sendNotFound(null, $exit);
     } else {
         Event::first('500', array($exception));
         Header::sendInternalServerError(null, $exit);
     }
 }
Ejemplo n.º 3
0
 /**
  * Handle an exception and display the exception report.
  *
  * @param \Exception $exception
  * @param boolean    $exit
  */
 public static function exception(\Exception $exception, $exit = true)
 {
     static::log($exception);
     ob_get_length() > 0 and ob_get_level() and ob_end_clean();
     $conf = Registry::get('conf');
     if (isset($conf['error']['debug_info']) && $conf['error']['debug_info'] === true) {
         echo static::format($exception);
         if ($exit) {
             exit;
         }
     }
     Header::clear();
     if ($exception instanceof \Pimf\Controller\Exception || $exception instanceof \Pimf\Resolver\Exception) {
         Event::first('404', array($exception));
         Header::sendNotFound(null, $exit);
     } else {
         Event::first('500', array($exception));
         Header::sendInternalServerError(null, $exit);
     }
 }
Ejemplo n.º 4
0
 /**
  * @param array $server
  * @param $tmpPath
  * @param string $logging
  */
 private static function setupUtils(array $server, $tmpPath, $logging = 'file')
 {
     self::$env = new Environment($server);
     $envData = self::$env->data();
     Logger::setup(self::$env->getIp(), $envData->get('PHP_SELF', $envData->get('SCRIPT_NAME')));
     ResponseStatus::setup($envData->get('SERVER_PROTOCOL', 'HTTP/1.0'));
     Header::setup(self::$env->getUserAgent());
     Url::setup(self::$env->getUrl(), self::$env->isHttps());
     Uri::setup(self::$env->PATH_INFO, self::$env->REQUEST_URI);
     Uuid::setup(self::$env->getIp(), self::$env->getHost());
     if ($logging === 'file') {
         self::$logger = new Logger(new Adapter\File($tmpPath, "pimf-logs.txt"), new Adapter\File($tmpPath, "pimf-warnings.txt"), new Adapter\File($tmpPath, "pimf-errors.txt"));
     } else {
         self::$logger = new Logger(new Adapter\Std(Adapter\Std::OUT), new Adapter\Std(Adapter\Std::OUT), new Adapter\Std(Adapter\Std::ERR));
     }
     self::$logger->init();
 }
Ejemplo n.º 5
0
 /**
  * @throws \RuntimeException
  */
 private function preventMultipleCaching()
 {
     if ($this->method != 'GET') {
         Header::clear();
         throw new \RuntimeException('HTTP cache headers can only take effect if request was sent via GET method!');
     }
     if (self::$cached === true) {
         Header::clear();
         throw new \RuntimeException('only one HTTP cache-control can be sent!');
     }
 }
<?php

/*
|--------------------------------------------------------------------------
| PIMF core bootstrap used for unit testing
|--------------------------------------------------------------------------
*/
if (!defined('DS')) {
    define('DS', DIRECTORY_SEPARATOR);
}
if (!defined('BASE_PATH')) {
    define('BASE_PATH', realpath(__DIR__) . DS);
}
require_once 'autoload.core.php';
require_once 'utils.php';
\Pimf\Config::load(array('environment' => 'testing', 'timezone' => 'UTC', 'ssl' => false, 'app' => array('name' => 'MyFirstBlog', 'key' => 'some5secret5key5here', 'default_controller' => 'blog', 'routeable' => true, 'restfull' => false, 'url' => 'http://localhost', 'index' => '', 'asset_url' => ''), 'production' => array('db' => array('driver' => 'sqlite', 'database' => 'app/MyFirstBlog/_database/blog-production.db')), 'testing' => array('db' => array('driver' => 'sqlite', 'database' => 'app/MyFirstBlog/_database/blog-production.db')), 'bootstrap' => array('local_temp_directory' => '/tmp/'), 'error' => array('ignore_levels' => array(0), 'debug_info' => true, 'log' => true), 'logging' => array('storage' => 'file'), 'session' => array('storage' => 'memory', 'storage_path' => 'app/MyFirstBlog/_session/', 'database' => array('driver' => 'sqlite', 'database' => 'app/MyFirstBlog/_session/blog-session.db'), 'garbage_collection' => array(2, 100), 'lifetime' => 60, 'expire_on_close' => false, 'cookie' => 'pimf_session', 'path' => '/', 'domain' => null, 'secure' => false), 'cache' => array('storage' => 'memory', 'storage_path' => 'app/MyFirstBlog/_cache/', 'database' => array('driver' => 'sqlite', 'database' => 'app/MyFirstBlog/_cache/blog-cache.db'), 'key' => 'pimfmaster', 'memcached' => array('servers' => array('host' => '127.0.0.1', 'port' => 11211, 'weight' => 100)))));
$env = new \Pimf\Environment($_SERVER);
$envData = $env->data();
\Pimf\Logger::setup($env->getIp(), $envData->get('PHP_SELF', $envData->get('SCRIPT_NAME')));
\Pimf\Util\Header\ResponseStatus::setup($envData->get('SERVER_PROTOCOL', 'HTTP/1.0'));
\Pimf\Util\Header::setup($env->getUserAgent());
\Pimf\Url::setup($env->getUrl(), $env->isHttps());
\Pimf\Uri::setup($env->PATH_INFO, $env->REQUEST_URI);
\Pimf\Util\Uuid::setup($env->getIp(), $env->getHost());
unset($env, $envData);
Ejemplo n.º 7
0
 /**
  * Handles setting pages that are always to be revalidated for freshness by any cache.
  *
  * @param int $last_modified Timestamp in seconds
  *
  * @return $this
  */
 public function exitIfNotModifiedSince($last_modified)
 {
     self::preventMultipleCaching();
     self::$cached = true;
     Header::exitIfNotModifiedSince($last_modified);
     return $this;
 }