{"id":40713956,"url":"https://github.com/matecat/simple-dic","last_synced_at":"2026-01-21T13:05:17.774Z","repository":{"id":45293818,"uuid":"199996872","full_name":"matecat/simple-dic","owner":"matecat","description":"A simple Dependency Injection Container (DIC).","archived":false,"fork":false,"pushed_at":"2023-12-15T05:28:08.000Z","size":3369,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-18T12:17:34.274Z","etag":null,"topics":["container","dependency-injection","dependency-injection-container","dic","php"],"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/matecat.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-01T07:07:40.000Z","updated_at":"2019-09-05T13:12:38.000Z","dependencies_parsed_at":"2022-09-21T13:31:55.410Z","dependency_job_id":null,"html_url":"https://github.com/matecat/simple-dic","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"purl":"pkg:github/matecat/simple-dic","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matecat%2Fsimple-dic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matecat%2Fsimple-dic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matecat%2Fsimple-dic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matecat%2Fsimple-dic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/matecat","download_url":"https://codeload.github.com/matecat/simple-dic/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matecat%2Fsimple-dic/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28633747,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-21T04:47:28.174Z","status":"ssl_error","status_checked_at":"2026-01-21T04:47:22.943Z","response_time":86,"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":["container","dependency-injection","dependency-injection-container","dic","php"],"created_at":"2026-01-21T13:05:17.046Z","updated_at":"2026-01-21T13:05:17.768Z","avatar_url":"https://github.com/matecat.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple DIC\n\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/5bee3c5a5e774e5aba1fcf9f622f08d2)](https://www.codacy.com/app/mauretto78_2/simple-dic?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=mauretto78/simple-dic\u0026amp;utm_campaign=Badge_Grade)\n[![license](https://img.shields.io/github/license/matecat/simple-dic.svg)]()\n[![Packagist](https://img.shields.io/packagist/v/matecat/simple-dic.svg)]()\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/matecat/simple-dic/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/mauretto78/simple-dic/?branch=master)\n\n**Simple DIC** is a simple Dependency Injection Container(DIC).\n\n## Basic Usage\n\nTo init DIC you must provide a configuration file. Use `initFromFile` method:\n\nHere is a sample (in YAML format):\n\n```yaml\ndummy-key: 'dummy-value'\ndummy-array: [43243,2432,4324,445667]\nthree: 3\ntwo: 2\nacme:\n  class: Matecat\\SimpleDIC\\Dummy\\Acme\nacme-calculator:\n  class: Matecat\\SimpleDIC\\Dummy\\AcmeCalculator\n  method: init\n  method_arguments: ['@three', '@two']\nacme-parser:\n  class: Matecat\\SimpleDIC\\Dummy\\AcmeParser\n  arguments: ['string']\nacme-repo:\n  class: Matecat\\SimpleDIC\\Dummy\\AcmeRepo\n  arguments: ['@acme']\n```\n\nAfter pass the name of dependency, you can specify:\n\n* `class` : the full qualified class name \n* `arguments`: an array of arguments to pass to instantiate the class from the constructor\n* `method`: if you want to run a specific method of the class (method could be static or not not)\n* `method_arguments`: an array of arguments to pass to instantiate the runned class method\n\nIf you want to pass an entry already present to other one, simply use the '@' symbol.\n\n## Change Caching Directory\n\nYou cah use `setCacheDir` to setup yor cache directory. Do this **before** invoke `initFromFile` method:\n\n```php\nDIC::setCacheDir(__DIR__.'/../_cache_custom');\nDIC::initFromFile(__DIR__ . '/../config/ini/redis.ini');\n\n// ...\n```\n\n## Parameters\n\nIf you want to use a separate parameters file, you can use `DICParams` class. Take a look at the following example of params configuration file\n (YAML format):\n\n```yaml\nyour_secret_token: 'YOUR_SECRET_TOKEN'\nyour_secret_password: 'YOUR_SECRET_PASS'\n```\n\nYou can setup `DICParams` class now:\n\n```php\nuse Matecat\\SimpleDIC\\DICParams;\n\nDICParams::initFromFile('your_params_file.yaml');\n```\n\nAnd then, you can use '%' synthax in your DIC configuration file. Please bear in mind that you MUST set parameters **before** instantiate DIC. \n\n```yaml\nclient:\n    class: 'SimpleDIC\\Dummy\\Client'\n    arguments: ['%your_secret_token%', '%your_secret_password%']\n```\n\n## Environment Variable Support\n\nTo use your environment variable, simply follow the `%env(xxxx)%` synthax, consider this example:\n\n```yaml\nlogger:\n    class: 'Matecat\\SimpleDIC\\Dummy\\Logger'\n    arguments: ['%env(FOO)%']\n```\n\n## Retrieve an entry\n\nIn order to retrieve an entry use `get` method:\n\n```php\nuse Matecat\\SimpleDIC\\DIC;\n\n$dependency = DIC::get('key');\n```\n\nPlease note that the method returns:\n* `false` if the entry has a wrong configuration;\n* `NULL` if the entry does not exists.\n\n## Lazy loading and automatic caching\n\nThe entries are **lazy-loaded** when you invoke `get` or `has` method for the first time. \n\nIf you have apcu enabled on your system, DIC will automatically cache the entry in APCU store. Please note that the **id in cache always refers to the sha1() of the init file**.\n\n## Commands\n\nIf you have an application which uses [Symfony Console](https://github.com/symfony/console), you have some commands available:\n\n*  ```dic:debug```     Dumps the entry list in the DIC.\n\nYou can register the commands in your app, consider this example:\n\n```php\n#!/usr/bin/env php\n\u003c?php\nset_time_limit(0);\n\n...\n\nuse Symfony\\Component\\Yaml\\Yaml;\n\n// create symfony console app\n$app = new \\Symfony\\Component\\Console\\Application('Simple DIC', 'console tool');\n\n// config\n$configFile = __DIR__.'/../config/yaml/config.yaml';\n\n// add commands here\n$app-\u003eadd(new \\Matecat\\SimpleDIC\\Console\\DICDebug($configFile));\n$app-\u003erun();\n```\n\n## Support\n\nIf you found an issue or had an idea please refer [to this section](https://github.com/mauretto78/simple-dic/issues).\n\n## Authors\n\n* **Mauro Cassani** - [github](https://github.com/mauretto78)\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatecat%2Fsimple-dic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatecat%2Fsimple-dic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatecat%2Fsimple-dic/lists"}