php-di-definitions/definitions-gatherer

Collect definition files from composer.json's

Fund package maintenance!
WyriHaximus

Installs: 26 961

Dependents: 3

Suggesters: 0

Security: 0

Stars: 1

Watchers: 2

Forks: 1

Open Issues: 0

Language:Makefile

1.3.1 2023-01-13 22:20 UTC

This package is auto-updated.

Last update: 2024-12-14 02:20:22 UTC


README

Build Status Latest Stable Version Total Downloads Code Coverage License PHP 7 ready

Install

To install via Composer, use the command below, it will automatically detect the latest version and bind it with ^.

composer require php-di-definitions/definitions-gatherer

Gather definitions from files listed in composer.json.

Usage

Lets say for a project we need react/event-loop so we create a package that holds a definition file (etc/di/event-loop.php) with the following contents:

<?php

use React\EventLoop\Factory;
use React\EventLoop\LoopInterface;

return [
    LoopInterface::class => function () {
        return Factory::create();
    },
];

And reference to it with the following configuration in composer.json:

{
    "extra": {
        "php-di-definitions": {
            "di": [
                "etc/di/event-loop.php"
            ]
        }
    }
}

Then using this package you can get that definition (and others) and pass it PHP-DI (or another DI that supports the same format):

use DI\ContainerBuilder;
use PHPDIDefinitions\DefinitionsGatherer;

$definitions = iterator_to_array(DefinitionsGatherer::gather());
$containerBuilder = new ContainerBuilder();
$containerBuilder->addDefinitions($definitions);
$container = $containerBuilder->build();

License

The MIT License (MIT)

Copyright (c) 2023 Cees-Jan Kiewiet

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.