Example #1
0
 public function initConfig()
 {
     $this->config = \App\Core\Config::getInstance();
     $this->config->init(CONFIG_INI);
     $this->config->loadConfig(CONFIG_DIR);
     $this->config->loadHelpers(HELPER_DIR);
 }
Example #2
0
 /**
  * Protected constructor to prevent creating a new instance of the
  * *Services* via the `new` operator from outside of this class.
  */
 protected function __construct()
 {
     parent::__construct();
     $this->config = new Config();
     $this->input = new Input($this->config->get('config'));
     $this->output = new Output($this->config->get('mimes'));
     $router = new Router($this->config->get('routes'));
     $this->route = $router->route($this->input->uri());
 }
Example #3
0
 public function getLogout()
 {
     if (Auth::check()) {
         Session::delete(Config::get('session.name'));
     }
     return Redirect::to('/');
 }
Example #4
0
 /**
  * Constructs a page
  * @param array $config     contains standard configuration with items: js (array of URLs), css (array of URLs), and title (string), baseURL
  */
 public function __construct($config = array())
 {
     $this->js = array();
     $this->css = array();
     $this->menuitems = array();
     $this->title = "The DataTank";
     if (class_exists('\\app\\core\\Config')) {
         // Get root folder for building relative URLS for assets
         $this->baseURL = '/' . \app\core\Config::get('general', 'subdir') . PACKAGE_PATH;
         $this->baseURL = str_replace('//', '/', $this->baseURL);
     } else {
         // Assume the example file is served
         $this->baseURL = '../public/';
     }
     if (!empty($config)) {
         if (isset($config["js"])) {
             $this->js = $config["js"];
         }
         if (isset($config["css"])) {
             $this->css = $config["css"];
         }
         if (isset($config["title"])) {
             $this->title = $config["title"];
         }
         if (isset($config["baseURL"])) {
             $this->baseURL = $config["baseURL"];
         }
     }
     $this->mustache = new Mustache_Engine();
 }
Example #5
0
 public function getLogin()
 {
     if (Session::exists(Config::get('session.name'))) {
         return Redirect::to('/');
     }
     return view('auth.login');
 }
Example #6
0
 /**
  * Mengecek apakah token yang dikirimkan sama dengan token yang disimpan di session.
  *
  * @return string $token
  * @return bool
  */
 public static function match($token)
 {
     $token_name = Config::get('session.token_name');
     if (Session::exists($token_name) && $token === Session::get($token_name)) {
         Session::delete($token_name);
         return true;
     }
     return false;
 }
Example #7
0
 public function isAuthenticated($user)
 {
     if ($userconf = Config::get("auth", $user)) {
         // Fix for empty PHP_AUTH_USER
         if (!empty($_SERVER['Authorization'])) {
             list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':', base64_decode(substr($_SERVER['Authorization'], 6)));
         }
         return isset($_SERVER['PHP_AUTH_USER']) && $_SERVER['PHP_AUTH_USER'] == $user && $_SERVER['PHP_AUTH_PW'] == $userconf['password'];
     } else {
         return true;
     }
 }
Example #8
0
 public function testConfigClass()
 {
     // Regular config
     $config = array("general" => array("hostname" => "http://localhost.be", "subdir" => "", "cache" => array("system" => "MemCache", "port" => 50123)), "db" => array("host" => "localhost", "port" => 3366));
     Config::setConfig($config);
     $this->assertEquals($config, Config::getConfigArray(), "Config array doesn't match");
     $this->assertCount(3, Config::get('general'), "Number of items doesn't match");
     $this->assertEquals(3366, Config::get('db', 'port'), "First level value not matching");
     $this->assertEquals("MemCache", Config::get('general', 'cache', 'system'), "Second level value not matching");
     $this->assertEmpty(Config::get('general', 'cache', 'host'), "Non-existing key not returning empty value");
     // Empty array
     $config = array();
     Config::setConfig($config);
     $this->assertEquals($config, Config::getConfigArray(), "Config array doesn't match");
     $this->assertEmpty(Config::get('general'), "Previous config is still in the array");
 }
