Пример #1
0
/**
 * [load_request description]
 * @param  [type] $request [description]
 * @return [type]          [description]
 */
function load_request($request)
{
    $resp = \shgysk8zer0\Core\JSON_Response::getInstance();
    $dom = \shgysk8zer0\DOM\HTML::getInstance();
    switch ($request) {
        case 'readme':
            $readme = call_user_func($dom->body, 'readme')[0];
            return $resp->append('body', $readme)->showModal("#{$readme->id}");
            break;
        case 'ad_insertion':
            return load_form('ad_insertion');
            break;
        case 'login':
            return load_form('login');
            break;
        default:
            \shgysk8zer0\Core\Console::getInstance()->error(sprintf(ERROR_FORMAT, $request));
            return $resp->notify('Unhandled request', sprintf(ERROR_FORMAT, $_REQUEST['load']), 'images/octicons/svg/bug.svg')->error(['$_REQUEST' => $_REQUEST]);
    }
}
Пример #2
0
use shgysk8zer0\Core_API as API;
use shgysk8zer0\DOM;
Core\Console::getInstance()->asErrorHandler()->asExceptionHandler();
DOM\HTMLElement::$import_path = realpath(getenv('COMPONENTS_DIR'));
function build_head(\DOMElement &$head)
{
    $head('head');
}
function build_body(\DOMElement &$body)
{
    $body->parentNode->class = 'no-js';
    $body->class = 'flex column';
    $body('header', 'main', 'footer');
}
function init()
{
    $headers = Core\Headers::getInstance();
    $dom = DOM\HTML::getInstance();
    if (in_array('text/html', explode(',', $headers->accept))) {
        build_head($dom->head);
        build_body($dom->body);
        return $dom;
    } elseif ($headers->accept === 'application/json' and !empty($_REQUEST)) {
        require_once './components/handlers/request.php';
        return \Components\Handlers\Request\handle($_REQUEST);
    } else {
        http_response_code(API\Abstracts\HTTPStatusCodes::BAD_REQUEST);
    }
}
Core\Console::getInstance()->sendLogHeader();
exit(init());
Пример #3
0
<?php

// Check PHP version >= 5.5
if (version_compare(PHP_VERSION, getenv('MIN_PHP_VERSION'), '<')) {
    http_response_code(500);
    exit(sprintf('PHP version %s or greater is needed', getenv('MIN_PHP_VERSION')));
}
// Setup Autoloader
set_include_path(realpath(getenv('AUTOLOAD_DIR')) . PATH_SEPARATOR . get_include_path());
spl_autoload_extensions(getenv('AUTOLOAD_EXTS'));
spl_autoload_register(getenv('AUTOLOAD_FUNC'));
// Set Console logger and other classes
$console = \shgysk8zer0\Core\Console::getInstance()->asErrorHandler()->asExceptionHandler();
$timer = new \shgysk8zer0\Core\Timer();
$headers = \shgysk8zer0\Core\Headers::getInstance();
$url = new \shgysk8zer0\Core\URL();
// Verify that HTML is in the Accept header
if (in_array('text/html', explode(',', $headers->accept))) {
    $dom = new \shgysk8zer0\DOM\HTML();
    $dom->head->append('title', 'HTTP-OS');
    $dom->head->append('link', null, ['rel' => 'prefetch', 'href' => 'combined.svg', 'type' => 'image/svg+xml']);
    // Load all JavaScript async
    \shgysk8zer0\Core\ArrayObject::of('scripts/custom.es6', 'scripts/std-js/polyfills/element/close.js', 'scripts/std-js/polyfills/element/remove.js', 'scripts/std-js/polyfills/element/show.js', 'scripts/std-js/polyfills/element/showModal.js', 'scripts/std-js/appcache_listener.es6', 'scripts/std-js/deprefixer.es6', 'scripts/std-js/prototypes.es6', 'scripts/std-js/zq.es6', 'scripts/std-js/support_test.es6', 'scripts/std-js/functions.es6', 'scripts/std-js/json_response.es6')->reduce(function (\DOMElement $head, $script) {
        $head->append('script', null, ['type' => 'application/javascript', 'src' => $script, 'asyne' => '', 'defer' => '']);
        return $head;
    }, $dom->head);
    // Import stylesheet
    $dom->head->append('link', null, ['rel' => 'stylesheet', 'href' => 'stylesheets/styles/import.css', 'media' => 'all']);
    $dom->body->append('header')->append('h1', 'HTTP-OS');
    $dom->body->append('a', 'Home', ['href' => $url]);
    $details = $dom->body->append('main')->append('details');