{"id":15029808,"url":"https://github.com/rancoud/application","last_synced_at":"2025-08-24T01:07:20.088Z","repository":{"id":37579836,"uuid":"144860855","full_name":"rancoud/Application","owner":"rancoud","description":"Application Package","archived":false,"fork":false,"pushed_at":"2025-08-21T06:30:22.000Z","size":656,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-21T09:23:47.633Z","etag":null,"topics":["application","composer","coverage","database","env","environment","http","packagist","php","php7","php8","phpdotenv","phpunit","psr-15","psr-7","router","session","skeleton"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/rancoud/application","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rancoud.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-08-15T14:05:27.000Z","updated_at":"2025-08-17T23:21:21.000Z","dependencies_parsed_at":"2023-09-27T16:58:56.661Z","dependency_job_id":"1b19f469-147b-4466-a149-72c756cb2b4c","html_url":"https://github.com/rancoud/Application","commit_stats":{"total_commits":126,"total_committers":4,"mean_commits":31.5,"dds":"0.32539682539682535","last_synced_commit":"04a4b30e193ba80106ebbaec6785d545863fe9d0"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"purl":"pkg:github/rancoud/Application","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rancoud%2FApplication","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rancoud%2FApplication/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rancoud%2FApplication/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rancoud%2FApplication/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rancoud","download_url":"https://codeload.github.com/rancoud/Application/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rancoud%2FApplication/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271778236,"owners_count":24819265,"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","status":"online","status_checked_at":"2025-08-23T02:00:09.327Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","composer","coverage","database","env","environment","http","packagist","php","php7","php8","phpdotenv","phpunit","psr-15","psr-7","router","session","skeleton"],"created_at":"2024-09-24T20:11:40.595Z","updated_at":"2025-08-24T01:07:20.047Z","avatar_url":"https://github.com/rancoud.png","language":"PHP","readme":"# Application Package\n\n![Packagist PHP Version Support](https://img.shields.io/packagist/php-v/rancoud/application)\n[![Packagist Version](https://img.shields.io/packagist/v/rancoud/application)](https://packagist.org/packages/rancoud/application)\n[![Packagist Downloads](https://img.shields.io/packagist/dt/rancoud/application)](https://packagist.org/packages/rancoud/application)\n[![Composer dependencies](https://img.shields.io/badge/dependencies-2-brightgreen)](https://github.com/rancoud/application/blob/master/composer.json)\n[![Test workflow](https://img.shields.io/github/actions/workflow/status/rancoud/application/test.yml?branch=master)](https://github.com/rancoud/application/actions/workflows/test.yml)\n[![Codecov](https://img.shields.io/codecov/c/github/rancoud/application?logo=codecov)](https://codecov.io/gh/rancoud/application)\n\nApplication skeleton with strict minimum Router and Environment.  \n\n## Dependencies\nEnvironment package: [https://github.com/rancoud/Environment](https://github.com/rancoud/Environment)  \nRouter package: [https://github.com/rancoud/Router](https://github.com/rancoud/Router)  \n\n## Installation\n```php\ncomposer require rancoud/application\n```\n\n## How to use it?\n### General\n#### Requirements\nYou need `.env` file and route file called for example `routes.php`  \nContent of default `.env` (all values are optionals, you can use an empty `.env` file if you want)\n```dotenv\n# setup timezone, by default use UTC (valid timezones are checked against DateTimeZone::listIdentifiers())\nTIMEZONE=null\n\n# file names that contain route configurations, if null it will load all files in current folder provided to the Application constructor\nROUTES=null\n\n# to enable all DEBUG_* parameters\nDEBUG=false\n\n# enable error_reporting: show php errors\nDEBUG_PHP=false\n\n# save PSR-7 request object for Application-\u003egetDebugInfos()\nDEBUG_REQUEST=false\n\n# save PSR-7 response object for Application-\u003egetDebugInfos()\nDEBUG_RESPONSE=false\n\n# save queries for Application-\u003egetDebugInfos()\nDEBUG_DATABASE=false\n\n# add all values of Session object to Application-\u003egetDebugInfos()\nDEBUG_SESSION=false\n\n# add memory usage/limit/percentage to Application-\u003egetDebugInfos()\nDEBUG_MEMORY=false\n\n# save elapsed time of each call of Application-\u003erun() for Application-\u003egetDebugInfos()\nDEBUG_RUN_ELAPSED_TIMES=false\n\n# add all included files included to Application-\u003egetDebugInfos()\nDEBUG_INCLUDED_FILES=false\n```\n`DEBUG_*` infos are available with `Application-\u003egetDebugInfos();` (except `DEBUG_PHP`)  \nContent of `routes.php`\n```php\n\u003c?php\n\nuse Rancoud\\Http\\Message\\Factory\\Factory;\nuse Rancoud\\Http\\Message\\Stream;\n\n/** @var \\Rancoud\\Router\\Router $router */\n$router-\u003eany('/home', static function ($request, $next) {\n    return (new Factory())-\u003ecreateResponse()-\u003ewithBody(Stream::create('hello world'));\n});\n```\n#### Usage\n```php\n// you have to set thoses required folders\n$folders = [\n    'ROOT' =\u003e 'folder/path/of/env',    // ROOT is used to read the .env file (must be a folder)\n    'ROUTES' =\u003e 'folder/path/of/routes'   // ROUTES is used to initialize the router with routes (must be a folder, so it will read php files inside it)\n];\n\n$app = new Application($folders);\n\n// create server request from globals\n$request = (new \\Rancoud\\Http\\Message\\Factory\\Factory())-\u003ecreateServerRequestFromGlobals();\n\n// you can also create request from scratch for example\n// $request = new \\Rancoud\\Http\\Message\\ServerRequest('GET', '/home');\n\n// $response can be null if no route AND no default404 has been found by the Router\n$response = $app-\u003erun($request);\n\n// you can send response output directly (if not null of course)\n$response-\u003esend();\n```\n\nYou can add more folders in constructor  \n\n```php\n$folders = [\n    'ROOT' =\u003e 'folder/path/of/env',\n    'ROUTES' =\u003e 'folder/path/of/routes',\n    'EXTRA' =\u003e 'folder/path/of/extra'\n];\n\n$app = new Application($folders);\n\n// you can access to specific folders\n$folderExtra = Application::getFolder('EXTRA');\n```\n\n### Environment File  \nYou can specify another environment file instead of using .env in ROOT folder  \n\n```php\n$env = new Environment(['folder/path/of/env'], 'another.env');\n$app = new Application($folders, $env);\n\n// you can access to the environment\n$config = Application::getConfig();\n```\n\n### Routes  \nBy default it will load all php files in the ROUTES folder.  \nYou can specify in .env file which routes files you want to use.  \n```dotenv\n# in this example, it will require() 3 files: www.php , backoffice.php and api.php in the routes folder\nROUTES=www,backoffice,api\n```\n\nThis example show how to add routes for the router  \n\n```php\n$config = [\n    'routes' =\u003e [\n        [\n            'methods'     =\u003e ['GET'],\n            'url'         =\u003e '/',\n            'callback'    =\u003e function($a,$b){\n                return (new MessageFactory())-\u003ecreateResponse(200, null, [], 'home');\n            },\n            'name'        =\u003e 'test_home'\n        ]\n    ]\n];\n\n/* @var \\Rancoud\\Router\\Router $router */\n$router-\u003esetupRouterAndRoutesWithConfigArray($config);\n```\n\n### Router  \n```php\n$app = new Application($folders, $env);\n\n$router = Application::getRouter();\n```\n\n### Database  \nYou have to use this [Database package](https://github.com/rancoud/Database)  \n```php\n$app = new Application($folders, $env);\n\nApplication::setDatabase($database);\n$db = Application::getDatabase();\n\n$infos = $app-\u003egetDebugInfos();\n// when enabled, all saved queries will be display in $infos['database']\n```\nYou are free to use something else if you don't use functions `setDatabase` and `getDatabase`.  \n\n### Session  \nYou can use this [Session package](https://github.com/rancoud/Session)  \nIt is used in the function `getDebugInfos()`  \nYou are free to use something else.  \n\n### Timezone  \nBy default the timezone used will be UTC  \nYou can specify a timezone in .env file  \n```dotenv\n# valid timezones are checked with DateTimeZone::listIdentifiers()\nTIMEZONE=\"Europe/Paris\"\n```\n\n### Debug Infos\nYou have to enable it in .env file\n```dotenv\n# to enable all DEBUG_* parameters\nDEBUG=true\n\n# enable error_reporting: show php errors\nDEBUG_PHP=true\n\n# save PSR-7 request object for Application-\u003egetDebugInfos()\nDEBUG_REQUEST=true\n\n# save PSR-7 response object for Application-\u003egetDebugInfos()\nDEBUG_RESPONSE=true\n\n# save queries for Application-\u003egetDebugInfos()\nDEBUG_DATABASE=true\n\n# add all values of Session object to Application-\u003egetDebugInfos()\nDEBUG_SESSION=true\n\n# add memory usage/limit/percentage to Application-\u003egetDebugInfos()\nDEBUG_MEMORY=true\n\n# save elapsed time of each call of Application-\u003erun() for Application-\u003egetDebugInfos()\nDEBUG_RUN_ELAPSED_TIMES=true\n\n# add all included files included to Application-\u003egetDebugInfos()\nDEBUG_INCLUDED_FILES=true\n```\n\n### Bags\nYou can put whatever you want in \"bags\", like your own database driver\n```php\n$app = new Application($folders, $env);\n\nApplication::setInBag('db', $mydb);\n$dbInBag = Application::getFromBag('db');\nApplication::removeFromBag('db');\n```\n\n## Application Constructor\n### Settings\n#### Mandatory\n| Parameter | Type  | Description                                  |\n|-----------|-------|----------------------------------------------|\n| folders   | array | Folder's list. ROOT and ROUTES are mandatory |\n\n#### Optionals\n| Parameter | Type                            | Default value | Description                 |\n|-----------|---------------------------------|---------------|-----------------------------|\n| env       | Rancoud\\Environment\\Environment | null          | Setup a different .env file |\n\n## Application Methods\n### General Commands  \n* run(request: \\Psr\\Http\\Message\\ServerRequestInterface): ?\\Rancoud\\Http\\Message\\Response  \n* getDebugInfos(): array  \n\n### Static Methods  \n* getFolder(index: string): string  \n* getInstance(): Rancoud\\Application\\Application  \n* getConfig(): Rancoud\\Environment\\Environment  \n* setDatabase(database: Rancoud\\Database\\Database): void  \n* getDatabase(): ?Rancoud\\Database\\Database  \n* getRouter(): Rancoud\\Router\\Router  \n* getFromBag(name: string): mixed  \n* removeFromBag(name: string): void  \n* setInBag(name: string, object: mixed): void  \n\n## Optionals Dependencies\n[Database package: https://github.com/rancoud/Database](https://github.com/rancoud/Database)  \n[Session package: https://github.com/rancoud/Session](https://github.com/rancoud/Session)  \n\n## How to Dev\n`composer ci` for php-cs-fixer and phpunit and coverage  \n`composer lint` for php-cs-fixer  \n`composer test` for phpunit and coverage  \n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Francoud%2Fapplication","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Francoud%2Fapplication","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Francoud%2Fapplication/lists"}