{"id":34003900,"url":"https://github.com/renakdup/simple-dic","last_synced_at":"2026-04-09T03:33:04.318Z","repository":{"id":209278885,"uuid":"722635249","full_name":"renakdup/simple-dic","owner":"renakdup","description":"🔥 Simple DIC - WordPress DI Container with autowiring in a single file allows you to easily use it in your PHP applications and especially convenient for WordPress plugins and themes.","archived":false,"fork":false,"pushed_at":"2025-10-02T15:12:23.000Z","size":142,"stargazers_count":10,"open_issues_count":10,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-14T13:53:45.206Z","etag":null,"topics":["dependency-injection-container","di","di-container","dic","dicontainer","php","php-di-container","php-dic","phpdi","phpdic","simple-di-container","simple-dic","wordpress","wordpress-di","wordpress-dic","wordpress-plugin","wordpress-theme"],"latest_commit_sha":null,"homepage":"https://github.com/renakdup/simple-php-dic","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/renakdup.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-11-23T15:16:05.000Z","updated_at":"2025-10-13T18:46:02.000Z","dependencies_parsed_at":"2024-03-07T22:22:49.801Z","dependency_job_id":"99586260-1b2c-409e-b242-96ddfb49e240","html_url":"https://github.com/renakdup/simple-dic","commit_stats":null,"previous_names":["renakdup/simple-dic","renakdup/simple-wordpress-dic","renakdup/simple-php-dic"],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/renakdup/simple-dic","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renakdup%2Fsimple-dic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renakdup%2Fsimple-dic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renakdup%2Fsimple-dic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renakdup%2Fsimple-dic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/renakdup","download_url":"https://codeload.github.com/renakdup/simple-dic/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renakdup%2Fsimple-dic/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31584578,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"online","status_checked_at":"2026-04-09T02:00:06.848Z","response_time":112,"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":["dependency-injection-container","di","di-container","dic","dicontainer","php","php-di-container","php-dic","phpdi","phpdic","simple-di-container","simple-dic","wordpress","wordpress-di","wordpress-dic","wordpress-plugin","wordpress-theme"],"created_at":"2025-12-13T10:02:30.831Z","updated_at":"2026-04-09T03:33:04.313Z","avatar_url":"https://github.com/renakdup.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple DIC - WordPress DI Container in one file for your plugin/project.\n[![UnitTests](https://github.com/renakdup/simple-wordpress-dic/actions/workflows/phpunit.yaml/badge.svg)](https://github.com/renakdup/simple-wordpress-dic/actions/workflows/phpunit.yaml)\n[![PHPStan](https://github.com/renakdup/simple-wordpress-dic/actions/workflows/phpstan.yaml/badge.svg)](https://github.com/renakdup/simple-wordpress-dic/actions/workflows/phpstan.yaml)\n\n[![Latest Stable Version](https://poser.pugx.org/renakdup/simple-dic/v)](https://packagist.org/packages/renakdup/simple-dic)\n[![PHP Version Require](https://poser.pugx.org/renakdup/simple-dic/require/php)](https://packagist.org/packages/renakdup/simple-dic)\n[![Total Downloads](https://poser.pugx.org/renakdup/simple-dic/downloads)](https://packagist.org/packages/renakdup/simple-dic)\n\nWordPress DI Container with **autowiring** in a single file **with NO dependencies** allows you to easily use it in your PHP applications and especially convenient for **WordPress** plugins and themes. \n\n\u003e [!IMPORTANT]  \n\u003e **100% code coverage**\n\n## Why choose Simple DI Container\n1. Easy to integrate in your WordPress project - just copy one file or install via Composer.\n2. No dependencies on other scripts or libraries.\n3. Supports auto-wiring `__constructor` parameters for classes as well as for scalar types that have default values.\n4. Supports PHP ^7.4|^8.\n5. Allow you following the best practices for developing your code.\n6. No PHPCS conflicts.\n7. Supports Lazy Load class instantiating.\n8. Lightweight and fast.\n\n## How to install in a project\nThere are several ways, you can choose what you more prefer:\n\n### Install via Composer\n```bash\ncomposer require renakdup/simple-php-dic\n```\n\n### Copy and paste file\n   1. Just copy the file `./src/Container.php` to your plugin directory or theme.\n   2. Rename `namespace` in the file  \n   from `Renakdup\\SimpleDIC` to `\u003cYour_Plugin_Name\u003e\\SimpleDIC`\n   3. Include the file.\n\n## How to use it\n\n### Get started:\n1. Create container instance.\n2. Set a service\n3. Get a service\n4. Use object\n```php\nuse Renakdup\\SimpleDIC\\Container;\n\n// create container\n$container = new Container();\n\n// set service\n$container-\u003eset( Paypal::class, function () {\n    return new Paypal();\n} );\n\n// get service\n$paypal = $container-\u003eget( Paypal::class );\n\n// use this object\n$paypal-\u003epay();\n```\n\nMethod `get()` works as a singleton. Service will be resolved once and cached inside the `$container`, new invocations of the `get()` method return the same object.\n\n```php\n$obj1 = $constructor-\u003eget( Paypal::class );\n$obj2 = $constructor-\u003eget( Paypal::class );\nvar_dump( $obj1 === $obj2 ) // true\n```\n\nIf you want to instantiate a service several times, then use the `make()` method. \n\n```php\n$obj1 = $constructor-\u003emake( Paypal::class );\n$obj2 = $constructor-\u003emake( Paypal::class );\nvar_dump( $obj1 === $obj2 ) // false\n```\n\n---\n\n### Factory\nFactory is an `anonymous function` that wrap creating an instance.  \nAllows to configure how an object will be created and allows to use `Conainer` instance inside the factory.\n\n```php\n$container-\u003eset( Paypal::class, function () {\n    return new Paypal();\n} );\n```\n\nAs well factories create objects in the Lazy Load mode. It means that object will be created just when you resolve it by using `get()` method:\n\n```php\n$container-\u003eset( Paypal::class, function () {\n    return new Paypal();\n} );\n\n$paypal = $constructor-\u003eget( Paypal::class ); // PayPal instance created\n```\n\n---\n\n### Primitives\nSimpleDIC allows setting values for the container for primitive types:\n```php\n$container-\u003eset( 'requests_limit', 100 );\n$container-\u003eset( 'post_type', 'products' );\n$container-\u003eset( 'users_ids', [ 1, 2, 3, 4] );\n\n$user_ids = $container-\u003eget( 'users_ids', [ 1, 2, 3, 4] );\n```\n\n---\n\n### Container inside factory\n**SimpleDIC** allows to get a `Container` instance inside a factory if you add parameter in a callback `( Container $c )`. This allows to get or resolve another services inside for building an object:\n```php\n$container-\u003eset( 'config', [\n    'currency' =\u003e '$',\n    'environment' =\u003e 'production',\n] );\n\n$container-\u003eset( Paypal::class, function ( Container $c ) {\n    return new Paypal( $c-\u003eget('config') );\n} );\n```\n\n---\n\n### Autowiring\n**SimpleDIС** autowiring feature **allows to `Container` automatically create and inject dependencies**.\n\nI'll show an example:\n```php\nclass PayPalSDK {}\nclass Logger {}\n\nclass Paypal {\n    public function __constructor( PayPalSDK $pal_sdk, Logger $logger ) {\n        //...\n    }\n}\n```\nAnd then when you create `Paypal::class`, you run `$container-\u003eget(Paypal::class)`, and `Container` identifies all classes in the constructor and resolves them. As if it's:\n```php\nnew Paypal( new PayPalSDK(), new Logger() );\n```\n---\nContainer autowiring can resolve default values for *primitive* parameters in a constructor:\n```php\nclass Logger {\n    public function __constructor( $type = 'filestorage', $error_lvl = 1 ) {\n        //...\n    }\n}\n```\n\nYou can use **auto-wiring** feature that allows to `Container` create an instances that requires in the `__constructor` of class as well as it resolves constructor dependencies for \n\n\n\u003e [!NOTE]\n\u003e But if object creating is more complex and requires configuring and you don't have parameters with default values in the constructor then you need to use `factory` for preparing service.\n\n---\n\n\n### Create an instance every time\n\nMethod `make()` resolves services by its name. It returns a new instance of service every time and supports auto-wiring.\n\n```php\n$conatainer-\u003emake( Paypal::class );\n```\n\n\u003e [!NOTE]  \n\u003e Constructor's dependencies will not instantiate every time.  \n\u003e If dependencies were resolved before then they will be passed as resolved dependencies.\n\nConsider example:\n```php\nclass PayPalSDK {}\n\nclass Paypal {\n    public PayPalSDK $pal_sdk;\n    public function __constructor( PayPalSDK $pal_sdk ) {\n        $this-\u003epal_sdk = $pal_sdk;\n    }\n}\n\n// if we create PayPal instances twice\n$paypal1 = $container-\u003emake( Paypal::class );\n$paypal2 = $container-\u003emake( Paypal::class );\n\nvar_dump( $paypal1 !== $paypal2 ); // true\nvar_dump( $paypal1-\u003epal_sdk === $paypal2-\u003epal_sdk ); // true\n```\nDependencies of PayPal service will not be recreated and will be taken from already resolved objects.\n\n---\n\n## PSR11 Compatibility\nin progress\n\n## Roadmap\n- [x] Add binding services with configuration\n- [x] Add auto-wiring for registered classes in DIC\n- [x] Add auto-wiring for defaults primitives for auto-fillings\n- [x] Add supporting invocable classes\n- [x] Add PSR11 interfaces in the Container.php.\n- [x] Add auto-wiring support for not bounded classes.\n- [x] Add resolved service storage (getting singleton).\n- [x] Add ability to create new instances of service every time.\n- [x] Improve performance.\n- [x] Fix deprecated `Use ReflectionParameter::getType() and the ReflectionType APIs should be used instead.` for PHP8\n- [x] Bind $container instance by default.\n- [ ] Add `remove` method.\n- [ ] Circular dependency protector.\n\n## Nice to have\n- [x] Integrate CI with running autotests\n- [x] Add badges with tests passed\n- [x] Add PHPStan analyzer\n- [x] Add code coverage badge\n- [ ] Add descriptions in the code for functions.\n- [ ] Choose codestyle\n- [x] Add on packagist\n- [ ] Add if class exists checks in the Container file?\n- [ ] Rename Container.php to SimpleContainer.php\n- [ ] Show stack trace when I have a debug only?\n- [ ] PHP 8 named arguments and autowiring.\n- [ ] Allow to set definitions via `__constructor`.\n- [ ] Add supporting Code Driven IoC.\n- [ ] Add configurations of Container.\n- [ ] Add Performance Benchmarks\n\n## License\n\n[![Software License][ico-license]](LICENSE)\n\nThe MIT License (MIT). Please see the [License File](LICENSE) for more information. \n\n[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frenakdup%2Fsimple-dic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frenakdup%2Fsimple-dic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frenakdup%2Fsimple-dic/lists"}