{"id":23842370,"url":"https://github.com/php-toolkit/di","last_synced_at":"2025-09-07T18:31:58.304Z","repository":{"id":57071736,"uuid":"123846625","full_name":"php-toolkit/di","owner":"php-toolkit","description":"dependency injection container","archived":false,"fork":false,"pushed_at":"2019-06-24T14:27:26.000Z","size":30,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-17T17:04:55.764Z","etag":null,"topics":["container","dependency-manager"],"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/php-toolkit.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}},"created_at":"2018-03-05T01:19:53.000Z","updated_at":"2023-05-21T12:38:01.000Z","dependencies_parsed_at":"2022-08-24T14:54:29.211Z","dependency_job_id":null,"html_url":"https://github.com/php-toolkit/di","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-toolkit%2Fdi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-toolkit%2Fdi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-toolkit%2Fdi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-toolkit%2Fdi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/php-toolkit","download_url":"https://codeload.github.com/php-toolkit/di/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232240701,"owners_count":18493527,"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":["container","dependency-manager"],"created_at":"2025-01-02T18:38:20.406Z","updated_at":"2025-01-02T18:38:20.942Z","avatar_url":"https://github.com/php-toolkit.png","language":"PHP","readme":"# Dependency injection container\n\n简单的容器管理实现\n\n## Install\n\n```bash\ncomposer require toolkit/di\n```\n\n## 注册服务\n\n```php\npublic function set(string $id, mixed $definition, array $opts = []): Container\n```\n\n### 参数说明\n\n#### 服务ID名\n\n string `$id` 服务组件注册id\n\n#### 服务定义 \n \nmixed(string|array|object|callback) `$definition` 服务实例对象|服务信息定义\n\n- string:\n\n```php\n   $definition = className\n```\n\n- array:\n\n```php    \n   $definition = [\n      // 1. 仅类名 参数($definition[0])则传入对应构造方法\n      'class' =\u003e 'className',\n      // 2. 类的静态方法,  参数($definition[0])则传入对应方法 className::staticMethod(args...)\n      'class' =\u003e 'className::staticMethod',\n      // 3. 类的动态方法,  参数($definition[0]) 则传入对应方法 (new className)-\u003emethod(args...)\n      'class' =\u003e 'className-\u003emethod',\n \n      // 设置参数方式, 没有key\n      [\n          arg1,arg2,arg3,...\n      ]\n \n      // 设置属性 ， // prop1 prop2 prop3 将会被收集 作为属性\n      prop1 =\u003e value1,\n      prop2 =\u003e value2,\n      ... ...\n      \n      // 一些服务设置(别名,是否共享). 将会合并到最后一个参数中\n      '_options' =\u003e [...] \n   ]\n```\n\n- object:\n\n```php\n   $definition = new xxClass();\n```\n\n- closure:\n\n```php\n   $definition = function($di){ \n        return object;\n   };\n```\n \n#### 选项\n \n- array `$opts` 选项\n\n```php\n  [\n   'shared' =\u003e (bool), 是否共享,单例\n   'locked' =\u003e (bool), 是否锁定服务\n   'aliases' =\u003e (array), 别名\n   'init' =\u003e (bool), 立即初始化\n  ]\n```\n\n## License\n\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-toolkit%2Fdi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphp-toolkit%2Fdi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-toolkit%2Fdi/lists"}