Example #1
0
 /**
  * Send this response object to output.
  */
 public function send()
 {
     $e = $this->getException();
     $tpd = $this->template_data;
     // variable $tpd is accessible in each template file
     if (is_null($e) || $e instanceof NoticeException || $e instanceof WarningException) {
         $templates_path = sprintf("%s/", Config::getAbsoluteFolderPath(Config::KEY_DIR_APP_TEMPLATES));
         // include Master header template
         if (!empty($templates_path) && is_file($templates_path . self::HEADER_TEMPLATE_FILE)) {
             include $templates_path . self::HEADER_TEMPLATE_FILE;
         }
         // make exception box
         if (!is_null($e)) {
             echo $this->getExceptionBox();
         }
         // make content (only for null or Notice exception)
         if ((is_null($e) || $e instanceof NoticeException) && !empty($this->template_file) && is_file($templates_path . $this->template_file)) {
             include $templates_path . $this->template_file;
         }
         // include Master footer template
         if (!empty($templates_path) && is_file($templates_path . self::FOOTER_TEMPLATE_FILE)) {
             include $templates_path . self::FOOTER_TEMPLATE_FILE;
         }
     } else {
         System::redirect(Config::get(Config::KEY_SITE_FQDN) . Config::get(Config::KEY_SHUTDOWN_PAGE));
     }
 }
 /**
  * Frontcontroller constructor.
  * It performs dispatching user request and runs the controller action.
  *
  * @param Phoenix\Core\Database $db            
  * @param Phoenix\Http\Request $request            
  * @return void
  */
 public function __construct(Database $db, Request $request)
 {
     $this->response = null;
     try {
         if ($db->getStatus() !== true) {
             throw new FailureException(FrameworkExceptions::F_DB_UNABLE_CONNECT);
         }
         $this->db = $db;
         $this->request = $request;
         $this->response_format = $this->request->getUrl()->getQueryParameter(self::URL_GET_FORMAT);
         $this->router = RouterFactory::createRouter(Config::get(Config::KEY_APP_USE_ROUTER));
         $this->dispatch();
         $this->performControllerAction();
     } catch (NoticeException $e) {
         $this->response = ResponseFactory::createResponse($this->response_format);
         $this->response->setException($e);
     } catch (WarningException $e) {
         Logger::log($e, $this->db);
         $this->response = ResponseFactory::createResponse($this->response_format);
         $this->response->setException($e);
     } catch (FailureException $e) {
         Logger::log($e);
         $this->response = ResponseFactory::createResponse($this->response_format);
         $this->response->setException($e);
     } catch (Exception $e) {
         Logger::log($e);
         $this->response = ResponseFactory::createResponse($this->response_format);
         $this->response->setException($e);
     }
 }
 /**
  * Register App Configuration into Config object.
  *
  * @return void
  */
 protected final function registerConfiguration()
 {
     Config::set(Config::KEY_SITE_FQDN, "http://localhost/phoenix/www");
     Config::set(Config::KEY_SITE_BASE, "/phoenix/");
     Config::set(Config::KEY_FORCE_HTTPS, false);
     Config::set(Config::KEY_APP_EXCEPTION_MODULE_NAME, ED::getModuleName());
     Config::set(Config::KEY_APP_USE_ROUTER, RouterFactory::SIMPLE_ROUTER);
     Config::setDatabasePool(Config::get(Config::KEY_DB_PRIMARY_POOL), "mysql", "localhost", "3306", "phoenix", "phoenix", "phoenix", "utf8");
 }
Example #4
0
 /**
  * Set Session value for given key.
  *
  * @param integer|string $key
  *            predefined constant Session::KEY_ (integer key); can be self defined string or integer constant (convention is integer grater than 1000)
  * @param mixed $value            
  * @return boolean
  */
 public static function set($key, $value)
 {
     if (!is_int($key) && !is_string($key)) {
         return false;
     }
     if (self::$registrationEnabled === true) {
         $_SESSION[Config::get(Config::KEY_SITE_FQDN)][$key] = $value;
         return true;
     }
     return false;
 }
Example #5
0
 /**
  * Request constructor.
  *
  * @throws Phoenix\Exceptions\FailureException
  * @param Url $url            
  * @param string $method            
  * @param string $post
  *            [optional] default null
  * @param string $files
  *            [optional] default null
  * @param string $cookies
  *            [optional] default null
  * @param string $headers
  *            [optional] default null
  * @param string $remote_address
  *            [optional] default null
  * @param string $remote_host
  *            [optional] default null
  * @return void
  */
 public function __construct(Url $url, $method, $post = null, $files = null, $cookies = null, $headers = null, $remote_address = null, $remote_host = null)
 {
     if (empty($method) || !is_string($method)) {
         throw new FailureException(FrameworkExceptions::F_REQUEST_INVALID_METHOD);
     }
     $this->url = $url;
     if (Config::get(Config::KEY_FORCE_HTTPS) === true && $this->isHttps() !== true) {
         throw new FailureException(FrameworkExceptions::F_REQUEST_FORCED_HTTPS);
     }
     $this->method = $method;
     $this->post = (array) $post;
     $this->files = (array) $files;
     $this->cookies = (array) $cookies;
     $this->headers = array_change_key_case((array) $headers, CASE_LOWER);
     $this->remote_address = $remote_address;
     $this->remote_host = $remote_host;
 }
