-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5dd72cc
commit bb37bc7
Showing
11 changed files
with
160 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ vendor | |
composer.phar | ||
composer.lock | ||
.DS_Store | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
(new µ) | ||
->get('/hello', function () { | ||
echo "<p>Hello, world!</p>"; | ||
}) | ||
->run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
(new µ) | ||
->get('/hello/(?<name>\w+)', function ($app, $params) { | ||
echo "<p>Hello, {$params['name']}!</p>"; | ||
}) | ||
->run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Monolog\Handler\StreamHandler; | ||
use Monolog\Logger; | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
(new µ) | ||
->cfg('log.channel', 'hello3') | ||
->cfg('log.handler', function () { | ||
return new StreamHandler(__DIR__ . '/hello3.log', Logger::DEBUG); | ||
}) | ||
->cfg('log', function ($app) { | ||
$log = new Logger($app->cfg('log.channel')); | ||
$log->pushHandler($app->cfg('log.handler')); | ||
return $log; | ||
}) | ||
->get('/hello/(?<name>\w+)', function ($app, $params) { | ||
$app->cfg('log')->debug("Said hello to {$params['name']}"); | ||
echo "<p>Hello, {$params['name']}!</p>"; | ||
}) | ||
->run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
(new µ) | ||
->cfg('views', __DIR__ . '/templates') | ||
->get('/hello/(?<name>\w+)', function ($app, $params) { | ||
echo $app->view('hello4', [ | ||
'greeting' => 'howdy', | ||
'name' => $params['name'], | ||
]); | ||
}) | ||
->run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<html> | ||
<head> | ||
<title>World Greeter</title> | ||
</head> | ||
<body> | ||
<p><?= ucfirst($greeting) ?>, <?= $name ?>!</p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$fn = function () { | ||
header('X-Test: Hello!', true, 200); | ||
if ($_SERVER['REQUEST_METHOD'] !== 'HEAD') { | ||
echo <<<HTML | ||
<ul> | ||
<li>Method: {$_SERVER['REQUEST_METHOD']}</li> | ||
<li>URI: {$_SERVER['REQUEST_URI']}</li> | ||
</ul> | ||
HTML; | ||
} | ||
}; | ||
|
||
(new µ) | ||
->delete('/user/(?<id>\d+)', $fn) | ||
->get('/user/(?<id>\d+)', $fn) | ||
->head('/user/(?<id>\d+)', $fn) | ||
->patch('/user/(?<id>\d+)', $fn) | ||
->post('/users', $fn) | ||
->put('/user/(?<id>\d+)', $fn) | ||
->run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
<?php class µ{function cfg($k,$v=null){$c=&$this->$k;if($v===null)return$c=is_callable($c)?$c($this):$c;$c=$v;return | ||
$this;}function __call($m,$a){$this->{($m=='any'?'':$m).$a[0]}=$a[1];return$this;}function run(){foreach($this as$x=>$f) | ||
if(preg_match("@$x@i","$_SERVER[REQUEST_METHOD]$_SERVER[REQUEST_URI]",$p))return$f($this,$p);}function view($f,$d=[]){ | ||
ob_start();extract($d);require"$this->views/$f.php";return ob_get_clean();}} | ||
<?php class µ{function __call($m,$a){$c=&$this->{$m.$a[0]};$c=$a[1]??(is_callable($c)?$c($this):$c);return isset($a[1])? | ||
$this:$c;}function run(){foreach($this as$x=>$f)preg_match("@$x@i","$_SERVER[REQUEST_METHOD]$_SERVER[REQUEST_URI]",$p)&& | ||
$f($this,$p);}function view($f,$d=[]){ob_start();extract($d);require"$this->cfgviews/$f.php";return ob_get_clean();}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters