{"id":17024658,"url":"https://github.com/michael-rubel/laravel-enhanced-container","last_synced_at":"2025-07-29T22:37:41.364Z","repository":{"id":37419112,"uuid":"406245016","full_name":"michael-rubel/laravel-enhanced-container","owner":"michael-rubel","description":"Laravel Service Container on steroids.","archived":false,"fork":false,"pushed_at":"2024-12-04T19:25:04.000Z","size":746,"stargazers_count":89,"open_issues_count":0,"forks_count":3,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-05-24T01:04:39.135Z","etag":null,"topics":["container","enhanced","ioc-container","laravel","looking-for-contributors","php","service-container"],"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/michael-rubel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":["https://paypal.com/donate/?hosted_button_id=KHLEL8PFS4AXJ"]}},"created_at":"2021-09-14T06:05:30.000Z","updated_at":"2025-05-16T00:28:57.000Z","dependencies_parsed_at":"2024-02-09T09:28:21.091Z","dependency_job_id":"8071bc9f-ba67-4f5e-985a-d11a8afe6728","html_url":"https://github.com/michael-rubel/laravel-enhanced-container","commit_stats":{"total_commits":573,"total_committers":3,"mean_commits":191.0,"dds":0.03315881326352532,"last_synced_commit":"dd9931862595f8c0cccfd193d1233a27354378b2"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"purl":"pkg:github/michael-rubel/laravel-enhanced-container","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michael-rubel%2Flaravel-enhanced-container","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michael-rubel%2Flaravel-enhanced-container/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michael-rubel%2Flaravel-enhanced-container/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michael-rubel%2Flaravel-enhanced-container/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/michael-rubel","download_url":"https://codeload.github.com/michael-rubel/laravel-enhanced-container/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michael-rubel%2Flaravel-enhanced-container/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267772713,"owners_count":24142094,"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-07-29T02:00:12.549Z","response_time":2574,"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":["container","enhanced","ioc-container","laravel","looking-for-contributors","php","service-container"],"created_at":"2024-10-14T07:26:30.062Z","updated_at":"2025-07-29T22:37:41.341Z","avatar_url":"https://github.com/michael-rubel.png","language":"PHP","funding_links":["https://paypal.com/donate/?hosted_button_id=KHLEL8PFS4AXJ"],"categories":[],"sub_categories":[],"readme":"![Method binding with Service Container   Call Proxy](https://github.com/michael-rubel/laravel-enhanced-container/assets/37669560/f7f2b1d0-68cb-485b-bdc5-93ea109f7e1d)\n\n# Laravel Enhanced Container\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/michael-rubel/laravel-enhanced-container.svg?style=flat-square)](https://packagist.org/packages/michael-rubel/laravel-enhanced-container)\n[![Total Downloads](https://img.shields.io/packagist/dt/michael-rubel/laravel-enhanced-container.svg?style=flat-square\u0026logo=packagist)](https://packagist.org/packages/michael-rubel/laravel-enhanced-container)\n[![Code Quality](https://img.shields.io/scrutinizer/quality/g/michael-rubel/laravel-enhanced-container.svg?style=flat-square\u0026logo=scrutinizer)](https://scrutinizer-ci.com/g/michael-rubel/laravel-enhanced-container/?branch=main)\n[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/michael-rubel/laravel-enhanced-container.svg?style=flat-square\u0026logo=scrutinizer)](https://scrutinizer-ci.com/g/michael-rubel/laravel-enhanced-container/?branch=main)\n[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/michael-rubel/laravel-enhanced-container/run-tests.yml?branch=main\u0026style=flat-square\u0026label=tests\u0026logo=github)](https://github.com/michael-rubel/laravel-enhanced-container/actions)\n[![PHPStan](https://img.shields.io/github/actions/workflow/status/michael-rubel/laravel-enhanced-container/phpstan.yml?branch=main\u0026style=flat-square\u0026label=larastan\u0026logo=laravel)](https://github.com/michael-rubel/laravel-enhanced-container/actions)\n\nThis package provides additional features for Laravel's Service Container.\n\n## #StandWithUkraine\n[![SWUbanner](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner2-direct.svg)](https://github.com/vshymanskyy/StandWithUkraine/blob/main/docs/README.md)\n\n## Contents\n  * [Installation](#installation)\n  * [Usage](#usage)\n    + [Resolve contextual binding outside of constructor](#resolve-contextual-binding-outside-of-constructor)\n    + [Method binding](#method-binding)\n    + [Method forwarding](#method-forwarding)\n\n## Installation\n\nInstall the package via composer (Laravel 11):\n```bash\ncomposer require michael-rubel/laravel-enhanced-container\n```\n\nIf you need the package for older versions of Laravel, check [changelog](https://github.com/michael-rubel/laravel-enhanced-container/releases).\n\n## Usage\n\n### Resolve contextual binding outside of constructor\n\n```php\ncall(ServiceInterface::class, context: static::class);\n\n// The `call` method automatically resolves the implementation from the interface you passed.\n// If you pass the context, the proxy tries to resolve contextual binding instead of global binding first.\n```\n\n[🔝 back to contents](#contents)\n\n### Method binding\nThis feature makes it possible to override the behavior of methods accessed using the `call`.\n\nAssuming that is your function in the service class:\n```php\nclass Service\n{\n    public function yourMethod(int $count): int\n    {\n        return $count;\n    }\n}\n```\n\nBind the service to an interface:\n```php\n$this-\u003eapp-\u003ebind(ServiceInterface::class, Service::class);\n```\n\nCall your service method through container:\n```php\ncall(ServiceInterface::class)-\u003eyourMethod(100);\n```\n\nFor example in feature tests:\n```php\n$this-\u003eapp-\u003ebind(ApiGatewayContract::class, InternalApiGateway::class);\n\nbind(ApiGatewayContract::class)-\u003emethod('performRequest', function ($service, $app, $params) {\n    // Note: you can access `$params` passed to the method call.\n\n    return true;\n});\n\n$apiGateway = call(ApiGatewayContract::class);\n$request = $apiGateway-\u003eperformRequest();\n$this-\u003eassertTrue($request);\n```\n\nNote: if you rely on interfaces, the proxy will automatically resolve bound implementation for you.\n\n#### Note for package creators\nIf you want to use method binding in your own package, you need to make sure the [`LecServiceProvider`](https://github.com/michael-rubel/laravel-enhanced-container/blob/main/src/LecServiceProvider.php) registered before you use this feature.\n```php\n$this-\u003eapp-\u003eregister(LecServiceProvider::class);\n```\n\n[🔝 back to contents](#contents)\n\n### Method forwarding\nThis feature automatically forwards the method if it doesn't exist in your class to the second one defined in the forwarding configuration.\n\nYou can define forwarding in your ServiceProvider:\n```php\nuse MichaelRubel\\EnhancedContainer\\Core\\Forwarding;\n\nForwarding::enable()\n    -\u003efrom(Service::class)\n    -\u003eto(Repository::class);\n```\n\nYou can as well use chained forwarding:\n```php\nForwarding::enable()\n    -\u003efrom(Service::class)\n    -\u003eto(Repository::class)\n    -\u003efrom(Repository::class)\n    -\u003eto(Model::class);\n```\n\n#### Important notes\n- Pay attention to which internal instance you're now working on in `CallProxy` when using forwarding. The instance may change without your awareness. If you interact with the same methods/properties on a different instance, the `InstanceInteractionException` will be thrown.\n- If you use `PHPStan/Larastan` you'll need to add the `@method` docblock to the service to make it static-analyzable, otherwise it will return an error that the method doesn't exist in the class.\n\n[🔝 back to contents](#contents)\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## License\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichael-rubel%2Flaravel-enhanced-container","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichael-rubel%2Flaravel-enhanced-container","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichael-rubel%2Flaravel-enhanced-container/lists"}