Exemple #1
0
 /**
  * DBException constructor.
  * @param string        $exceptionMessage
  * @param int           $exceptionCode
  * @param string        $dbMessage
  * @param int           $dbCode
  */
 public function __construct($exceptionMessage, $exceptionCode, $dbMessage = null, $dbCode = null)
 {
     if (App::getEnvironment() == 1) {
         parent::__construct($dbMessage, $exceptionCode);
     } else {
         parent::__construct($exceptionMessage, $exceptionCode);
     }
     $this->dbErrorCode = $dbCode;
     $this->dbErrorMessage = $dbMessage;
 }
Exemple #2
0
 /**
  * DB constructor.
  * @param string|null $configInstance - Database instance from config file, for example: "mysql_connection"
  * @param bool $useReusableConnection - Set this to true to use DBManager to hold DBConnections for reuse
  *
  * @throws \Exception
  */
 function __construct($configInstance = null, $useReusableConnection = true)
 {
     $this->isTransaction = false;
     if (!isset($configInstance)) {
         # Apply parameters from config
         $this->config = App::getConfig('mysql_connection');
         if (isset($this->config)) {
             $this->constructDBOBJ($useReusableConnection);
             return;
         }
     } else {
         # Apply parameters from custom config instance
         $conf_cred = App::getConfig($configInstance);
         if (isset($conf_cred)) {
             $this->config = $conf_cred;
             $this->constructDBOBJ($useReusableConnection);
             return;
         }
     }
     throw new DBException("Database driver can't be instantiated. Failed to load configuration.", 500, "DB Connection failed", 500);
 }
Exemple #3
0
function __sdn()
{
    $isBuffered = \Xdire\Dude\Core\App::getOutputType();
    if ($error = error_get_last()) {
        if ($isBuffered == 1) {
            ob_clean();
        }
        header("HTTP/1.0 500");
        if (\Xdire\Dude\Core\App::getEnvironment() == 1) {
            echo "Error produced by application: \n";
            echo "Code: " . $error['type'] . " \nMessage: " . $error['message'] . " \nFile: " . $error['file'] . " \nLine: " . $error['line'];
        } else {
            $file = explode("/", $error['file']);
            $fileName = strstr(array_pop($file), '.', true);
            echo '{"errorCode":500,"errorMessage":"Error happened, be calm, send us a report and we\'ll fix it. (' . $fileName . ':' . $error['line'] . ') "}';
        }
        if ($isBuffered == 1) {
            ob_flush();
        }
    }
    if ($isBuffered == 1) {
        ob_end_clean();
    }
}
Exemple #4
0
<?php

use Xdire\Dude\Core\App;
use App\Controller;
/* **********************************************************************
// ----------------------------------------------------------------------
//                        Specific App PROCESSES
// ----------------------------------------------------------------------
//
// If Request came from CRON or CLI and not detected as WEB then next
// code will be executed
// ----------------------------------------------------------------------
//                              USAGE
// ----------------------------------------------------------------------
// use value of constant SYSTEM_PROCESS_ID for determine which command
//                   was run with -p flag, at the start of the program
*/
if (SYSTEM_PROCESS_ID == "") {
    App::useController(new Controller\ExampleController());
} else {
    echo "Process ID is not defined";
}
/* **********************************************************************
// ----------------------------------------------------------------------
//              Next Code Will be Executed after processes
// ----------------------------------------------------------------------
*/
// Get controller <ExampleController> and function <test> in this controller
Exemple #5
0
require_once __DIR__ . '/vendor/autoload.php';
/* ---------------------------------------------  \
|                                                 \
|       APPLICATION RELATED OPTIONS               \
|                                                 \
------------------------------------------------ */
// SET APPLICATION ROOT PATH
chdir(dirname(__FILE__));
define('ROOTPATH', getcwd());
define('APPPATH', ROOTPATH . '/App');
// Feed Core with Application structure files
App::feedAppRouteFile(APPPATH . "/route.php");
App::feedAppProcessFile(APPPATH . "/process.php");
// Switch environment properties and config zones
$config = null;
if (APPENVIRONMENT == 'prod') {
    error_reporting(0);
    $config = (require APPPATH . '/config.prod.php');
} elseif (APPENVIRONMENT == 'dev') {
    error_reporting(-1);
    $config = (require APPPATH . '/config.dev.php');
} elseif (APPENVIRONMENT == 'test') {
    error_reporting(-1);
    $config = (require APPPATH . '/config.test.php');
} else {
    throw new \Exception('Environment parameter is wrong');
}
require APPPATH . '/const.php';
// STARTING CORE
App::init($config, APPENVIRONMENT);
Exemple #6
0
<?php

use Xdire\Dude\Core\App;
use Xdire\Dude\Core\Server\Request;
use Xdire\Dude\Core\Server\Response;
/** -------------------------------------- DEFINE MIDDLEWARE CONTROLLERS ------------------------------------------ */
$middleware = new \App\Middleware\ExampleMiddleware();
/** ------------------------------------------ DEFINE ROUTING BELOW ----------------------------------------------- */
// ROUTE EXAMPLE 1 - With Routing Controller
App::route(ROUTE_ALL, '/', function (Request $req, Response $res) {
    // Route to Controller
    App::routeNextController(new \App\Controller\ExampleController(), $req, $res);
}, $middleware);
// ROUTE EXAMPLE 2 - With Calling Specific Controller
App::route(ROUTE_ALL, '/test/*variable1/*variable2/*variable3', function (Request $req, Response $res) {
    // Send response from Route
    $res->send(200, "<h1>Hello World!</h1>");
    echo "<br> I am variable 1: " . $req->getPathParameter('variable1');
    echo "<br> I am variable 2: " . $req->getPathParameter('variable2');
    echo "<br> I am variable 3: " . $req->getPathParameter('variable3');
    // Use some Controller
    App::useController(new \App\Controller\ExampleController());
    // Flush all echoed data, if needed. Response object contains flush() ,send() and end() methods
    $res->flush();
}, $middleware);
// ROUTE EXAMPLE 3 - Same test route but without parameters
App::route(ROUTE_ALL, '/test', function (Request $req, Response $res) {
    // Send response from Route
    $res->send(200, "<h1>Hello World!</h1>");
}, $middleware);