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 testCache()
 {
     $app = $this->app;
     $app->setup(function () use($app) {
         $app->parameter("testparam", "value");
         $app->addService("app.service", "AppService", ["@kernel.container", "%testparam", "teststring"]);
     });
     $storage = new \FabysCore\Component\Cache\Storage\FileStorage(__DIR__ . "/tests_tmp");
     $app = new Application($storage);
     $app->setup(function () use($app) {
         $app->parameter("testparam", "value");
         $app->parameter("testparam2", "v");
         $app->addService("app.service", "AppService", ["@kernel.container", "%testparam", "teststring"]);
         $app->addService("app.service2", "AppService", ["@kernel.container", "%testparam", "teststring"]);
     });
     $container = $app->getContainer();
     $this->assertFalse($container->has("app.service2"));
     $this->assertTrue($container->has("app.service"));
     $this->assertEmpty($app->parameter("testparam2"));
     $this->assertEquals("value", $app->parameter("testparam"));
 }