Esempio n. 1
0
<?php

use Application\Core;
//global constants
define('ROOT_BASE', __DIR__ . '/..');
define('APPLICATION_BASE', realpath(ROOT_BASE . '/Application'));
define('MEDIA_BASE', realpath(__DIR__ . '/media'));
//define HTTP response codes
define('HTTP_BAD_REQUEST', 400);
define('HTTP_FORBIDDED', 403);
define('HTTP_NOT_FOUND', 404);
define('HTTP_SERVER_ERROR', 500);
//init core
require realpath(APPLICATION_BASE . '/Core/bootstrap.php');
//run application
echo Core\Router::run();
Esempio n. 2
0
<?php

/**
 * Register development routes which are available when
 * the development status is on
 */
namespace Application;

use Application\Core\App;
use Application\Core\Router;
use Application\Core\HTMLHandler;
use Application\Core\StatusCodeHandler;
Router::restrict(function () {
    return App::environment() == 'dev' || App::environment() == 'development';
}, function () {
    Router::get('xtend/codes', function () {
        $table = HTMLHandler::createDocument()->createElement('table');
        $codes = StatusCodeHandler::all();
        foreach ($codes as $code) {
            $row = $table->createElement('tr');
            $row->createElement('td')->addText($code->hex());
            $row->createElement('td')->addText($code->name());
            $row->createElement('td')->addText($code->readable());
        }
        $table->write(true);
    });
});
Esempio n. 3
0
 /**
  *
  * @return type
  */
 public function printError($code = \HTTP_NOT_FOUND, $message = null)
 {
     if (Core\Request::server('REQUEST_METHOD') == 'POST') {
         $content = json_encode(array('status' => 'failure'));
     } else {
         $layout = Core\Router::call('Layout.create');
         $this->setErrorTitle($code);
         $this->setErrorMessage(is_null($message) ? 'Page Not Found' : $message);
         $layout->setContent($this->loadTemplate(Module\VIEW_BASE . "/error.phtml"));
         $content = $layout->render();
     }
     return $content;
 }
Esempio n. 4
0
<?php

namespace Application;

use xTend\Workbench\Workbench;
/**
 * Shows the application routes
 * (those not under restrict)
 */
Workbench::register('^routes$', function ($argv) {
    $routes = Core\Router::all();
    foreach ($routes as $route) {
        echo '/' . str_pad($route->handle(), 28) . $route . PHP_EOL;
    }
}, 'routes');
Esempio n. 5
0
<?php

namespace Application;

use Application\Core\Router;
Router::home('My homepage');
Router::error(0x194, '404 - Page Not Found');
// Router::error(404, ..) would also work
Esempio n. 6
0
 /**
  * Runs the app
  */
 public static function run()
 {
     // set display errors
     // upon development environment
     if (self::$_environment == 'development' || self::$_environment == 'dev') {
         ini_set('display_errors', 1);
     }
     // Set directories
     self::$_directoryBackups = new Directory(self::$_directorySystem . '/' . self::$_directoryBackups);
     self::$_directoryBlueprints = new Directory(self::$_directorySystem . '/' . self::$_directoryBlueprints);
     self::$_directoryConfig = new Directory(self::$_directorySystem . '/' . self::$_directoryConfig);
     self::$_directoryControllers = new Directory(self::$_directorySystem . '/' . self::$_directoryControllers);
     self::$_directoryLayouts = new Directory(self::$_directorySystem . '/' . self::$_directoryLayouts);
     self::$_directoryLibs = new Directory(self::$_directorySystem . '/' . self::$_directoryLibs);
     self::$_directoryLogs = new Directory(self::$_directorySystem . '/' . self::$_directoryLogs);
     self::$_directoryMeta = new Directory(self::$_directorySystem . '/' . self::$_directoryMeta);
     self::$_directoryModels = new Directory(self::$_directorySystem . '/' . self::$_directoryModels);
     self::$_directoryModules = new Directory(self::$_directorySystem . '/' . self::$_directoryModules);
     self::$_directoryViewOutput = new Directory(self::$_directorySystem . '/' . self::$_directoryViewOutput);
     self::$_directoryViews = new Directory(self::$_directorySystem . '/' . self::$_directoryViews);
     self::$_directoryObjects = new Directory(self::$_directorySystem . '/' . self::$_directoryObjects);
     self::$_directorySystem = new Directory(self::$_directorySystem);
     self::$_directoryPublic = new Directory(self::$_directoryPublic);
     // run
     self::integrity();
     PackagistHandler::start();
     self::libraries();
     if (self::$_modifier < App::BAREBONES) {
         BackupManager::create();
         SessionHandler::start();
         Request::start();
         self::configure();
     } else {
         self::bareconfig();
     }
     if (self::$_modifier < App::NO_ROUTING) {
         Router::start();
     }
 }
Esempio n. 7
0
<?php

/**
 * Created by PhpStorm.
 * User: Artem
 * Date: 1/6/2016
 * Time: 4:35 PM
 */
include_once dirname(__FILE__) . '/application/bootstrap.php';
use Application\Core\Router;
Router::start();