{"id":20089922,"url":"https://github.com/bugadani/factory","last_synced_at":"2026-05-13T19:33:19.556Z","repository":{"id":62498076,"uuid":"45686523","full_name":"bugadani/Factory","owner":"bugadani","description":"A simple PHP DIC","archived":false,"fork":false,"pushed_at":"2016-05-05T07:39:39.000Z","size":16,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-13T02:43:18.099Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/bugadani.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-11-06T14:26:55.000Z","updated_at":"2016-02-03T12:17:09.000Z","dependencies_parsed_at":"2022-11-02T11:46:38.322Z","dependency_job_id":null,"html_url":"https://github.com/bugadani/Factory","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bugadani%2FFactory","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bugadani%2FFactory/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bugadani%2FFactory/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bugadani%2FFactory/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bugadani","download_url":"https://codeload.github.com/bugadani/Factory/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241525421,"owners_count":19976708,"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":[],"created_at":"2024-11-13T16:20:45.501Z","updated_at":"2026-05-13T19:33:19.523Z","avatar_url":"https://github.com/bugadani.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/bugadani/Factory.svg?branch=master)](https://travis-ci.org/bugadani/Factory)\n\nFactory\n========\n\nFactory is a simple PHP dependency injection container for PHP 7 and newer.\n\nUsage\n--------\n\nTo instantiate an object, simply pass its name to Factory::get(). The instantiated objects are stored and can be retrieved later.\n\n    $instance = $factory-\u003eget(FooClass::class);\n\nClass dependencies are resolved automatically.\n\n    class FooClass {\n        public function __construct(BarClass $b){\n            //$b will be injected\n        }\n    }\n    $instance = $factory-\u003eget(FooClass::class);\n\nOther constructor parameters may be defined by passing an array to either Factory::setParameters(), or as the second argument of Factory::get().\nThese parameters may be both positional or named. Named parameters have precedence over positional ones and parameters passed to Factory::get() will\noverride the ones set via Factory::setParameters().\n\n    class FooClass {\n        public function __construct($a, $b){\n            //$a == 'foobar'\n            //$b == 'baz'\n        }\n    }\n    $factory-\u003esetParameters(FooClass::class, ['b' =\u003e 'baz', 0 =\u003e 'foobar']);\n    $instance = $factory-\u003eget(FooClass::class);\n\nIndividual parameters can also be set using `$factory-\u003esetParameter(FooClass::class, $parameterNameOrPosition, $parameterValue)`\n\nClass names may also be aliased, which may be useful to inject interface implementations or extended classes.\nAliased classes use the actual class' parameters.\n\n    class FooClass {\n        public function __construct(SomeInterface $a){\n            //$a instanceof SomeInterfaceImpl\n        }\n    }\n    $factory-\u003eaddAlias(SomeInterfaceImpl::class, SomeInterface::class);\n    $instance = $factory-\u003eget(FooClass::class);\n\nIt is possible to set callback functions to be called when an object is instantiated to do some additional initialization.\nThe Factory instance and the object is passed to the callback. This callback will only be called if a new object is created.\n\n    $factory-\u003eaddCallback(SomeClass::class, function(Factory $factory, SomeClass $instance){});\n    $instance = $factory-\u003eget(SomeClass::class);","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbugadani%2Ffactory","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbugadani%2Ffactory","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbugadani%2Ffactory/lists"}