Пример #1
0
        $URL = array_shift($URL_PARTS);
        if (false === strpos($URL, '.')) {
            $FORMAT = 'html';
        } else {
            $FORMAT = array_pop($URL_PARTS);
        }
        break;
    }
}
if (!isset($URL)) {
    $FILE = '404.php';
    $URL = $_GET['__url__'];
    $URL_PARTS = array();
    $FORMAT = 'html';
}
unset($routes);
unset($pattern);
unset($_GET['__url__']);
Sd('FILE', $FILE);
Sd('URL', $URL);
Sd('URL_PARTS', $URL_PARTS);
Sd('FORMAT', $FORMAT);
# Dispatch
#   Beyond the superglobals, these are passed to the called file:
#     FILE: the name of the file included to handle the request
#     URL: the complete request URL, minus the query string
#     URL_PARTS: array of matched sub-patterns in the URL
#     FORMAT: one (html|xml|json|rss|rdf|php) for determining output format
require_once $FILE;
Sout(Sl(reset(explode('.', $FILE)) . '.' . $FORMAT . '.php'));
Пример #2
0
            $key = $keys[0];
            $value = $keys[1];
            break;
    }
    $out = array();
    foreach ($arr as $k => $v) {
        SometimesData::set($key, $k);
        SometimesData::set($value, $v);
        $s = clone $sometimes;
        $s->bind();
        $out[] = $s;
    }
    SometimesData::delete($key);
    SometimesData::delete($value);
    return new Nil($out);
}
# A test, if run from the command line via `php sometimes.php`
if ('cli' == php_sapi_name() && is_array($argv) && preg_match('!/' . basename(__FILE__) . '$!', realpath($argv[0]))) {
    # For the test, use templates in this directory
    $GLOBALS['SOMETIMES_TEMPLATEDIR'] = dirname(__FILE__);
    # Set a variable expected by foo.html.php
    Sd('foo', 'bar');
    # Include and output foo.html.php under both possible conditions
    $doc = Sf('foo.html.php');
    Sout($doc, Sc('bold'));
    echo "\n\n";
    Sout($doc, Sc('bold', false));
    echo "\n\n";
    # Safely fail to include a non-existent file
    var_dump(Sf('does-not-exist.html.php'));
}