Example #9
0
 public function __construct()
 {
     // Define PDO instance
     if ($this->pdo === null) {
         try {
             $config = Config::getInstance();
             $dbConfig = $config->load('app')->get("database");
             $this->pdo = new PDO('mysql:dbname=' . $dbConfig['DB_DATABASE'] . ';host=' . $dbConfig['DB_HOST'], $dbConfig['DB_USERNAME'], $dbConfig['DB_PASSWORD']);
             // Set default fetch mode
             $this->pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
             // Set MySQL specific attributes
             if ($this->pdo->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql') {
                 $this->pdo->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES utf8");
             }
         } catch (\PDOException $exception) {
             throw new \Exception($exception->getMessage());
         }
     }
 }
Example #10
0
 public static function user()
 {
     return self::check() ? Session::get(Config::get('session.name')) : false;
 }
Example #11
0
File: glue.php Project: tdt/start
 /**
  * stick
  *
  * the main static function of the glue class.
  *
  * @param   array    	$urls  	    The regex-based url to class mapping
  * @throws  Exception               Thrown if corresponding class is not found
  * @throws  Exception               Thrown if no match is found
  * @throws  BadMethodCallException  Thrown if a corresponding GET,POST is not found
  *
  */
 static function stick($urls)
 {
     $method = strtoupper($_SERVER['REQUEST_METHOD']);
     $HTTPheaders = getallheaders();
     if (isset($HTTPheaders["X-HTTP-Method-Override"])) {
         $method = strtoupper($HTTPheaders["X-HTTP-Method-Override"]);
     }
     // Drop first slash
     $path = preg_replace('/^\\//', '', trim($_SERVER['REQUEST_URI']));
     $found = false;
     krsort($urls);
     // Logger configuration
     $exception_config = array();
     $exception_config["log_dir"] = Config::get("general", "logging", "path");
     $exception_config["url"] = Config::get("general", "hostname") . Config::get("general", "subdir") . "error";
     foreach ($urls as $regex => $class) {
         $classa = explode(".", $class);
         $class = $classa[0];
         // Check for a required user(s)
         preg_match("/\\|\\s*((?:@[^\\s]+?(?:\\s*,\\s*)?)*)\\s*\$/i", $regex, $user_string);
         if (isset($user_string[1])) {
             preg_match_all("/@([^\\s,]+)/i", $user_string[1], $users);
             $users = $users[1];
         } else {
             $users = null;
         }
         // Filter user from route
         $regex = preg_replace("/\\|\\s*((?:@[^\\s]+?(?:\\s*,\\s*)?)*)\\s*\$/i", "", $regex);
         // Drop first slash of route
         $regex = preg_replace('/^\\//', '', trim($regex));
         $regex = str_replace('/', '\\/', $regex);
         $regex = '^' . $regex . '\\/?$';
         if (preg_match("/{$regex}/i", $path, $matches)) {
             $found = true;
             if (class_exists($class)) {
                 if ($users) {
                     // Requires authentication
                     $match_autenticated = false;
                     $auth = null;
                     // Loop through allowed users, check if one is already authenticated
                     foreach ($users as $user) {
                         if ($userconf = Config::get("auth", $user)) {
                             $classname = "app\\auth\\" . $userconf['type'];
                             // Check if all users use the same authentication scheme
                             if ($auth != null && !$auth instanceof $classname) {
                                 // Users need same auth scheme for one route
                                 // TODO: show better error here
                                 throw new TDTException(551, array($path, $method), $exception_config);
                                 break;
                             } else {
                                 if ($auth == null) {
                                     $auth = new $classname();
                                 }
                             }
                             // Check authentication for this user
                             if ($auth->isAuthenticated($user)) {
                                 $match_autenticated = true;
                             }
                         }
                     }
                     // None matched => authenticate
                     if (!$match_autenticated) {
                         if ($auth) {
                             $auth->authenticate();
                         } else {
                             // Specified unexisting user as only authentication options
                             throw new TDTException(551, array($class), $exception_config);
                         }
                         exit;
                     }
                 }
                 $obj = new $class();
                 if (method_exists($obj, $method)) {
                     $obj->{$method}($matches);
                 } else {
                     throw new TDTException(450, array($path, $method), $exception_config);
                 }
             } else {
                 throw new TDTException(551, array($class), $exception_config);
             }
             break;
         }
     }
     if (!$found) {
         throw new TDTException(404, array($path), $exception_config);
     }
 }
