{"id":20085424,"url":"https://github.com/mkgor/simple-di","last_synced_at":"2026-06-05T06:31:46.740Z","repository":{"id":57018038,"uuid":"260292783","full_name":"mkgor/simple-di","owner":"mkgor","description":"SimpleDI is a lightweight and easy to use dependency injection container for PHP.","archived":false,"fork":false,"pushed_at":"2020-06-04T09:14:43.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-13T02:17:16.346Z","etag":null,"topics":["dependecy-injection","di","dic","pattern","php"],"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/mkgor.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":"2020-04-30T18:51:19.000Z","updated_at":"2020-06-04T09:14:46.000Z","dependencies_parsed_at":"2022-08-22T11:31:22.745Z","dependency_job_id":null,"html_url":"https://github.com/mkgor/simple-di","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/mkgor%2Fsimple-di","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkgor%2Fsimple-di/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkgor%2Fsimple-di/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkgor%2Fsimple-di/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mkgor","download_url":"https://codeload.github.com/mkgor/simple-di/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241518038,"owners_count":19975366,"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":["dependecy-injection","di","dic","pattern","php"],"created_at":"2024-11-13T15:55:53.600Z","updated_at":"2026-06-05T06:31:46.736Z","avatar_url":"https://github.com/mkgor.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SimpleDI\nSimpleDI is a lightweight and easy to use dependency injection container for PHP.\n\n## Installation\nYou can install SimpleDI via composer\n\n``composer require mkgor/simple-di``\n\nThat's it! You already can use it, because it need a little configuration to provide base functionality of DIC\n\n## How to use it?\nJust call ``$container-\u003eget()`` method and it'll resolve all dependencies of specified class and returns it to you!\n\n\n*SomeDependency.php*\n```php\n\n\u003c?php\n\nclass SomeDependency {\n    public $anotherDependency;\n\n\tpublic function __construct(AnotherDependency $b) {\n\t\t$this-\u003eanotherDependency = $b;\n\t}\n}\n```\n\n*AnotherDependency.php*\n\n```php\n\n\u003c?php\n\nclass AnotherDependency {\n\tpublic function sayHello() {\n\t\techo \"Hello from AnotherDependency\";\n\t}\n}\n```\n\n\n*test.php*\n\n```php\n\u003c?php\n\nrequire \"vendor/autoload.php\";\n\n$container = new \\SimpleDI\\Container(__DIR__ . '/config.php');\n\n//Output: Hello from AnotherDependency\n$container-\u003eget(SomeDependency::class)-\u003eanotherDependency-\u003esayHello();\n```\n\n*config.php*\n\n```php\n\u003c?php\n\nreturn [\n    'singleton' =\u003e [],\n    'definition' =\u003e [],\n];\n```\n\n## Getting class by alias\nYou can specify alias for some class and call it by that alias using SimpleDI\n\n```php\n\u003c?php\n\nreturn [\n    'singleton' =\u003e [],\n\n    'definition' =\u003e [\n        'aliasName' =\u003e [\n            'classname' =\u003e SomeClass::class,\n            'arguments' =\u003e []\n        ]\n    ],\n];\n```\n\n```php\n\u003c?php\n\nrequire \"vendor/autoload.php\";\n\n$container = new \\SimpleDI\\Container(__DIR__ . '/config.php');\n\n/** @var SomeClass $someClass */\n$someClass = $container-\u003eget('aliasName');\n```\n\n## Declaring singletons\nIf you have some class which will be created one time during request lifetime, you can declare it like singleton in configuration.\nSimpleDI will create its instance one time and save it in singletons container\n\n```php\n\u003c?php\n\nreturn [\n    'singleton' =\u003e [\n        'aliasForSingleton' =\u003e [\n            'classname' =\u003e SomeSingleton::class,\n            'arguments' =\u003e []\n        ]\n    ],\n\n    'definition' =\u003e []\n];\n```\n\n```php\n\u003c?php\n\nrequire \"vendor/autoload.php\";\n\n$container = new \\SimpleDI\\Container(__DIR__ . '/config.php');\n\n/** @var SomeSingleton $someClass */\n$someClass = $container-\u003eget('aliasForSingleton');\n$someClass-\u003ea = 4;\n\n// Output: 4\necho $someClass-\u003ea;\n\n$someClass2 = $container-\u003eget('aliasForSingleton');\n\n// Output: 4\necho $someClass2-\u003ea;\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkgor%2Fsimple-di","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmkgor%2Fsimple-di","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkgor%2Fsimple-di/lists"}