{"id":18929540,"url":"https://github.com/thecodingmachine/drupal-stratigility-bridge","last_synced_at":"2025-10-27T03:04:17.391Z","repository":{"id":57067865,"uuid":"75106825","full_name":"thecodingmachine/drupal-stratigility-bridge","owner":"thecodingmachine","description":"This Drupal 8 module provides a bridge to include PSR-15 middlewares through Stratigility.","archived":false,"fork":false,"pushed_at":"2018-05-29T14:55:21.000Z","size":10,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":8,"default_branch":"1.0","last_synced_at":"2025-04-11T18:59:46.952Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"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/thecodingmachine.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}},"created_at":"2016-11-29T17:47:26.000Z","updated_at":"2018-05-29T20:29:27.000Z","dependencies_parsed_at":"2022-08-24T10:20:12.827Z","dependency_job_id":null,"html_url":"https://github.com/thecodingmachine/drupal-stratigility-bridge","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Fdrupal-stratigility-bridge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Fdrupal-stratigility-bridge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Fdrupal-stratigility-bridge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Fdrupal-stratigility-bridge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thecodingmachine","download_url":"https://codeload.github.com/thecodingmachine/drupal-stratigility-bridge/tar.gz/refs/heads/1.0","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249097872,"owners_count":21212365,"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-08T11:33:26.743Z","updated_at":"2025-10-27T03:04:12.360Z","avatar_url":"https://github.com/thecodingmachine.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# thecodingmachine/drupal-stratigility-bridge\n\nBridges between [Drupal 8](https://www.drupal.org/8) and PSR-15 middleware modules through the use of [Zend Framework's Stratigility](https://zendframework.github.io/zend-stratigility/).\n\n\n[![Latest Stable Version](https://poser.pugx.org/thecodingmachine/drupal-stratigility-bridge/v/stable)](https://packagist.org/packages/thecodingmachine/drupal-stratigility-bridge)\n[![Total Downloads](https://poser.pugx.org/thecodingmachine/drupal-stratigility-bridge/downloads)](https://packagist.org/packages/thecodingmachine/drupal-stratigility-bridge)\n[![Latest Unstable Version](https://poser.pugx.org/thecodingmachine/drupal-stratigility-bridge/v/unstable)](https://packagist.org/packages/thecodingmachine/drupal-stratigility-bridge)\n[![License](https://poser.pugx.org/thecodingmachine/drupal-stratigility-bridge/license)](https://packagist.org/packages/thecodingmachine/drupal-stratigility-bridge)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/thecodingmachine/drupal-stratigility-bridge/badges/quality-score.png?b=1.0)](https://scrutinizer-ci.com/g/thecodingmachine/drupal-stratigility-bridge/?branch=1.0)\n\n\u003e Version 1.0 allows you to use PSR-15 middlewares in Drupal 8.\n\u003e Versions 0.x are bridges with the now deprecated http-interop middlewares.\n\n## Installation\n\nThis project is a Drupal 8 module.\n\nThe recommended way to install drupal-stratigility-bridge is through [Composer](http://getcomposer.org/):\n\n```sh\ncomposer require thecodingmachine/drupal-stratigility-bridge\n```\n\n## Usage\n\nThis module will fill the Drupal container with a new `stratigility_pipe` entry (it is a `Zend\\Stratigility\\MiddlewarePipe`).\n\nYou can extend this entry in your own module to register a new middleware.\n\nIn Drupal services, you can simply add the `psr15_middleware` to your middleware service. This will automatically register the middleware in Stratigility's pipe.\n\nSo your `MYMODULE.services.yml` will certainly look like this:\n\n```yml\nservices:\n  my_middleware:\n    class:      Acme\\MyMiddleware\n    tags:\n      - { name: psr15_middleware }\n```\n\n## Using Drupal render arrays in PSR-15 middlewares\n\nThis module comes with a service that let's you [render Drupal \"arrays\"](https://www.drupal.org/docs/8/api/render-api/render-arrays).\n\nTo do so, simply inject the `drupal_array_render_caller` service in your controller and call the `getResponse` method.\n\nBelow is a sample middleware that returns a \"Hello world!\" Drupal page when the \"/foo\" page is hit:\n\n```php\nclass HelloWorldMiddleware implements MiddlewareInterface\n{\n    /**\n     * @var DrupalArrayRenderCaller\n     */\n    private $arrayRenderCaller;\n\n    public function __construct(DrupalArrayRenderCaller $arrayRenderCaller)\n    {\n        $this-\u003earrayRenderCaller = $arrayRenderCaller;\n    }\n\n    public function process(ServerRequestInterface $request, RequestHandlerInterface $delegate)\n    {\n        if (trim($request-\u003egetUri()-\u003egetPath(), '/') === 'foo') {\n            // Let's render a drupal page\n            return $this-\u003earrayRenderCaller-\u003egetResponse(array(\n                '#type' =\u003e 'markup',\n                '#title' =\u003e \"My title\",\n                '#markup' =\u003e t('Hello world')\n            ));\n        } else {\n            return $delegate-\u003eprocess($request);\n        }\n    }\n}\n```\n\n## How it works\n\nThis module listens to the `KernelEvents::REQUEST` event that is triggered at each request by the Drupal kernel.\n\nThe Symfony request is converted into a PSR-7 request and then is sent to Stratigility's middleware pipe.\n\nIf a middleware returns a PSR-7 response, this response is sent back to the user.\nIf all middleware are calling the \"next\" middleware, the final middleware is a dummy middleware that returns a \"418 I'm a teapot\" response.\nThis response is interpreted by the module as a \"I don't care\" response, and the rendering is passed to Drupal that will continue its rendering. \n\n## Limitations\n\nStratigility middlewares provided are not \"really\" middlewares as they cannot modify the request or the response from Drupal.\nThey run \"before\" Drupal, in a separate middleware stack. This is still very useful if you want to add your own router in front of Drupal!\n\nCurrently, the PSR-7 request is never converted back to a Symfony request. This means that any modification done on the PSR-7 request by a middleware will be ignored by Drupal.\nDue to the way Drupal is built, it is also impossible to catch the Drupal response in a PSR-15 middleware to modify it.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthecodingmachine%2Fdrupal-stratigility-bridge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthecodingmachine%2Fdrupal-stratigility-bridge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthecodingmachine%2Fdrupal-stratigility-bridge/lists"}