Example #1
0
 protected function __construct()
 {
     if (Application::getProfiler()) {
         Benchmark::getInstance('router')->startTime()->startRam();
     }
     Logger::getInstance()->addGroup('router', 'Router Benchmark and Informations', true);
 }
 public function notify()
 {
     // Erase buffer
     $buffer = ob_get_status();
     if (!empty($buffer)) {
         ob_end_clean();
     }
     if ($this->_observers->count()) {
         foreach ($this->_observers as $observer) {
             $observer->update($this);
         }
     }
     // Clear error for avoid multiple call
     if ($this->_clearErrorAfterSending) {
         $this->_error = false;
     }
     // Show internal server error (500)
     if (!Application::getDebug()) {
         Router::getInstance()->show500();
     }
     // Exit script
     exit;
 }
Example #3
0
        :-""-.`./-.'     /    `.___.'   
              \ `t  ._  /  Yoda         
               "-.t-._:'
*  Always two there are, no more, no less: a master(REQUEST) and an apprentice(RESPONSE).
* 
* Index file :
*     - Include loader, paths and run application
*
* @copyright  Copyright 2014 - MidichlorianPHP and contributors
* @author     NAYRAND Jérémie (dreadlokeur) <*****@*****.**>
* @version    1.0.1dev2
* @license    GNU General Public License 3 http://www.gnu.org/licenses/gpl.html
* @package    MidichloriansPHP
*/
use framework\Application;
// Init
ini_set('display_errors', 1);
ini_set('display_startup_errors', true);
ini_set('output_buffering', 1);
ini_set('error_reporting', E_ALL);
// Start Buffer
ob_start('ob_gzhandler');
try {
    // autoloader
    require 'loader.php';
    // Run app
    Application::getInstance(PATH_APP . 'bootstrap.php')->run();
} catch (\Exception $e) {
    // throw new exeception for manage with Exeception manager
    throw $e;
}
 /**
  * On appel le constructeur de \Framework\Application et on fixe le nom de l'application
  */
 public function __construct()
 {
     parent::__construct();
     $this->name = 'Frontend';
 }
Example #5
0
<?php

/**
 * Created by JetBrains PhpStorm.
 * User: krajewski
 * Date: 28.8.13
 * Time: 15:19
 * To change this template use File | Settings | File Templates.
 */
require_once '../../ws/autoload.php';
use Framework\Application;
error_reporting(E_ALL);
ini_set('display_errors', true);
mb_internal_encoding("UTF-8");
date_default_timezone_set('Europe/Prague');
// set_error_handler( array( '\Framework\Error', 'captureError' ) );
// set_exception_handler( array( '\Framework\Error', 'captureException' ) );
// register_shutdown_function(array( 'Framework/Error', 'captureShutdown' ));
Application::Run();
Example #6
0
 protected function _addLog($message, $level, $groupName = false, $isBacktrace = false, $notify = false)
 {
     if ($level <= $this->getLevel() || $this->getLevel() == self::DEBUG || Application::getDebug()) {
         // cache log
         if (self::getCache() && $level >= self::NOTICE && !Application::getDebug()) {
             $hash = md5($message . $level);
             $cache = self::getCache()->read($hash);
             // no exists, or epiress => write
             if (!$cache) {
                 self::getCache()->write($hash, $hash, true, $cache::EXPIRE_HOUR);
             } else {
                 return;
             }
             // no need log, because already exists in cache
         }
         // set log
         $date = new \DateTime('now');
         $log = new \stdClass();
         $log->message = $message;
         $log->level = $level;
         $log->group = $groupName;
         $log->date = $date->format('Y-m-d H:i:s');
         $log->isTrace = $isBacktrace;
         // add log on logs
         if ($groupName) {
             $this->_addLogOnGroup($groupName, $log);
         } else {
             $this->_logs[] = $log;
         }
         if (!$isBacktrace && self::getLogBacktrace()) {
             $this->_logBackTrace();
         }
         if ($notify) {
             $this->notify();
         }
     }
 }
Example #7
0
 public function shutdown()
 {
     if ($this->config->getVar("CONFIG/SCHEDULER_HOST") == "") {
         $this->schedulerurl = $this->request->prefix . "://" . $this->request->http_host . $this->base . "scheduler/?bsu=" . $this->session->getSessionVar("userid");
     } else {
         $this->schedulerurl = $this->config->getVar("CONFIG/SCHEDULER_HOST") . $this->base . "scheduler/?bsu=" . $this->session->getSessionVar("userid");
     }
     $scheduler_pages_str = $this->config->getVar("CONFIG/SCHEDULER_PAGES");
     $scheduler_pages = explode(",", $scheduler_pages_str);
     if (in_array($this->page, $scheduler_pages) || $scheduler_pages_str == "") {
         if ((int) $this->config->getVar("CONFIG/SCHEDULER") == 1 && $this->page != "scheduler") {
             register_shutdown_function('framework\\propagateShutdown', $this->schedulerurl);
         }
     }
     parent::shutdown();
 }
Example #8
0
<?php

require_once '../app/bootstrap.php';
use Framework\Application;
use Framework\Core\Router;
use Framework\Core\Route;
use Framework\Core\Response;
use Framework\Core\View;
use Exception;
$router = new Router();
$router->addRoute(new Route('get', '/posts', 'PostController@posts'));
$router->addRoute(new Route('get', '/posts/post/{id}', 'PostController@show'));
$router->addRoute(new Route('post', '/posts/post', 'PostController@add'));
$router->addRoute(new Route('get', '/index', 'MainController@index'));
$router->addRoute(new Route('get', '/', 'MainController@index'));
$router->addRoute(new Route('get', '/counter', 'CountController@count'));
$response = Application::run($router);
Application::handleResponse($response);
Example #9
0
 protected function _read($modelType, $slug)
 {
     $cache = $this->_cache->read($modelType . $slug);
     if (!is_null($cache) && !Application::getDebug()) {
         $data = $cache;
     } else {
         $manager = Model::factoryManager($modelType);
         $data = $manager->read($slug, true);
         //try by slug
         if (is_null($data)) {
             $data = $manager->read($slug);
         }
         //try by id
         if (!is_null($data)) {
             $this->_cache->write($modelType . $slug, $data, true);
         }
     }
     return $data;
 }
Example #10
0
 /**
  * Log uncaught exceptions.
  * @param $exception
  */
 public function exception($exception)
 {
     $log = \Application::log();
     if (!empty($log)) {
         $log->error($exception, $exception->getTrace());
     }
     throw $exception;
 }
Example #11
0
<?php

use Framework\Application;
define('ROOT_PATH', realpath(dirname(__FILE__) . '/../'));
define('SRC_PATH', ROOT_PATH . '/src');
define('FRAMEWORK_PATH', ROOT_PATH . '/framework');
require FRAMEWORK_PATH . '/Autoloader.php';
$autoloader = new Framework\Autoloader();
$autoloader->register();
$autoloader->addNamespace('Framework', FRAMEWORK_PATH);
$autoloader->addNamespace('Students', SRC_PATH . '/students');
$autoloader->addNamespace('Src', SRC_PATH);
$config = (require ROOT_PATH . '/app/config.php');
Application::run($config);
function dd($v)
{
    echo '<pre>';
    print_r($v);
    echo '</pre>';
    die;
}
Example #12
0
<?php

error_reporting(E_ALL ^ E_NOTICE);
include '../app_code/Application.php';
$app = \Framework\Application::getInstance();
$app->run();
Example #13
0
<?php

require_once __DIR__ . '/../framework/Application.php';
use framework\Application;
$config = ['dbConnection' => ['dsn' => 'mysql:host=localhost;dbname=DZEmployee', 'username' => 'root', 'password' => '']];
$application = new Application();
$application->run($config);
Example #14
0
 public function execute($checkBindNumber = true)
 {
     if (Application::getDebug()) {
         Benchmark::getInstance($this->_configName)->startTime()->startRam();
     }
     if (is_null($this->_query) || !$this->_statement) {
         throw new \Exception('Prepare query before execute');
     }
     if ($checkBindNumber) {
         if (count($this->_params) < $this->_paramsNumberNecesary) {
             throw new \Exception('Miss bind parameters');
         }
     }
     // Bind parameters
     $i = 0;
     foreach ($this->_params as $param) {
         $bindName = $this->_bindParamType === Database::PARAM_BIND_POSITIONAL ? $i + 1 : ':' . $this->_namedParamOrder[$i];
         if ($param['isParam']) {
             $this->_statement->bindParam($bindName, $param['value'], $param['type']);
         } else {
             $this->_statement->bindValue($bindName, $param['value'], $param['type']);
         }
         $i++;
     }
     // Execute
     $this->_execute = $this->_statement->execute();
     //check error
     $lastError = $this->getLastError(true);
     if (!is_null($lastError)) {
         Logger::getInstance()->error('Sql query : ' . $this->_query . ' has error : ' . $lastError);
     }
     // Debug
     if (Application::getDebug()) {
         Database::getDatabase($this->_configName)->logQuery($this->_query, $this->_params, $this->_bindParamType, $lastError);
     }
     return $this->_execute;
 }