Example #12
0
<?php

use App\Core\Session;
use App\Core\Config;
use App\Core\Redirect;
use App\Core\Middleware;
$middleware = new Middleware();
/**
 * Berhubung isu method next pada Middleware.
 * Sekarang hanya bisa menggunakan before middleware/filter. 
 * Note: Dikarenakan fungsi exit() pada helper view().
 */
$middleware->add('auth', function ($params) use($middleware) {
    // echo "auth <br>";
    if (!Session::exists(Config::get('session.name'))) {
        if (is_ajax()) {
            http_response_code(401);
            exit;
        } else {
            Redirect::route('get-login');
        }
    }
    $middleware->next($params);
});
$middleware->add('admin', function ($params) use($middleware) {
    // do something
    $middleware->next($params);
});
$middleware->add('something', function ($params) use($middleware) {
    // do something
    $middleware->next($params);
Example #13
0
<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
    <base href="<?php 
echo PUB;
?>
">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title><?php 
echo $site_title . ' - ' . \app\core\Config::get('site_name');
?>
</title>
    <meta name="description" content="<?php 
echo isset($site_description) ? $site_description : '';
?>
">
    <meta name="keywords" content="<?php 
echo isset($site_keywords) ? $site_keywords : '';
?>
">
    <meta name="viewport" content="width=device-width">

    <link rel="stylesheet" href="assets/css/bootstrap.min.css">
    <link rel="stylesheet" href="assets/css/bootstrap-responsive.min.css">
    <link rel="stylesheet" href="assets/css/font-awesome.min.css">
    <link rel="stylesheet" href="assets/css/main.css">
    <link rel="stylesheet" href="assets/css/sl-slide.css">
Example #14
0
<?php

use app\core\Config;
//If your website is in root, just leave it empty ''
Config::set('sub_folder', 'publicts3/');
Config::set('url', 'http://' . $_SERVER["HTTP_HOST"] . '/' . Config::get('sub_folder'));
Config::set('languages', ['cz', 'en']);
Config::set('site_name', 'PublicTS3');
Config::set('default_controller', 'home');
//This default action(method) is used for other controllers too. So if it doesn't exists - error appears.
Config::set('default_action', 'index');
Config::set('default_lang', 'cz');
Example #15
0
<body>
<div class="navbar-wrapper">
    <div class="container">

        <nav class="navbar navbar-inverse navbar-static-top">
            <div class="container">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar"
                            aria-expanded="false" aria-controls="navbar">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand"><?php 
echo \app\core\Config::get('site_name');
?>
</a>
                </div>
                <div id="navbar" class="navbar-collapse collapse">
                    <ul class="nav navbar-nav">
                        <li<?php 
if ($controller == 'Home') {
    echo ' class="active"';
}
?>
>
                            <a href="<?php 
echo URL;
?>
home">Domů</a>
Example #16
0
 /**
  * PATCH is not supported on the user interface
  */
 public function PATCH($matches)
 {
     //get the current URL
     $ru = RequestURI::getInstance(Config::getConfigArray());
     $pageURL = $ru->getURI();
     $exception_config = array();
     $exception_config["log_dir"] = Config::get("general", "logging", "path");
     $exception_config["url"] = Config::get("general", "hostname") . Config::get("general", "subdir") . "error";
     throw new TDTException(450, array("PATCH", $pageURL), $exception_config);
 }
Example #17
0
<?php

define('ROOT', dirname(dirname(__FILE__)));
define('DS', DIRECTORY_SEPARATOR);
//Set to 'dev' for debugging
define('ENVIRONMENT', 'pub');
require_once ROOT . DS . 'app' . DS . 'init.php';
define('URL', \app\core\Config::get('url'));
//Public folder if you can't set apache's default root
define('PUB', URL . 'public/');
//\app\core\App::redirect('error');
//echo \app\core\Config::get("url");
new \app\core\App($_SERVER['REQUEST_URI']);
Example #18
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     Config::load('validation');
     $this->messages = Config::get('validation', 'messages');
 }