{"id":19039619,"url":"https://github.com/windwalker-io/application","last_synced_at":"2026-03-14T19:44:54.956Z","repository":{"id":20479600,"uuid":"23757526","full_name":"windwalker-io/application","owner":"windwalker-io","description":"[DEPRECATED] Application package for Windwalker.","archived":false,"fork":false,"pushed_at":"2023-07-18T08:35:50.000Z","size":125,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-02T06:44:55.472Z","etag":null,"topics":["application","cli-app","cli-application","psr7-handler","server"],"latest_commit_sha":null,"homepage":"https://github.com/ventoviro/windwalker","language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/windwalker-io.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2014-09-07T10:31:07.000Z","updated_at":"2024-12-16T13:47:07.000Z","dependencies_parsed_at":"2022-07-31T21:18:12.010Z","dependency_job_id":null,"html_url":"https://github.com/windwalker-io/application","commit_stats":{"total_commits":74,"total_committers":1,"mean_commits":74.0,"dds":0.0,"last_synced_commit":"3272c4364b3369dabe5b7db92556453f3f048e9a"},"previous_names":["ventoviro/windwalker-application"],"tags_count":80,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/windwalker-io%2Fapplication","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/windwalker-io%2Fapplication/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/windwalker-io%2Fapplication/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/windwalker-io%2Fapplication/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/windwalker-io","download_url":"https://codeload.github.com/windwalker-io/application/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240100159,"owners_count":19747639,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["application","cli-app","cli-application","psr7-handler","server"],"created_at":"2024-11-08T22:17:55.658Z","updated_at":"2025-12-18T09:05:15.558Z","avatar_url":"https://github.com/windwalker-io.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Windwalker Application\n\nWindwalker application is a kernel as main entry of your system.\n\n## Installation via Composer\n\nAdd this to the require block in your `composer.json`.\n\n``` json\n{\n    \"require\": {\n        \"windwalker/application\": \"~3.0\"\n    }\n}\n```\n\n## Create An Application\n\nCreate application and extends the `doExecute()` method to something.\n\n``` php\nuse Windwalker\\Application\\AbstractApplication;\nuse Windwalker\\IO\\Input;\nuse Windwalker\\Structure\\Structure;\n\nclass MyApplication extends AbstractApplication\n{\n    protected function init()\n    {\n        // Do stuff.\n\n        // Get config\n        $this-\u003eget('foo'); // bar\n    }\n\n    public function doExecute()\n    {\n        try\n        {\n            // Some code here...\n        }\n        catch (\\Exception $e)\n        {\n            Error::renderErrorPage();\n        }\n\n        return true;\n    }\n}\n\n$app = new MyApplication(new Structure(array('foo' =\u003e 'bar')));\n\n$app-\u003eexecute();\n```\n\nConfig is `Structure` object, see [Windwalker Structure](https://github.com/ventoviro/windwalker-structure)\n\n## WebApplication\n\n`AbstractWebApplication` contains `WebEnvironment` and `WenHttpServer` object that help us handle HTTP request and output.\n\n### WebEnvironment\n\nUse `WebEnvironment` to get information of browser or server.\n\n``` php\n$this-\u003eenvironment-\u003ebrowser-\u003egetBrowser(); // Get browser name\n```\n\nUse `Platform` to get server information.\n\n``` php\n$this-\u003eenvironment-\u003eplatform-\u003eisUnix();\n```\n\nSee: [Environment Package](https://github.com/ventoviro/windwalker-environment)\n\n### PSR7 Handler\n\n`dispatch()` is a standard PSR7 handler so we can write our logic here, just return Response object and the `WebHttpServer`\nobject which in Application will render it to client.\n\n``` php\nuse Psr\\Http\\Message\\ResponseInterface as Response;\nuse Psr\\Http\\Message\\ServerRequestInterface as Request;\nuse Windwalker\\Application\\AbstractWebApplication;\n\nclass MyHttpKernel extends AbstractWebApplication\n{\n\tpublic function dispatch(Request $request, Response $response, $next = null)\n\t{\n\t\t// Get request query\n\t\t$query = $request-\u003egetQueryParams();\n\n\t\t// Get Psr Uri\n\t\t$uri = $request-\u003egetUri();\n\n\t\t// Write body\n\t\t$response-\u003egetBody()-\u003ewrite('\u003ch1\u003eHello World~~~!\u003c/h1\u003e');\n\n\t\treturn $response;\n\t}\n}\n\n$app = new MyHttpKernel;\n\n$app-\u003eexecute();\n```\n\nResult:\n\n``` html\n\u003ch1\u003eHello World~~~!\u003c/h1\u003e\n```\n\n### Error Handler\n\nSet error handler as final handler so we can use it in `dispatch()`.\n\n``` php\nclass MyHttpKernel extends AbstractWebApplication\n{\n\tpublic function dispatch(Request $request, Response $response, $next = null)\n\t{\n\t\ttry\n\t\t{\n\t\t\tthrow new \\Exception('Whoops~', 500);\n\t\t}\n\t\tcatch (\\Exception $e)\n\t\t{\n\t\t\treturn $next($e, $request, $response);\n\t\t}\n\n\t\treturn $response;\n\t}\n}\n\n$app = new MyHttpKernel;\n\n$app-\u003esetFinalHandler(function (Exception $e, Request $request, Response $response)\n{\n    $response-\u003egetBody()-\u003ewrite(sprintf('\u003ch1\u003eError %s. Message: %s\u003c/h1\u003e', $e-\u003egetCode(), $e-\u003egetMessage()));\n});\n\n$app-\u003eexecute();\n```\n\nResult:\n\n``` html\n\u003ch1\u003eError 500. Message: Whoops~\u003c/h1\u003e\n```\n\nSee [Windwalker Http Package](https://github.com/ventoviro/windwalker-http)\n\n## Cli Application\n\nThis is a example of a simple cli application.\n\n``` php\n// app.php\n\nuse Windwalker\\Application\\AbstractCliApplication;\n\nclass MyCliApp extends AbstractCliApplication\n{\n    public function doExecute()\n    {\n        // Get options (-h)\n        $help = $this-\u003eio-\u003eget('h');\n\n        if ($help)\n        {\n            $msg = \u003c\u003c\u003cMSG\nHelp message: version 1.0\n------------------------------------\nmyapp.php \u003ccommand\u003e [-options]\n\n  foo    Description of this command.\n  bar    Description of this command.\n  help   Description of this command.\nMSG;\n\n            $this-\u003eio-\u003eout($msg);\n            \n            $this-\u003eclose();\n        }\n\n        // Get arguments\n        $arg = $this-\u003egetArgument(0);\n\n        // Do some stuff...\n\n        return 0; // Exit code 0 means success\n    }\n}\n\n$app = new MyCliApp;\n\n$app-\u003eexecute();\n```\n\nNow we can access this app by PHP CLI:\n\n``` bash\nphp app.php arg1 arg2 -h --option --foo bar --n=a\n```\n\nSee: [Windwalker IO](https://github.com/ventoviro/windwalker-io)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwindwalker-io%2Fapplication","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwindwalker-io%2Fapplication","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwindwalker-io%2Fapplication/lists"}