32 lines
596 B
PHP
32 lines
596 B
PHP
|
<?php
|
||
|
|
||
|
require_once __DIR__ . '/../vendor/autoload.php';
|
||
|
|
||
|
use Sharkk\Web\App;
|
||
|
use Sharkk\Router\SegmentRouter;
|
||
|
|
||
|
// Make sure an HTTP method and URI are provided
|
||
|
if ($argc < 3) {
|
||
|
echo 'Usage: php test.php <method> <uri>';
|
||
|
exit(1);
|
||
|
}
|
||
|
|
||
|
// Ensure the method is a valid HTTP method
|
||
|
$method = strtoupper($argv[1]);
|
||
|
if (!in_array($method, ['GET', 'POST'])) {
|
||
|
echo 'Invalid HTTP method';
|
||
|
exit(1);
|
||
|
}
|
||
|
|
||
|
$app = new App(new SegmentRouter);
|
||
|
|
||
|
$app->get('/', function () {
|
||
|
echo "Hello, World!\n";
|
||
|
});
|
||
|
|
||
|
$app->get('/about/:daniel', function ($d) {
|
||
|
echo "What about $d?\n";
|
||
|
});
|
||
|
|
||
|
$app->run($method, $argv[2]);
|