{"id":15028201,"url":"https://github.com/passchn/cakephp-simple-di","last_synced_at":"2026-01-26T00:06:20.098Z","repository":{"id":224225039,"uuid":"762770649","full_name":"passchn/cakephp-simple-di","owner":"passchn","description":"Dependency Injection plugin for CakePHP","archived":false,"fork":false,"pushed_at":"2024-08-18T18:14:23.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-10T17:29:43.512Z","etag":null,"topics":["cakephp","cakephp4","cakephp5","dependency-injection","php","php82"],"latest_commit_sha":null,"homepage":"","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/passchn.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-24T16:38:56.000Z","updated_at":"2024-08-18T18:12:41.000Z","dependencies_parsed_at":"2024-08-09T21:07:58.643Z","dependency_job_id":null,"html_url":"https://github.com/passchn/cakephp-simple-di","commit_stats":null,"previous_names":["passchn/cakephp-simple-di"],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/passchn/cakephp-simple-di","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/passchn%2Fcakephp-simple-di","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/passchn%2Fcakephp-simple-di/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/passchn%2Fcakephp-simple-di/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/passchn%2Fcakephp-simple-di/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/passchn","download_url":"https://codeload.github.com/passchn/cakephp-simple-di/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/passchn%2Fcakephp-simple-di/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28761894,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-25T23:06:19.311Z","status":"ssl_error","status_checked_at":"2026-01-25T23:03:50.555Z","response_time":113,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["cakephp","cakephp4","cakephp5","dependency-injection","php","php82"],"created_at":"2024-09-24T20:07:47.483Z","updated_at":"2026-01-26T00:06:20.076Z","avatar_url":"https://github.com/passchn.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SimpleDI plugin for CakePHP\n\n## Installation\n\nYou can install this plugin into your CakePHP application using [composer](https://getcomposer.org).\n\nThe recommended way to install composer packages is:\n\n```sh\ncomposer require passchn/cakephp-simple-di\n```\n\nLoad the plugin:\n\n```sh\nbin/cake plugin load Passchn/SimpleDI\n```\n\n## Usage\n\nIn your `Application.php`:\n\n```php\npublic function services(ContainerInterface $container): void\n{\n    Configure::load('app_di');\n    \n    DIManager::create($container)\n        // to add individual services: \n        -\u003eaddServices(Configure::readOrFail('DI.services'))\n        /**\n        * to collect multiple services, define a module: \n        * @see \\Passchn\\SimpleDI\\Module\\Module\\ModuleInterface\n        */\n        -\u003eaddModules(Configure::readOrFail('DI.modules')) \n        /**\n        * a plugin can define multiple modules: \n        * @see \\Passchn\\SimpleDI\\Module\\Plugin\\PluginInterface\n        */\n        -\u003eaddPlugin(SomePlugin::class); \n}\n```\n\nThen, define Factories/Modules in your `app_di.php`:\n\n```php\nreturn [\n    'DI' =\u003e [\n        'services' =\u003e [\n            NewsletterService::class =\u003e NewsletterServiceFactory::class,\n            CheckoutService::class =\u003e CheckoutServiceFactory::class,\n            PaymentService::class =\u003e fn () =\u003e new PaymentService(),\n        ],\n        'modules' =\u003e [\n            MyModule::class,\n        ],\n    ],\n];\n```\n\nFactories should be Invokables or class-strings of Invokables. \n\nYou can then use the Service e.g. in Controller Actions:\n\n```php\nclass ExamplesController {\n    \n    public function someAction(NewsletterService $service): Response \n    {\n        $service-\u003edoSomething();\n    }\n}\n```\n\nIf real DI is not possible, e.g. in ViewCells, you can use the `ServiceLocator` to receive the container or Services.\n\n```php\nPasschn\\SimpleDI\\Module\\ServiceLocator\\ServiceLocator::get(NewsletterService::class); // the service\n```\n\nThis only works if you loaded the plugin or registered the container yourself, e.g.:\n\n```php\n// in your Application::services()\nServiceLocator::setContainer($container);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpasschn%2Fcakephp-simple-di","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpasschn%2Fcakephp-simple-di","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpasschn%2Fcakephp-simple-di/lists"}