/** * resolves the instance arguments * * @param array $parameters * @return array */ private function getInstanceArgs(array $parameters) : array { $args = []; foreach ($parameters as $argument) { if ($argument[0] === "@") { $service = substr($argument, 1); if (strpos($service, ":") !== false) { list($service, $method) = explode(":", $service); $serviceInstance = $this->get($service); $arg = $serviceInstance->{$method}(); } else { $arg = $this->get($service); } } elseif ($argument[0] === "%") { $arg = $this->app->parameter(substr($argument, 1)); } else { $arg = $argument; } $args[] = $arg; } return $args; }
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()); }