Example #6
0
 /**
  * Connect to db server.
  *
  * @throws Phoenix\Exceptions\FailureException
  * @return void
  */
 private function connect()
 {
     $cp = Config::getDatabasePool($this->pool_id);
     try {
         if (empty($cp) || !is_array($cp)) {
             throw new PDOException();
         }
         $this->link = new PDO(sprintf("%s:host=%s:%d;dbname=%s;charset=%s", $cp[Config::DB_DRIVER], $cp[Config::DB_SERVER], $cp[Config::DB_PORT], $cp[Config::DB_SCHEMA], $cp[Config::DB_CHARSET]), $cp[Config::DB_LOGIN], $cp[Config::DB_PASSWORD]);
         $this->link->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         $this->status = true;
     } catch (PDOException $e) {
         $this->status = false;
         throw new FailureException(FX::F_DB_UNABLE_CONNECT);
     }
 }
Example #7
0
 /**
  * Resolve proxy request.
  *
  * @todo cache
  * @todo file download + condition
  * @throws Phoenix\Exceptions\WarningException
  */
 private function performProxyRequest()
 {
     $token = $this->request->getUrl()->getQueryParameter(FrontController::URL_GET_TOKEN);
     // @todo load from cache
     // load from db
     $proxy_item = ProxyDao::getProxyItemByValidToken($this->db, $token);
     if ($proxy_item == Database::EMPTY_RESULT) {
         throw new WarningException(FrameworkExceptions::W_INVALID_TOKEN);
     }
     $proxy_item = $proxy_item[0];
     // detect type of request
     if (is_null($proxy_item->getRoute()) && is_null($proxy_item->getAction()) && !is_null($proxy_item->getData())) {
         // external link to redirect on (data=url)
         System::redirect($proxy_item->getData());
     } else {
         if (!is_null($proxy_item->getRoute()) && !is_null($proxy_item->getAction())) {
             $config_route = Config::get(Config::KEY_APP_PROXY_FILE_ROUTE);
             $config_action = Config::get(Config::KEY_APP_PROXY_FILE_ACTION);
             if (!empty($config_route) && !empty($config_action) && $proxy_item->getRoute() == $config_route && $proxy_item->getAction() == $config_action && !is_null($proxy_item->getData())) {
                 // @todo file download
             } else {
                 // internal rewrite link to app (data=query string part of url saved as json)
                 $_GET = array();
                 $_GET[FrontController::URL_GET_ROUTE] = $proxy_item->getRoute();
                 $_GET[FrontController::URL_GET_ACTION] = $proxy_item->getAction();
                 $_GET[FrontController::URL_GET_FORMAT] = ${$this}->response_format;
                 if (!is_null($proxy_item->getData())) {
                     // decode json data and put into GET
                     $_GET = array_merge($_GET, json_decode($proxy_item->getData(), true));
                 }
                 $this->request = RequestFactory::createRequest();
                 $this->performFrontControllerRequest();
                 return;
             }
         } else {
             throw new WarningException(FrameworkExceptions::W_INVALID_TOKEN);
         }
     }
 }
use Phoenix\Core\Config;
use Phoenix\Locale\Translate;
/**
 * HTML page header template.
 *
 * @version 1.1
 * @author MPI
 *
 */
?>
<!DOCTYPE html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<base href="<?php 
echo htmlspecialchars(Config::get(Config::KEY_SITE_BASE));
?>
">
<title><?php 
?>
</title>
<meta name="description" content="<?php 
?>
">
<meta name="keywords" content="<?php 
?>
">
<meta name="author" content="<?php 
?>
">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
Example #9
0
 /**
  * Save exception into log file.
  *
  * @param \Exception $e
  *            exception object
  * @return void
  */
 public static function saveToFile(Exception $e)
 {
     $path = Config::getAbsoluteFolderPath(Config::KEY_DIR_LOG);
     $files = Files::findAllFiles($path, array(".", ".."));
     $out_file = $path;
     sort($files);
     $reg_files = array();
     foreach ($files as $file) {
         $r = explode("/", $file);
         if (preg_match("/^([0-9]+)\\.log\$/i", $r[1], $matches)) {
             $reg_files[$matches[1]] = filesize($file);
         }
     }
     $last = count($reg_files);
     if ($last > 0 && $reg_files[$last - 1] <= Config::get(Config::KEY_LOG_SIZE)) {
         $out_file .= "/" . ($last - 1) . ".log";
     } else {
         $out_file .= "/" . $last . ".log";
     }
     file_put_contents($out_file, sprintf("\n>> %s [%d] %s\n%s\n%s", get_class($e), $e->getCode(), date("Y-m-d H:i:s"), $e->getTraceAsString(), $e->getMessage()), FILE_APPEND | LOCK_EX);
 }
Example #10
0
 public function testDisabledRegistration()
 {
     $this->assertFalse(Config::isRegistrationEnabled());
 }
Example #11
0
 /**
  * Get translated message of exception.
  * 
  * @param integer $exception_key
  *            it is $code from Exception
  * @return string
  */
 public static final function getTranslatedMessage($exception_code)
 {
     return Translate::get(Config::get(Config::KEY_APP_EXCEPTION_MODULE_NAME), self::get($exception_code));
 }