{"id":18929529,"url":"https://github.com/thecodingmachine/alias-container","last_synced_at":"2025-04-15T15:31:06.766Z","repository":{"id":26371359,"uuid":"29820602","full_name":"thecodingmachine/alias-container","owner":"thecodingmachine","description":"This package contains a really minimalist dependency injection container that can be used to create aliases of instances in existing containers.","archived":false,"fork":false,"pushed_at":"2020-04-15T21:17:11.000Z","size":24,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":18,"default_branch":"1.0","last_synced_at":"2025-04-11T18:59:46.508Z","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-25T16:22:25.000Z","updated_at":"2020-04-07T16:58:45.000Z","dependencies_parsed_at":"2022-08-22T20:20:29.013Z","dependency_job_id":null,"html_url":"https://github.com/thecodingmachine/alias-container","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Falias-container","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Falias-container/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Falias-container/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Falias-container/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thecodingmachine","download_url":"https://codeload.github.com/thecodingmachine/alias-container/tar.gz/refs/heads/1.0","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249097872,"owners_count":21212365,"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:25.141Z","updated_at":"2025-04-15T15:31:06.504Z","avatar_url":"https://github.com/thecodingmachine.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Alias-Container\n===============\n[![Latest Stable Version](https://poser.pugx.org/mouf/alias-container/v/stable.svg)](https://packagist.org/packages/mouf/alias-container)\n[![Latest Unstable Version](https://poser.pugx.org/mouf/alias-container/v/unstable.svg)](https://packagist.org/packages/mouf/alias-container)\n[![License](https://poser.pugx.org/mouf/alias-container/license.svg)](https://packagist.org/packages/mouf/alias-container)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/thecodingmachine/alias-container/badges/quality-score.png?b=1.0)](https://scrutinizer-ci.com/g/thecodingmachine/alias-container/?branch=1.0) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/04f9f269-db42-4a3b-9cf9-1fd41aac2e8a/mini.png)](https://insight.sensiolabs.com/projects/04f9f269-db42-4a3b-9cf9-1fd41aac2e8a)\n[![Build Status](https://travis-ci.org/thecodingmachine/alias-container.svg?branch=1.0)](https://travis-ci.org/thecodingmachine/alias-container)\n[![Coverage Status](https://coveralls.io/repos/thecodingmachine/alias-container/badge.svg?branch=1.0)](https://coveralls.io/r/thecodingmachine/alias-container?branch=1.0)\n\nThis package contains a really minimalist dependency injection container that can be used to **create aliases** of instances\nin existing containers. Alias-container is compatible with [container-interop](https://github.com/container-interop/container-interop)\nand is meant to be used in conjunction with other containers. By itself, Alias-container does not store any entry. It can only be used\nto **create aliases of instances stored in other containers**.\n\nYou can use AliasContainer to add support for alias for any container that does not support this feature.\n\nInstallation\n------------\n\nBefore using AliasContainer in your project, add it to your `composer.json` file:\n\n```\n$ ./composer.phar require mouf/alias-container ~1.0\n```\n\n\nDefining aliases in the container\n---------------------------------\n\nCreating an alias container is a matter of creating an `AliasContainer` instance.\nThe `AliasContainer` class takes 2 parameters:\n\n- a [delegate-lookup container](https://github.com/container-interop/container-interop/blob/master/docs/Delegate-lookup.md) (e.g. the container we will look aliases into)\n- the list of aliases, as an **associative array of strings**\n\n```php\nuse Mouf\\AliasContainer;\nuse Interop\\Container\\ContainerInterface;\n\n$aliasContainer = new AliasContainer($rootContainer, [\n\t\"myAlias\"=\u003e\"myInstance\",\n\t\"myAlias2\"=\u003e\"myInstance2\"\n]);\n```\n\nThe list of entries is an associative array.\n\n- The key is the identifier of the alias to create\n- The value is the identifier of the entry that will be aliased\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 = $aliasContainer-\u003eget('myAlias');\n```\n\nAdding aliases to the container\n-------------------------------\n\nYou can add new aliases using the `set` method.\n\n```php\n$aliasContainer-\u003eset('newAlias', 'myInstance');\n```\n\n\u003cdiv class=\"alert alert-info\"\u003eNote that it is more efficient to initialize aliases in the container\nthan calling recursively the \u003ccode\u003eset\u003c/code\u003e method.\u003c/div\u003e\n\nRemoving aliases from the container\n-----------------------------------\n\nYou can add new aliases using the `remove` method.\n\n```php\n$aliasContainer-\u003eremove('myAlias');\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%2Falias-container","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthecodingmachine%2Falias-container","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthecodingmachine%2Falias-container/lists"}