예제 #1
0
    public function addRoute($route, $callback)
    {
        $this->routes[$route] = $callback->bindTo($this, __CLASS__);
    }
    public function dispatch($endpoint)
    {
        foreach ($this->routes as $route => $callback) {
            if ($route === $endpoint) {
                $callback();
            }
        }
    }
}
$router = new RouteFactory();
$router->addRoute('show/me', function () {
    echo $this->contentType . ', ' . $this->contentBody;
});
$router->addRoute('show/him', function () {
    $this->contentType = 'html';
    $this->contentBody = '{"message": "Hello World!"}';
    echo $this->contentType . ', ' . $this->contentBody;
});
print_r($argv);
$router->dispatch($argv[1]);
$dt = new \DateTime();
$di = \DateInterval::createFromDateString('-1 week');
$dp = new \DatePeriod($dt, $di, 10);
foreach ($dp as $date) {
    # code...
    echo $date->format('Y m d h-m-s'), PHP_EOL;
}