{"id":15789608,"url":"https://github.com/ytake/hh-container","last_synced_at":"2026-01-11T05:41:34.103Z","repository":{"id":57088282,"uuid":"84735163","full_name":"ytake/hh-container","owner":"ytake","description":"simple light weight service location container for hhvm/hack","archived":false,"fork":false,"pushed_at":"2018-12-22T17:37:53.000Z","size":44,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-05T22:02:31.013Z","etag":null,"topics":["container","hack","hacklang","hhvm","serviceloader"],"latest_commit_sha":null,"homepage":null,"language":"Hack","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/ytake.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":"2017-03-12T15:14:59.000Z","updated_at":"2018-12-22T17:37:55.000Z","dependencies_parsed_at":"2022-08-20T16:00:28.100Z","dependency_job_id":null,"html_url":"https://github.com/ytake/hh-container","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ytake%2Fhh-container","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ytake%2Fhh-container/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ytake%2Fhh-container/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ytake%2Fhh-container/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ytake","download_url":"https://codeload.github.com/ytake/hh-container/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246516711,"owners_count":20790289,"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","hack","hacklang","hhvm","serviceloader"],"created_at":"2024-10-04T22:02:32.910Z","updated_at":"2026-01-11T05:41:34.063Z","avatar_url":"https://github.com/ytake.png","language":"Hack","funding_links":[],"categories":[],"sub_categories":[],"readme":"# This Project Has Been Deprecated\n# HH-Container\nsimple light weight service location / dependency injection container\n\n[![Build Status](https://travis-ci.org/ytake/hh-container.svg?branch=master)](https://travis-ci.org/ytake/hh-container)\n\n## Installation\n\n```bash\n$ hhvm $(which composer) require ytake/hh-container\n```\n\n```json\n\"require\": {\n  \"hhvm\": \"\u003e=3.24\",\n  \"ytake/hh-container\": \"^1.0\"\n},\n```\n\n## Usage\n\n```hack\n$container = new \\Ytake\\HHContainer\\FactoryContainer();\n$container-\u003eset('testing', $container ==\u003e 'testing');\n$container-\u003eget('testing'); // return string\n```\n\n## Singleton or Prototype\n\ndefault *prototype*\n\n### SINGLETON\n\n```hack\n$container = new \\Ytake\\HHContainer\\FactoryContainer();\n$container-\u003eset('scope:singleton', $container ==\u003e new \\stdClass(), \\Ytake\\HHContainer\\Scope::Singleton);\n```\n\n### PROTOTYPE\n\n```hack\n$container = new \\Ytake\\HHContainer\\FactoryContainer();\n$container-\u003eset('scope:prototype', $container ==\u003e new \\stdClass(), \\Ytake\\HHContainer\\Scope::Prototype);\n```\n\n## Dependency Injection\n\n### set parameters\nsample class\n\n```hack\nfinal class MessageClass {\n  public function __construct(\n    protected string $message\n  ) {}\n\n  public function message(): string {\n    return $this-\u003emessage;\n  }\n}\n\nfinal class MessageClient {\n  public function __construct(\n    protected MessageClass $message\n  ) {}\n\n  public function message(): MessageClass {\n    return $this-\u003emessage;\n  }\n}\n```\n\n### Inject\n\n```hack\n$container = new \\Ytake\\HHContainer\\FactoryContainer();\n$container-\u003eset('message.class', $container ==\u003e new MessageClass('testing'));\n$container-\u003eset(MessageClient::class, $container ==\u003e {\n  $instance = $container-\u003eget('message.class');\n  invariant($instance instanceof MockMessageClass, 'error');\n  new MessageClient($instance);\n});\n$instance = $container-\u003eget(MessageClient::class);\n```\n\n### callable\nreturns the value of a callable with parameters supplied at calltime.\n\n```hack\nfinal class TestingInvokable {\n  public function __invoke(FactoryContainer $container): int {\n    return 1;\n  }\n}\n\n$container = new \\Ytake\\HHContainer\\FactoryContainer();\n$container-\u003eset(TestingInvokable::class, $container ==\u003e \n  $container-\u003ecallable(\n    new \\Ytake\\HHContainer\\Invokable(\n      new TestingInvokable(), '__invoke', $container\n    )\n  )\n);\n\n```\n\n## Use modules\n\n```hack\n\nuse Ytake\\HHContainer\\ServiceModule;\nuse Ytake\\HHContainer\\FactoryContainer;\n\nclass ExampleModule extends ServiceModule {\n  \n  public function provide(FactoryContainer $container): void {\n    $container-\u003eset('example', $container ==\u003e new \\stdClass());\n  }\n}\n\n```\n\n```hack\n$container = new \\Ytake\\HHContainer\\FactoryContainer();\n$container-\u003eregister(ExampleModule::class);\n$container-\u003elockModule();\n```\n\n## Service Factory\n\n```hack\nuse Ytake\\HHContainer\\Scope;\nuse Ytake\\HHContainer\\ServiceFactory;\nuse Ytake\\HHContainer\\FactoryContainer;\nuse Ytake\\HHContainer\\FactoryInterface;\n\nclass StringFactory implements FactoryInterface {\n  const type T = string;\n  public function provide(FactoryContainer $_container): StringFactory::T {\n    return 'testing';\n  }\n  public function scope(): Scope {\n    return Scope::Singleton;\n  }\n\n  public function name(): string {\n    return 'testing'\n  }\n}\n\n$factory = new ServiceFactory(new FactoryContainer());\n$factory-\u003eregisterFactory(new StringFactory());\n$factory-\u003ecreate('testing');\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fytake%2Fhh-container","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fytake%2Fhh-container","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fytake%2Fhh-container/lists"}