Exemple #1
0
function main()
{
    /* create application */
    $cacheStorage = new FileStorage(__DIR__ . "/../var/cache/");
    $logHandler = new StreamHandler(__DIR__ . "/../var/logs/fabyscore.log");
    $app = new Application($cacheStorage, $logHandler, \Psr\Log\LogLevel::INFO);
    /* enable debug mode */
    $app->enableDebugMode();
    /* application setup */
    $app->setup(function () use($app) {
        /* parameters */
        $app->addParameter("secret", "IamASecretString");
        /* services */
        $app->addService("controller.example", ExampleController::class, ["@kernel.container"]);
        $app->addService("controller.error", ErrorController::class);
        /* middleware */
        $app->error(["@controller.error", "errorAction"]);
        $app->before(["@controller.example", "beforeAction"]);
        $app->after(["@controller.example", "afterAction"]);
        /* routes */
        $app->get("/{name}", ["@controller.example", "indexAction"], [-1024 => ["@controller.example", "beforeRouteAction"]], [["@controller.example", "afterRouteAction"]]);
        $app->post("/{name}", ["@controller.example", "indexAction"]);
    });
    /* run application */
    $request = ServerRequest::createNew($_GET, $_POST, $_FILES, $_COOKIE, $_SERVER, $_ENV);
    $app->run($request);
}
 public function testEnableDebugMode()
 {
     $storage = new \FabysCore\Component\Cache\Storage\FileStorage(__DIR__ . "/tests_tmp");
     $app = new Application($storage);
     $this->assertFalse($app->isInDebugMode());
     $app->enableDebugMode();
     $this->assertTrue($app->isInDebugMode());
 }