【Silex】Silexをコマンドラインから実行する方法

【Silex】Silexをコマンドラインから実行する方法です。

ソースコードは以下のとおり。

<?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 /

 

コメントする

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

This site uses Akismet to reduce spam. Learn how your comment data is processed.