예제 #1
0
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);
    }
}
예제 #2
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');