{"id":19737198,"url":"https://github.com/patchlevel/event-sourcing-psr-container","last_synced_at":"2025-07-09T01:36:43.967Z","repository":{"id":65143019,"uuid":"582959666","full_name":"patchlevel/event-sourcing-psr-container","owner":"patchlevel","description":"patchlevel/event-sourcing factories for PSR-11 containers","archived":false,"fork":false,"pushed_at":"2024-12-30T16:59:24.000Z","size":94,"stargazers_count":0,"open_issues_count":11,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-10T19:23:32.575Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/patchlevel.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-28T10:55:44.000Z","updated_at":"2024-04-22T06:40:16.000Z","dependencies_parsed_at":"2024-03-23T23:26:05.263Z","dependency_job_id":"298e5010-1d2e-471c-9be6-8c84452be15e","html_url":"https://github.com/patchlevel/event-sourcing-psr-container","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patchlevel%2Fevent-sourcing-psr-container","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patchlevel%2Fevent-sourcing-psr-container/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patchlevel%2Fevent-sourcing-psr-container/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patchlevel%2Fevent-sourcing-psr-container/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/patchlevel","download_url":"https://codeload.github.com/patchlevel/event-sourcing-psr-container/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241062674,"owners_count":19902940,"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-12T01:09:58.137Z","updated_at":"2025-02-27T21:46:52.575Z","avatar_url":"https://github.com/patchlevel.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Latest Stable Version](https://poser.pugx.org/patchlevel/event-sourcing-psr-container/v)](//packagist.org/packages/patchlevel/event-sourcing-psr-container)\n[![License](https://poser.pugx.org/patchlevel/event-sourcing-psr-container/license)](//packagist.org/packages/patchlevel/event-sourcing-psr-container)\n\n# Event-Sourcing PSR-11 Container\n\n[patchlevel/event-sourcing](https://github.com/patchlevel/event-sourcing) factories for PSR-11 containers.\n\n## Installation\n\n```bash\ncomposer require patchlevel/event-sourcing-psr-container\n```\n\n## Documentation\n\n### Config Builder\n\nTo create a configuration array, you can use the ConfigBuilder. \nThis offers methods to adjust the configuration.\n\n```php\n$eventSourcingConfig = (new ConfigBuilder())\n    -\u003esingleTable()\n    -\u003edatabaseUrl('mysql://user:secret@localhost/app')\n    -\u003eaddAggregatePath(__DIR__ . '/Aggregate')\n    -\u003eaddEventPath(__DIR__ . '/Events')\n    -\u003eaddProcessor(SendEmailProcessor::class)\n    -\u003eaddProjector(ProfileProjection::class)\n    -\u003ebuild();\n```\n\n### Default Build-In Container\n\nThe own PSR container implementation already integrates all necessary factories. \nSo we only have to pass the configuration.\n\n```php\nuse Patchlevel\\EventSourcing\\Container\\ConfigBuilder;\nuse Patchlevel\\EventSourcing\\Container\\DefaultContainer;\n\n$container = new DefaultContainer(\n    $eventSourcingConfig,\n    [\n        HotelProjection::class =\u003e fn(DefaultContainer $container) \n            =\u003e new HotelProjection($container-\u003econnection()),\n        SendEmailProcessor::class =\u003e fn(DefaultContainer $container) \n            =\u003e new SendEmailProcessor($container-\u003eget('mailer')),\n    ]\n);\n\n$container-\u003eget(SchemaDirector::class)-\u003ecreate();\n\n$hotelRepository = $container-\u003erepository(Hotel::class);\n```\n\n### Laminas Service Manager\n\nFactories can also be used with other PSR-11 compatible libraries. \nHere is an example with [Laminas](https://docs.laminas.dev/laminas-servicemanager/).\n\n```bash\ncomposer require laminas/laminas-servicemanager\n```\n\nWe only have to specify the factories and pass the configuration.\n\n```php\nuse Laminas\\ServiceManager\\ServiceManager;\nuse Patchlevel\\EventSourcing\\Repository\\RepositoryManager;\nuse Patchlevel\\EventSourcing\\Schema\\SchemaDirector;\nuse Patchlevel\\EventSourcingPsrContainer\\ConfigBuilder;\nuse Patchlevel\\EventSourcingPsrContainer\\Factory\\ConnectionFactory;\nuse Patchlevel\\EventSourcingPsrContainer\\Factory\\RepositoryManagerFactory;\nuse Patchlevel\\EventSourcingPsrContainer\\Factory\\SchemaDirectorFactory;\n\n$serviceManager = new ServiceManager([\n    'services' =\u003e [\n        'config' =\u003e [\n            'event_sourcing' =\u003e $eventSourcingConfig\n        ],\n        SendEmailProcessor::class =\u003e new SendEmailProcessor()\n    ],\n    'factories' =\u003e [\n        'event_sourcing.connection' =\u003e new ConnectionFactory(),\n        RepositoryManager::class =\u003e new RepositoryManagerFactory(),\n        SchemaDirector::class =\u003e new SchemaDirectorFactory(),\n        HotelProjection::class =\u003e static fn (ServiceManager $container) =\u003e new HotelProjection($container-\u003eget('event_sourcing.connection')),\n    ],\n]);\n\n$serviceManager-\u003eget(SchemaDirector::class)-\u003ecreate();\n\n$repositoryManager = $serviceManager-\u003eget(RepositoryManager::class);\n$hotelRepository = $repositoryManager-\u003eget(Hotel::class);\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatchlevel%2Fevent-sourcing-psr-container","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpatchlevel%2Fevent-sourcing-psr-container","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatchlevel%2Fevent-sourcing-psr-container/lists"}