/**
  * Returns a class instance
  **/
 static function instance()
 {
     $storage = new \Core\Storage();
     $classes = $storage->get('CORE.instantiable') ?: [];
     if (!isset($classes[$class = get_called_class()])) {
         $ref = new \Reflectionclass($class);
         $args = func_get_args();
         $classes[$class] = $args ? $ref->newinstanceargs($args) : new $class();
         $storage->set('CORE.instantiable', $classes);
     }
     return $classes[$class] ?: null;
 }
Beispiel #2
0
<?php

$storage = new \Core\Storage();
$storage->sync();
if (isset($_GET['url']) && is_file($_GET['url'])) {
    // For images and that kind of stuff
    $file = $_GET['url'];
    $ext = \Core\File::getExtension($file);
    switch ($ext) {
        case 'css':
        case 'js':
            header("Content-Type: " . \Core\File::getMime(strtolower(pathinfo($file, PATHINFO_EXTENSION))));
            header('Content-Length: ' . filesize($file));
            if ($storage->get('CORE.static_client_cache')) {
                $offset = $storage->get('CORE.static_client_cache_time');
                header("Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT");
                header("Cache-Control: max-age={$offset}, must-revalidate");
            }
            // Minify
            $content = file_get_contents($file);
            $buffer = preg_replace('!/\\*[^*]*\\*+([^/][^*]*\\*+)*/!', '', $content);
            $buffer = str_replace(array("\r\n", "\r", "\n", "\t", '    ', '   ', '  '), '', $content);
            echo $buffer;
            die;
            break;
    }
}
$router = new \Core\Router\Router($_GET['url']);
$router->on404 = function () {
    echo '404, no route found.';
};