{"id":22656870,"url":"https://github.com/libreworks/caridea-container","last_synced_at":"2025-07-16T01:46:47.064Z","repository":{"id":33173032,"uuid":"36814156","full_name":"libreworks/caridea-container","owner":"libreworks","description":":fried_shrimp: Caridea is a miniscule PHP application library. This is a shrimpy dependency injection container.","archived":false,"fork":false,"pushed_at":"2018-01-06T20:51:06.000Z","size":59,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-04T12:47:11.143Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/libreworks.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":"2015-06-03T15:51:57.000Z","updated_at":"2016-11-17T19:51:41.000Z","dependencies_parsed_at":"2022-09-12T04:41:19.827Z","dependency_job_id":null,"html_url":"https://github.com/libreworks/caridea-container","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libreworks%2Fcaridea-container","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libreworks%2Fcaridea-container/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libreworks%2Fcaridea-container/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libreworks%2Fcaridea-container/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/libreworks","download_url":"https://codeload.github.com/libreworks/caridea-container/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246156419,"owners_count":20732397,"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-12-09T10:16:45.600Z","updated_at":"2025-03-29T08:11:19.572Z","avatar_url":"https://github.com/libreworks.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# caridea-container\nCaridea is a miniscule PHP application library. This shrimpy fellow is what you'd use when you just want some helping hands and not a full-blown framework.\n\n![](http://libreworks.com/caridea-100.png)\n\nThis is its [PSR-11](http://www.php-fig.org/psr/psr-11/) compliant dependency injection container.\n\n[![Packagist](https://img.shields.io/packagist/v/caridea/container.svg)](https://packagist.org/packages/caridea/container)\n[![Build Status](https://travis-ci.org/libreworks/caridea-container.svg)](https://travis-ci.org/libreworks/caridea-container)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/libreworks/caridea-container/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/libreworks/caridea-container/?branch=master)\n[![Code Coverage](https://scrutinizer-ci.com/g/libreworks/caridea-container/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/libreworks/caridea-container/?branch=master)\n\n## Installation\n\nYou can install this library using Composer:\n\n```console\n$ composer require caridea/container\n```\n\n* The master branch (version 3.x) of this project requires PHP 7.1 and depends on `caridea/event`.\n* Version 2.x of this project requires PHP 7.0 and depends on `caridea/event`.\n* Version 1.x of this project requires PHP 5.5 and depends on `caridea/event`.\n\n## Compliance\n\nReleases of this library will conform to [Semantic Versioning](http://semver.org).\n\nOur code is intended to comply with [PSR-1](http://www.php-fig.org/psr/psr-1/), [PSR-2](http://www.php-fig.org/psr/psr-2/), and [PSR-4](http://www.php-fig.org/psr/psr-4/). If you find any issues related to standards compliance, please send a pull request!\n\n## Overview\n\n* The `Caridea\\Container\\Properties` class is intended for scalar configuration values that might be used as settings for other components.\n* The `Caridea\\Container\\Objects` class allows for eager, lazy, and prototype objects.\n   * It also implements `Caridea\\Event\\Publisher` and will broadcast events to any managed object which implements `Caridea\\Event\\Listener`.\n* The `Caridea\\Container\\EmptyContainer` class is an empty, no-op container.\n\nYou can retrieve contained objects both by name and by type!\n\n## Documentation\n\n* Head over to [Read the Docs](http://caridea-container.readthedocs.io/en/latest/)\n\n## Examples\n\nJust a few quick examples.\n\n### Configuration and Dependencies\n```php\n$config = [\n    'db.uri' =\u003e 'mongodb://localhost:27017',\n    'mail.host' =\u003e '192.168.1.100'\n];\n$properties = new \\Caridea\\Container\\Properties($config);\n$objects = \\Caridea\\Container\\Objects::builder()\n    -\u003eeager('mongoClient', 'MongoClient', function($c){\n        return new \\MongoClient($c-\u003eget('db.uri'));\n    })\n    -\u003elazy('mailService', 'My\\Mail\\Service', function($c){\n        return new \\My\\Mail\\Service($c-\u003e('mail.host'));\n    })\n    -\u003elazy('userService', 'My\\User\\Service', function($c){\n        return new \\My\\User\\Service($c-\u003eget('mongoClient'), $c-\u003eget('objectStorage'));\n    })\n    -\u003eproto('objectStorage', 'SplObjectStorage', function($c){\n        return new \\SplObjectStorage();\n    })\n    -\u003ebuild($properties);\n\n$userService = $objects-\u003eget('userService');\n```\n\n### Parent Delegation\n\nYou can nest Objects containers. For example, you can have a container with service objects and a child container with web controllers.\n\n```php\n$services = \\Caridea\\Container\\Objects::builder()\n    -\u003eeager('blogService', 'My\\Blog\\Service', function($c){\n        return new \\My\\Blog\\Service();\n    })\n    -\u003ebuild();\n$controllers = \\Caridea\\Container\\Objects::builder()\n    -\u003eeager('blogController', 'My\\Blog\\Controller', function($c){\n        return new \\My\\Blog\\Controller($c-\u003eget('blogService'));\n    })\n    -\u003ebuild($services);\n\n$controllers = $controllers-\u003egetByType('My\\Blog\\Controller'); // ['blogController' =\u003e BlogController]\n```\n\n### Events\n\n```php\n$objects = \\Caridea\\Container\\Objects::builder()\n    -\u003eeager('eventListener', 'My\\Cool\\EventListener', function($c){\n        // we are assuming that this class implements Caridea\\Event\\Listener\n        return new \\My\\Cool\\EventListener();\n    })\n    -\u003ebuild();\n\n// assuming that CustomEvent implements Caridea\\Event\\Event\n$objects-\u003epublish(new CustomEvent());\n// Here, the eventListener object will have its -\u003enotify() method invoked with the CustomEvent\n```\n\nAny objects returned from an `Objects` container that implement `\\Caridea\\Event\\PublisherAware` will receive the container via the `setPublisher` method.\n\n### ContainerAware\n\nAny objects returned from an `Objects` container that implement `\\Caridea\\Container\\ContainerAware` will receive the container via the `setContainer` method.\nWe provide a trait to make this easier.\n\n```php\nclass MyContainerAware implements \\Caridea\\Container\\ContainerAware\n{\n    use \\Caridea\\Container\\ContainerSetter;\n\n    public function __construct()\n    {\n        $this-\u003econtainer = new \\Caridea\\Container\\EmptyContainer();\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibreworks%2Fcaridea-container","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flibreworks%2Fcaridea-container","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibreworks%2Fcaridea-container/lists"}