{"id":18620816,"url":"https://github.com/exts/starch","last_synced_at":"2025-11-03T12:30:26.811Z","repository":{"id":114941317,"uuid":"110395100","full_name":"exts/starch","owner":"exts","description":"Starch binds together components into a micro-framework. ","archived":false,"fork":false,"pushed_at":"2017-10-16T14:46:45.000Z","size":78,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-27T04:26:21.840Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":false,"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/exts.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-12T01:34:59.000Z","updated_at":"2020-02-11T12:35:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"7fc39fed-f773-429f-865a-72db263db13a","html_url":"https://github.com/exts/starch","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exts%2Fstarch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exts%2Fstarch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exts%2Fstarch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exts%2Fstarch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/exts","download_url":"https://codeload.github.com/exts/starch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239414206,"owners_count":19634394,"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":[],"created_at":"2024-11-07T04:08:05.226Z","updated_at":"2025-11-03T12:30:26.781Z","avatar_url":"https://github.com/exts.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# starchphp/starch\n\n\n[![Build Status](https://img.shields.io/travis/starchphp/starch.svg?style=flat-square)](https://travis-ci.org/starchphp/starch)\n[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/starchphp/starch.svg?style=flat-square)](https://scrutinizer-ci.com/g/starchphp/starch/?branch=master)\n[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/starchphp/starch.svg?style=flat-square)](https://scrutinizer-ci.com/g/starchphp/starch/?branch=master)\n\nStarch binds a bunch of PSR compatible components together to form a functioning micro-framework.\n\n## Installation\n\nRequire the package with composer\n\n```bash\ncomposer require starchphp/starch\n```\n\n## Usage\n\n\nCreate a new App, define routes, add middlewares and run the app.\n\n```php\n\u003c?php\n\nuse Interop\\Http\\ServerMiddleware\\DelegateInterface;\nuse Starch\\App;\nuse Starch\\Router\\RouterMiddleware;\nuse Zend\\Diactoros\\Response;\n\nrequire('../vendor/autoload.php');\n\n$app = new App();\n\n$app-\u003eget('/', function() {\n    $response = new Response();\n    $response-\u003egetBody()-\u003ewrite('Hello');\n\n    return $response;\n});\n$app-\u003eget('/hello/{name}', function($request, $name) {\n    $response = new Response();\n    $response-\u003egetBody()-\u003ewrite(sprintf('Hello, %s!', $name));\n\n    return $response;\n});\n\n$app-\u003eadd(function($request, DelegateInterface $next) {\n    $response = $next-\u003eprocess($request);\n    $response-\u003egetBody()-\u003ewrite(', world! ');\n\n    return $response;\n});\n$app-\u003eadd(function($request, DelegateInterface $delegate) {\n    $response = $delegate-\u003eprocess($request);\n\n    $response-\u003egetBody()-\u003ewrite(' How are you?');\n\n    return $response;\n}, '/hello');\n\n$app-\u003eadd(RouterMiddleware::class);\n\n$app-\u003erun();\n\n```\n\n#### Constraining middleware to certain paths\n\nThe `App::add` method has an optional second `$pathConstraint` parameter. Add a (part of a) route path here to limit the\n execution of this middleware to this route. \n\n#### RouterMiddleware\nThe RouterMiddleware is not added by default. You should add it yourself at the end of the stack or add one of your own.\n\n### Container\n\nBy default, Starch uses php-di as it's container. If you want to extend the App to your own, you can override \n`App::configureContainer` to add your own dependencies. Make sure to either call `parent::configureContainer` or make sure \nyou define the required definitions (see lower).\n\nIf you want, you can use another PSR-11 compatible container with Starch, simply pass it as a parameter when creating the app:\n \n ```php\n $app = new App($myContainer);\n ```\n\n#### Required definitions\n\nYou must add the following services to your container:\n\n- `Invoker\\InvokerInterface`: [PHP-DI/Invoker](https://github.com/PHP-DI/Invoker) is recommended.\n- `Zend\\Diactoros\\Response\\EmitterInterface`: The built in `Zend\\Diactoros\\Response\\SapiEmitter` is recommended.\n- `Starch\\Middleware\\StackInterface`: Should be an instance of `Starch\\Middleware\\Stack`, unless you decide to override this.\n\nAditionally, if your container does not support auto-wiring, the following should be defined as an instance of themselves as well:\n\n- `Starch\\Router\\Router`\n- `Starch\\Exception\\ExceptionHandler`\n- `Starch\\Router\\RouterMiddleware`\n\n## Components used\n\nThe following components are used to provide a coherent whole\n\n- [zendframework/zend-diactoros](https://github.com/zendframework/zend-diactoros) provides the PSR-7 interfaces\n- [php-di/php-di](https://github.com/PHP-DI/PHP-DI) provides a PSR-11 container\n- [nikic/fast-route](https://github.com/nikic/FastRoute) is used for the routing\n\n## How it works\n\n- You construct a new App (optionally extending it to configure your own container services)\n- You add routes (which get added to the Router) and middlewares (which get added to the Stack)\n- You call `app-\u003erun()`, which will construct a request from globals, process the request and emit the returned response\n- To process the request to get a response:\n    - It's dispatched to our Router, which calls nikic's FastRouter. If the request matches a route, the request gets tagged with the route as attribute and is returned.\n    - Upon errors in the dispatcher, appropriate HttpExceptions are thrown\n    - Next, the request (now enriched with route) is sent to the middleware stack.\n    - The stack will return Delegates that call the middlewares in a First In, First Out order.\n    - Once the stack is empty, it will return one last Delegate that actually calls the route handler (with potential route arguments)\n    \n## Comparison with other frameworks\n \n Other micro frameworks exist that handle middleware too. Here's a comparison explaining why and where Starch is different:\n \n |                                                           |                                                                            Slim                                                                           |                                      Silex                                     |              Starch             |\n |-----------------------------------------------------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------:|:------------------------------------------------------------------------------:|:-------------------------------:|\n |        Single `-\u003eadd()` interface to add middleware       |                                                                            Yes                                                                            |                No  (separate `-\u003ebefore()` and `-\u003eafter()` calls)               |               Yes               |\n | Unified queue with full control over middleware execution |              No, outer middleware are app-bound, then follow route group middleware, then route middleware as inner most layers of the stack.             |                                       yes                                      |               Yes               |\n |                 Middleware execution order                |                                                                 FILO (First In, Last Out)                                                                 |            FIFO (First In, First Out) with optional priority control           |               FIFO              |\n |                    Middleware interface                   | \"Double pass\" See [PSR-15 meta discussion](https://github.com/php-fig/fig-standards/blob/master/proposed/http-middleware/middleware-meta.md#4-approaches) | Separate interfaces depending on wether it's a `before` or `after` middleware. | PSR-15 compatible \"single pass\" |\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexts%2Fstarch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexts%2Fstarch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexts%2Fstarch/lists"}