{"id":21194434,"url":"https://github.com/cspray/annotated-container","last_synced_at":"2025-04-09T23:16:13.141Z","repository":{"id":38186287,"uuid":"354553154","full_name":"cspray/annotated-container","owner":"cspray","description":"Dependency Injection framework to configure a PSR-11 Container with Attributes!","archived":false,"fork":false,"pushed_at":"2025-03-29T22:48:33.000Z","size":1596,"stargazers_count":39,"open_issues_count":26,"forks_count":1,"subscribers_count":5,"default_branch":"release-2.x","last_synced_at":"2025-04-09T23:16:04.717Z","etag":null,"topics":["annotated-container","dependency-injection","php","php8","psr-11"],"latest_commit_sha":null,"homepage":"","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/cspray.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-04T13:39:32.000Z","updated_at":"2024-08-23T08:41:51.000Z","dependencies_parsed_at":"2024-06-18T18:57:47.798Z","dependency_job_id":"91007650-365d-401c-b316-d17ff317e3b7","html_url":"https://github.com/cspray/annotated-container","commit_stats":{"total_commits":145,"total_committers":2,"mean_commits":72.5,"dds":0.06206896551724139,"last_synced_commit":"232d0b05d9f2253979652b094e90edeb27c99f9d"},"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cspray%2Fannotated-container","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cspray%2Fannotated-container/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cspray%2Fannotated-container/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cspray%2Fannotated-container/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cspray","download_url":"https://codeload.github.com/cspray/annotated-container/tar.gz/refs/heads/release-2.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248125591,"owners_count":21051770,"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":["annotated-container","dependency-injection","php","php8","psr-11"],"created_at":"2024-11-20T19:22:10.728Z","updated_at":"2025-04-09T23:16:13.100Z","avatar_url":"https://github.com/cspray.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AnnotatedContainer\n\n[![Unit Tests](https://github.com/cspray/annotated-container/actions/workflows/php.yml/badge.svg)](https://github.com/cspray/annotated-container/actions/workflows/php.yml)\n\nA Dependency Injection framework for creating an autowired, feature-rich, [PSR-11](https://www.php-fig.org/psr/psr-11/) compatible Container using PHP 8 Attributes!\n\n- Designate an interface as a Service and easily configure which concrete implementations to use\n- Delegate service construction to a factory\n- Inject scalar values, environment variables, and other services into your constructors and setters\n- Automatically invoke methods after the service is constructed\n- Use Profiles to easily use different services in different runtimes\n- Create type-safe, highly flexible configuration objects\n- Easily include third-party services that cannot be easily annotated\n- Bring Your Own Container!\n\n## Quick Start\n\nThis quick start is intended to get you familiar with Annotated Container's core functionality and get a working Container created. First, a simple example showing how an interface can be aliased to a concrete Service. After that we'll show you how to get a Container to create the Service.\n\n### Code Example\n\n```php\n\u003c?php declare(strict_types=1);\n\n// interfaces and classes in __DIR__ . '/src'\n\nuse Cspray\\AnnotatedContainer\\Attribute\\Service;\nuse Cspray\\AnnotatedContainer\\Attribute\\InjectEnv;\n\n#[Service]\ninterface BlobStorage {\n\n    public function store(string $identifier, string $contents) : void;\n    \n    public function retrieve(string $identifier) : ?string;\n\n}\n\n#[Service]\nclass FilesystemStorage implements BlobStorage {\n    \n    public function store(string $identifier, string $contents) : void {\n        file_put_contents($identifier, $contents);\n    }\n    \n    public function retrieve(string $identifier) : ?string {\n        return file_get_contents($identifier) ?? null;\n    }\n\n}\n```\n\nThis example is built upon in the docs. Check out the tutorials for more examples of Annotated Container's functionality!\n\n### Bootstrapping Your Container\n\nAnnotated Container ships with a built-in CLI tool to easily create a configuration detailing how to build your Container and a corresponding `Cspray\\AnnotatedContainer\\Bootstrap\\Bootstrap` implementation to create your Container using that configuration. It is highly recommended to use the provided tooling to create your Container.\n\n\u003e The CLI tool offers extensive documentation detailing how to run commands and what options are available. If you're ever looking for more info run: `./vendor/bin/annotated-container help`\n\nThe first step is to create the configuration. By default, the tooling will look at your `composer.json` to determine what directories to scan and create a directory that the ContainerDefinition can be cached in. Run the following command to complete this step. \n\n```\n./vendor/bin/annotated-container init\n```\n\nThe configuration file will be created in the root of your project named \"annotated-container.xml\". The cache directory will also be created in the root of your project named \".annotated-container-cache\". Check out the command's help documentation for available options, including how to customize these values.\n\nBe sure to review the generated configuration! A \"normal\" Composer setup might result in a configuration that looks like the following. If there are any directories that should be scanned but aren't listed in `\u003csource\u003e\u003c/source\u003e` be sure to include them. Conversely, if there are directories included that _shouldn't_ be scanned be sure to remove them.\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\" ?\u003e\n\u003cannotatedContainer xmlns=\"https://annotated-container.cspray.io/schema/annotated-container.xsd\"\u003e\n  \u003cscanDirectories\u003e\n    \u003csource\u003e\n      \u003cdir\u003esrc\u003c/dir\u003e\n      \u003cdir\u003etests\u003c/dir\u003e\n    \u003c/source\u003e\n  \u003c/scanDirectories\u003e\n  \u003ccacheDir\u003e.annotated-container-cache\u003c/cacheDir\u003e\n\u003c/annotatedContainer\u003e\n```\n\nNow, bootstrap your Container in your app.\n\n```php\n\u003c?php declare(strict_types=1);\n\n// app bootstrap in __DIR__ . '/app.php'\nrequire __DIR__ . '/vendor/autoload.php';\n\nuse Cspray\\AnnotatedContainer\\Bootstrap\\Bootstrap;\n\n// Include other active profiles in this list\n// If the only active profile is default you can call this method without any arguments\n$profiles = ['default'];\n$container = (new Bootstrap())-\u003ebootstrapContainer($profiles);\n\n$storage = $container-\u003eget(BlobStorage::class);     // instanceof FilesystemStorage\n```\n\n## Installation\n\n```\ncomposer require cspray/annotated-container\n```\n\n### Choose a Backing Container\n\nAnnotatedContainer does not provide any of the actual Container functionality. We provide Attributes and definition objects that can determine how actual implementations are intended to be setup. AnnotatedContainer currently supports the following backing Containers:\n\n#### [rdlowrey/auryn](https://github.com/rdlowrey/auryn)\n\n```\ncomposer require rdlowrey/auryn\n```\n\n#### [php-di/php-di](https://github.com/php-di/php-di)\n\n```\ncomposer require php-di/php-di\n```\n\n#### [illuminate/container](https://github.com/illuminate/container)\n\n```\ncomposer require illuminate/container\n```\n\n## Documentation\n\nThis library is thoroughly documented in-repo under the `/docs` directory. The documentation is split into three parts; Tutorials, How Tos, and References.\n\n**Tutorials** are where you'll want to start. It'll expand on the examples in the \"Quick Start\" and teach you how to do most of the things you'll want to do with the library. This documentation tends to split the difference between the amount of code and the amount of explanation.\n\n**How Tos** are where you'll go to get step-by-step guides on how to achieve specific functionality. These documents tend to be more code and less explanation. We assume you've gotten an understanding of the library and have questions on how to do something beyond the \"normal\" use cases. \n\n**References** are where you can get into the real internal, technical workings of the library. List of APIs and more technically-explicit documentation can be found here. References may be a lot of code, a lot of explanation, or a split between the two depending on the context.\n\n## Roadmap\n\nThe Roadmap can be found in the [annotated-container Project page](https://github.com/users/cspray/projects/1/views/1).\n\n## External Resources\n\n### Notable Libraries Using Annotated Container\n\n- [Annotated Console](https://github.com/cspray/annotated-console)\n- [Labrador Async Event](https://github.com/labrador-kennel/async-event) (3.0.0-beta2+)\n\n### Blog Posts\n\n- [Introducing Annotated Container - Part 1](https://www.cspray.io/blog/introducing-annotated-container-part-1/)\n- [Introducing Annotated Container - Part 2](https://www.cspray.io/blog/introducing-annotated-container-part-2/)\n- [Introducing Annotated Container - Part 3](https://www.cspray.io/blog/introducing-annotated-container-part-3/)\n- [Annotated Container, Why Attributes?](https://www.cspray.io/blog/annotated-container-why-attributes/)\n- [Autowiring Annotated Container](https://www.cspray.io/blog/autowiring-and-annotated-container/)\n\n### Demos\n\n- [cspray/annotated-container-microframework](https://github.com/cspray/annotated-container-microframework)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcspray%2Fannotated-container","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcspray%2Fannotated-container","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcspray%2Fannotated-container/lists"}