{"id":37004367,"url":"https://github.com/polylang/polylang-di","last_synced_at":"2026-01-14T00:38:03.136Z","repository":{"id":57082424,"uuid":"474092138","full_name":"polylang/polylang-di","owner":"polylang","description":"Dependency Injection Container by WP Syntex (Polylang).","archived":false,"fork":false,"pushed_at":"2022-04-11T09:48:27.000Z","size":43,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-10-21T11:48:26.319Z","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":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/polylang.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":"2022-03-25T16:49:38.000Z","updated_at":"2022-03-25T16:55:50.000Z","dependencies_parsed_at":"2022-08-24T14:42:49.931Z","dependency_job_id":null,"html_url":"https://github.com/polylang/polylang-di","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/polylang/polylang-di","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polylang%2Fpolylang-di","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polylang%2Fpolylang-di/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polylang%2Fpolylang-di/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polylang%2Fpolylang-di/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/polylang","download_url":"https://codeload.github.com/polylang/polylang-di/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polylang%2Fpolylang-di/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28406520,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T21:51:37.118Z","status":"ssl_error","status_checked_at":"2026-01-13T21:45:14.585Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":"2026-01-14T00:38:02.062Z","updated_at":"2026-01-14T00:38:03.120Z","avatar_url":"https://github.com/polylang.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Polylang DI\n\n![php](https://badgen.net/packagist/php/wpsyntex/polylang-di)\n[![Latest Version](https://badgen.net/packagist/v/wpsyntex/polylang-di/latest)](https://packagist.org/packages/wpsyntex/polylang-di)\n[![Software License](https://badgen.net/github/license/polylang/polylang-di)](LICENSE.md)\n\nDependency Injection Container by WP Syntex (Polylang).\n\nThis package is compliant with [PSR-4](https://www.php-fig.org/psr/psr-4/) and [PSR-11](https://www.php-fig.org/psr/psr-11/).  \nHowever, PSR-11's interfaces are not implemented, to prevent conflicts with other plugins and themes that may use a different version of them.\n\nThis project is pretty much a fork of an old version of [league/container](https://github.com/thephpleague/container), that has been reworked a bit to keep only the features that we need in our projects.\n\n## Install\n\nVia Composer\n\n``` bash\ncomposer require wpsyntex/polylang-di\n```\n\n## Requirements\n\nThis package supports php 5.6+.\n\n## Documentation\n\n### Create and retrieve shared and not shared instances\n\n```php\n\u003c?php\nnamespace Foobar;\n\nclass Foo {}\n\n$container = new \\WP_Syntex\\Polylang_DI\\Container();\n\n// Add to the container.\n$container-\u003eadd( 'foo', 'Foobar\\Foo' );\n\n// Instanciate and retrieve.\n$foo1 = $container-\u003eget( 'foo' );\n$foo2 = $container-\u003eget( 'foo' );\n\n// We created 2 different instances.\nvar_dump( $foo1 === $foo2 ); // False.\n\n// Add to the container as a shared item.\n$container-\u003eaddShared( 'foo', 'Foobar\\Foo' );\n\n// Instanciate and retrieve.\n$foo1 = $container-\u003eget( 'foo' );\n$foo2 = $container-\u003eget( 'foo' );\n\n// We created only one instance.\nvar_dump( $foo1 === $foo2 ); // True.\n```\n\n### Add arguments\n\n```php\n\u003c?php\nnamespace Foobar;\n\nclass Foo {\n    public $int;\n    public $string;\n\n    public function __construct( $int, $string = null ) {\n        $this-\u003eint    = $int;\n        $this-\u003estring = $string;\n    }\n}\n\n$container = new \\WP_Syntex\\Polylang_DI\\Container();\n\n// Add to the container.\n$container-\u003eadd( 'foo', Foo::class )\n    -\u003ewithArgument( 46 );\n\n// Instanciate and retrieve.\n$foo1 = $container-\u003eget( 'foo' );\n$foo2 = $container-\u003eget( 'foo' );\n\n// We created 2 different instances with the same arguments.\nvar_dump( $foo1 === $foo2 ); // False.\nvar_dump( $foo1-\u003eint ); // 46.\nvar_dump( $foo1-\u003estring ); // Null.\nvar_dump( $foo1-\u003eint === $foo2-\u003eint ); // True.\nvar_dump( $foo1-\u003estring === $foo2-\u003estring ); // True.\n\n// Retrieve the definition and add an argument.\n$container-\u003eextend( 'foo' )\n    -\u003ewithArgument( 'a string' ); // Not not shared items only.\n\n// Instanciate and retrieve.\n$foo3 = $container-\u003eget( 'foo' );\n\nvar_dump( $foo3-\u003eint ); // 46.\nvar_dump( $foo3-\u003estring ); // 'a string'.\n\n// Retrieve the definition and replace previous arguments.\n$container-\u003eextend( 'foo' )\n    -\u003ewithNewArguments(\n        [\n            22,\n            'some string',\n        ]\n    );\n\n$foo4 = $container-\u003eget( 'foo' );\n\nvar_dump( $foo4-\u003eint ); // 22.\nvar_dump( $foo4-\u003estring ); // 'some string'.\n\n// With an anonymous function.\n$container-\u003eadd( 'prefix', 'String prefix' );\n$container-\u003eadd(\n    'foo',\n    function ( $container, $int, $string ) {\n        $prefix = $container-\u003eget( 'prefix' );\n        return new Foo( $int, $prefix . ' - ' . $string );\n    }\n)\n    -\u003ewithArguments(\n        [\n            32,\n            'another string',\n        ]\n    );\n\n$foo5 = $container-\u003eget( 'foo' );\n\nvar_dump( $foo5-\u003eint ); // 32.\nvar_dump( $foo5-\u003estring ); // 'String prefix - another string'.\n```\n\n### Reference other items (or not)\n\n```php\n\u003c?php\nnamespace Foobar;\n\nclass Foo {}\n\nclass Bar {\n    public $foo;\n    public $string;\n\n    public function __construct( Foo $foo, $string = null ) {\n        $this-\u003efoo    = $foo;\n        $this-\u003estring = $string;\n    }\n}\n\n$container = new \\WP_Syntex\\Polylang_DI\\Container();\n\n// Add to the container.\n$container-\u003eaddShared( 'foo', Foo::class );\n$container-\u003eadd( 'bar', Bar::class )\n    -\u003ewithArgument( 'foo' ) // Same identifier used for Foobar\\Foo.\n    -\u003ewithArgument(\n        new \\WP_Syntex\\Polylang_DI\\Argument\\RawArgument( 'foo' ) // Same identifier used for Foobar\\Foo, but we just want to pass a string here.\n    );\n\n// Instanciate and retrieve.\n$bar1 = $container-\u003eget( 'bar' );\n$bar2 = $container-\u003eget( 'bar' );\n\n// We created 2 different instances with the same arguments.\nvar_dump( $bar1 === $bar2 ); // False.\nvar_dump( $bar1-\u003efoo instanceof Foo ); // True.\nvar_dump( $bar1-\u003efoo === $bar2-\u003efoo ); // True.\nvar_dump( $bar1-\u003estring ); // 'foo'.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolylang%2Fpolylang-di","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpolylang%2Fpolylang-di","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolylang%2Fpolylang-di/lists"}