【Silex】Silexをコマンドラインから実行する方法です。
ソースコードは以下のとおり。
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
<?php | |
require_once 'vendor/autoload.php'; | |
use Symfony\Component\HttpFoundation\Request; | |
$app = new Silex\Application(); | |
$app->get('/', function(Request $request){ | |
// do something | |
}); | |
if(count($argv) < 3) | |
return; | |
list($file, $method, $path) = $argv; | |
$request = Request::create($path, $method); | |
$app->handle($request); |
コマンドラインで以下のように入力すれば実行されます。
php /home/user/script.php GET /