Пример #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));
     }
 }
Пример #2
0
 /**
  * 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);
     }
 }
Пример #3
0
 /**
  * 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");
 }
Пример #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;
 }
Пример #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;
 }
Пример #6
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);
         }
     }
 }
Пример #7
0
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">
Пример #8
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);
 }
Пример #9
0
 public function testDisableRegistration()
 {
     Config::disableRegistration();
     /* modify user defined config */
     Config::set(2001, "XDD");
     $this->assertSame("string", Config::get(2001));
     Config::set(Config::KEY_FORCE_HTTPS, false);
     $this->assertTrue(Config::get(Config::KEY_FORCE_HTTPS));
     /* modify DIR_ROOT */
     Config::set(Config::KEY_DIR_ROOT, "/srv/www/88");
     $this->assertEquals("/srv/www", Config::get(Config::KEY_DIR_ROOT));
     /* modify Database pool 1 */
     Config::setDatabasePool(1, "mysql", "localhost", "3306", "MODIFIED", "", "db", "utf8");
     $expected1 = array(1 => "mysql", 2 => "localhost", 3 => "3306", 4 => "login", 5 => "", 6 => "db", 7 => "utf8");
     $actual1 = Config::getDatabasePool(1);
     $this->assertSame(array_diff($expected1, $actual1), array_diff($actual1, $expected1));
     /* add Database pool 4 */
     Config::setDatabasePool(4, "mysql", "localhost", "3306", "login4", "444", "db", "utf8");
     $this->assertNull(Config::getDatabasePool(4));
     /* modify Email pool 1 */
     Config::setEmailPool(1, "localhost", "25", "MODIFIED", "pass", true, "tls", "Test1");
     $expected2 = array(1 => "localhost", 2 => "25", 3 => "login", 4 => "pass", 5 => true, 6 => "tls", 7 => "Test1");
     $actual2 = Config::getEmailPool(1);
     $this->assertSame(array_diff($expected2, $actual2), array_diff($actual2, $expected2));
     /* add Email pool 4 */
     Config::setEmailPool(4, "localhost", "25", "login", "passWORD", true, "ssl", "Test3");
     $this->assertNull(Config::getDatabasePool(4));
 }
Пример #10
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));
 }