コード例 #1
0
ファイル: index.php プロジェクト: sergeycher/routine
    {
        return $this->echoAction('delete', $id);
    }
    public function actionProd($prod_id, $id)
    {
        print_r(['$prod_id' => $prod_id, '$id' => $id]);
        return $this->echoAction('prod', [$prod_id, $id]);
    }
    private function echoAction($actionName, $opts = null)
    {
        $json = ['action' => $actionName, 'options' => $opts];
        return $json;
    }
}
echo '<pre>';
TestController::register(['GET test' => "default", 'POST test' => "create", 'GET test/{id}' => "read", 'PUT test/{id}' => "update", 'DELETE test/{id}' => "delete", 'GET test/{id}/prod/{prod_id}' => "prod"], ['id' => '\\d+', 'prod_id' => '\\d+']);
function test($name, $route, $method, $action)
{
    $res = Router::dispatch($route, $method);
    if ($action == $res['action']) {
        echo "Test '{$name}' [{$method} {$route}] passed\n";
    } else {
        echo "Test '{$name}' [{$method} {$route}] NOT passed\n";
    }
}
test('', 'test', 'GET', 'default');
test('when route does not exist', 'test', 'PUT', null);
test('', 'test', 'POST', 'create');
test('', 'test/1', 'GET', 'read');
test('', 'test/1', 'PUT', 'update');
test('', 'test/1', 'DELETE', 'delete');