{"id":18929505,"url":"https://github.com/thecodingmachine/picotainer","last_synced_at":"2025-04-15T15:31:04.178Z","repository":{"id":26145041,"uuid":"29590142","full_name":"thecodingmachine/picotainer","owner":"thecodingmachine","description":"A minimalist PHP dependency injection container compatible with ContainerInterop","archived":false,"fork":false,"pushed_at":"2017-03-09T09:21:11.000Z","size":12,"stargazers_count":16,"open_issues_count":1,"forks_count":6,"subscribers_count":20,"default_branch":"1.1","last_synced_at":"2025-04-11T18:59:50.219Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thecodingmachine.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-21T13:14:31.000Z","updated_at":"2023-10-31T13:53:53.000Z","dependencies_parsed_at":"2022-08-01T05:48:37.877Z","dependency_job_id":null,"html_url":"https://github.com/thecodingmachine/picotainer","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Fpicotainer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Fpicotainer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Fpicotainer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Fpicotainer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thecodingmachine","download_url":"https://codeload.github.com/thecodingmachine/picotainer/tar.gz/refs/heads/1.1","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249097861,"owners_count":21212363,"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-08T11:33:07.070Z","updated_at":"2025-04-15T15:31:03.899Z","avatar_url":"https://github.com/thecodingmachine.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Picotainer\n==========\n[![Latest Stable Version](https://poser.pugx.org/mouf/picotainer/v/stable.svg)](https://packagist.org/packages/mouf/picotainer)\n[![Latest Unstable Version](https://poser.pugx.org/mouf/picotainer/v/unstable.svg)](https://packagist.org/packages/mouf/picotainer)\n[![License](https://poser.pugx.org/mouf/picotainer/license.svg)](https://packagist.org/packages/mouf/picotainer)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/thecodingmachine/picotainer/badges/quality-score.png?b=1.0)](https://scrutinizer-ci.com/g/thecodingmachine/picotainer/?branch=1.0)\n[![SensioLabsInsight](https://insight.sensiolabs.com/projects/3ac43eac-dcec-496a-9e0f-5fe82f8b3824/mini.png)](https://insight.sensiolabs.com/projects/3ac43eac-dcec-496a-9e0f-5fe82f8b3824)\n[![Build Status](https://travis-ci.org/thecodingmachine/picotainer.svg?branch=1.0)](https://travis-ci.org/thecodingmachine/picotainer)\n[![Coverage Status](https://coveralls.io/repos/thecodingmachine/picotainer/badge.svg?branch=1.0)](https://coveralls.io/r/thecodingmachine/picotainer?branch=1.0)\n\nThis package contains a really minimalist dependency injection container (24 lines of code!) compatible with\n[container-interop](https://github.com/container-interop/container-interop) (supports ContainerInterface and\ndelegate lookup feature).  It is also, therefore, compatible with\n[PSR-11](https://github.com/php-fig/fig-standards/blob/master/proposed/container.md), the FIG container standard.\n\nPicotainer is heavily influenced by the [Pimple DI container](http://pimple.sensiolabs.org/). Think about it\nas a Pimple container with even less features, and ContainerInterop compatibility.\n\nInstallation\n------------\n\nBefore using Picotainer in your project, add it to your `composer.json` file:\n\n```\n$ ./composer.phar require mouf/picotainer ~1.0\n```\n\n\nStoring entries in the container\n--------------------------------\n\nCreating a container is a matter of creating a `Picotainer` instance.\nThe `Picotainer` class takes 2 parameters:\n\n- the list of entries, as an **array of anonymous functions**\n- an optional [delegate-lookup container](https://github.com/container-interop/container-interop/blob/master/docs/Delegate-lookup.md)\n\n```php\nuse Mouf\\Picotainer\\Picotainer;\nuse Psr\\Container\\ContainerInterface;\n\n$container = new Picotainer([\n\t\"myInstance\"=\u003efunction(ContainerInterface $container) {\n\t\treturn new MyInstance();\n\t},\n\t\"myOtherInstance\"=\u003efunction(ContainerInterface $container) {\n\t\treturn new MyOtherInstance($container-\u003eget('myInstance'));\n\t}\n\t\"myParameter\"=\u003efunction(ContainerInterface $container) {\n\t\treturn MY_CONSTANT;\n\t}\n], $rootContainer);\n```\n\nThe list of entries is an associative array.\n\n- The key is the name of the entry in the container\n- The value is an **anonymous function** that will return the entry\n\nThe entry can be anything (an object, a scalar value, a resource, etc...)\n\nThe **anonymous function** must accept one parameter: the container on which dependencies will be fetched.\nThe container is the \"delegate-lookup container\" if it was passed as the second argument of the constructor,\nor the Picotainer instance itself if no delegate lookup container was passed.\n\n\nFetching entries from the container\n-----------------------------------\n\nFetching entries from the container is as simple as calling the `get` method:\n\n```php\n$myInstance = $container-\u003eget('myInstance');\n```\n\nWhy the need for this package?\n------------------------------\n\nThis package is part of a long-term effort to bring [interoperability between DI containers](https://github.com/container-interop/container-interop). The ultimate goal is to\nmake sure that multiple containers can communicate together by sharing entries (one container might use an entry from another\ncontainer, etc...)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthecodingmachine%2Fpicotainer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthecodingmachine%2Fpicotainer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthecodingmachine%2Fpicotainer/lists"}