{"id":15045101,"url":"https://github.com/indragunawan/middleware-bundle","last_synced_at":"2026-02-17T11:30:56.310Z","repository":{"id":56990934,"uuid":"157903898","full_name":"IndraGunawan/middleware-bundle","owner":"IndraGunawan","description":"Before and After filter implementation by using annotation","archived":false,"fork":false,"pushed_at":"2018-11-30T20:22:57.000Z","size":25,"stargazers_count":1,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-08T05:47:39.999Z","etag":null,"topics":["event-dispatcher","middleware","php","symfony","symfony-bundle"],"latest_commit_sha":null,"homepage":"","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/IndraGunawan.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}},"created_at":"2018-11-16T18:05:10.000Z","updated_at":"2019-10-15T19:12:04.000Z","dependencies_parsed_at":"2022-08-21T10:10:40.545Z","dependency_job_id":null,"html_url":"https://github.com/IndraGunawan/middleware-bundle","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/IndraGunawan%2Fmiddleware-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IndraGunawan%2Fmiddleware-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IndraGunawan%2Fmiddleware-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IndraGunawan%2Fmiddleware-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IndraGunawan","download_url":"https://codeload.github.com/IndraGunawan/middleware-bundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247785922,"owners_count":20995643,"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":["event-dispatcher","middleware","php","symfony","symfony-bundle"],"created_at":"2024-09-24T20:51:27.522Z","updated_at":"2025-10-08T19:01:57.724Z","avatar_url":"https://github.com/IndraGunawan.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MiddlewareBundle\n\n[![license](https://img.shields.io/github/license/IndraGunawan/middleware-bundle.svg?style=flat-square)](https://github.com/IndraGunawan/middleware-bundle/blob/master/LICENSE.md)\n[![Travis](https://img.shields.io/travis/IndraGunawan/middleware-bundle.svg?style=flat-square)](https://travis-ci.org/IndraGunawan/middleware-bundle)\n[![Scrutinizer Coverage](https://img.shields.io/scrutinizer/coverage/g/IndraGunawan/middleware-bundle.svg?style=flat-square)](https://scrutinizer-ci.com/g/IndraGunawan/middleware-bundle/?branch=master)\n[![Scrutinizer](https://img.shields.io/scrutinizer/g/IndraGunawan/middleware-bundle.svg?style=flat-square)](https://scrutinizer-ci.com/g/IndraGunawan/middleware-bundle/?branch=master)\n[![Source](https://img.shields.io/badge/source-IndraGunawan%2Fmiddleware--bundle-blue.svg)](https://github.com/IndraGunawan/middleware-bundle)\n[![Packagist](https://img.shields.io/badge/packagist-indragunawan%2Fmiddleware--bundle-blue.svg)](https://packagist.org/packages/indragunawan/middleware-bundle)\n\nMiddleware bundle provide simple implementation of [symfony before and after filter](https://symfony.com/doc/current/event_dispatcher/before_after_filters.html) by using annotation. this implementation is inspired by Laravel Middleware.\n\n## Installation\n\nIf your project already uses Symfony Flex, execute this command to\ndownload, register and configure the bundle automatically:\n\n```bash\ncomposer require indragunawan/middleware-bundle\n```\n\nIf you install without using Symfony Flex, first add the bundle by using composer then enable the bundle by adding `new Indragunawan\\MiddlewareBundle\\IndragunawanMiddlewareBundle()` to the list of registered bundles in the app/AppKernel.php file of your project.\n\n## Create middleware service\n\n```php\n\u003c?php\n// src/Middleware/Subscribed.php\nuse Indragunawan\\MiddlewareBundle\\Middleware\\BeforeFilterInterface;\nuse Indragunawan\\MiddlewareBundle\\Middleware\\AfterFilterInterface;\nuse Symfony\\Component\\HttpFoundation\\Request;\nuse Symfony\\Component\\HttpFoundation\\Response;\n\nclass Subscribed implements BeforeFilterInterface //, AfterFilterInterface // you can implement multi filter at once\n{\n    public static function supports()\n    {\n        return 'subscribed'; // return the filter name\n        // return ['subscribed', 10] // return [filter_name, priority] same like usual Symfony event\n    }\n\n    // implement this method for BeforeFilter\n    public function onBeforeFilter(Request $request, array $controller, ?int $requestType)\n    {\n        // your logic\n    }\n\n    // implement this method for AfterFilter\n    public function onAfterFilter(Request $request, Response $response, array $controller, ?int $requestType)\n    {\n        // your logic\n    }\n}\n```\n\n## Usage\n\nYou only need to create the annotation on class level.\n\n```php\n\u003c?php\n// app/Controller/HomepageController.php\nuse Indragunawan\\MiddlewareBundle\\Annotation\\BeforeFilter;\nuse Indragunawan\\MiddlewareBundle\\Annotation\\AfterFilter;\n\n/**\n * @BeforeFilter(\"subscribed\") // the 'subscribed' middleware will execute before every actions at this controller.\n * @BeforeFilter(\"subscribed\", only=\"index\") // the 'subscribed' middleware will execute ONLY before 'index' action at this controller.\n * @BeforeFIlter(\"subscribed\", except=\"create\") // the 'subscribed' middleware will execute before every actions at this controller EXCEPT 'create' action.\n *\n * @AfterFilter({\"subscribed\", \"other\"}) // the 'subscribed' and 'other' middleware will execute after every actions at this controller.\n * @AfterFilter({\"subscribed\", \"other\"}, only={\"index\",\"delete\"}) // the 'subscribed' and 'other' middleware will execute ONLY after 'index' and 'delete' action at this controller.\n * @AfterFilter({\"subscribed\", \"other\"}, except={\"create\",\"update\"}) // the 'subscribed' and 'other' middleware will execute after every actions at this controller EXCEPT 'create' and 'update' action.\n *\n * BeforeFilter and AfterFilter receive same arguments format.\n */\nclass HomepageController extends AbstractController\n{\n    // your action\n}\n```\n\n## TODO\n- Add tests\n\n## License\n\nThis bundle is under the MIT license. See the complete [license](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Findragunawan%2Fmiddleware-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Findragunawan%2Fmiddleware-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Findragunawan%2Fmiddleware-bundle/lists"}