Skip to content

ojullien/container-builder-bridge-php-di

Repository files navigation

The autogenerated table of contents is here

Container Builder Bridge PHP-DI

A concrete implementation of the Container Builder Bridge using php-di/php-di

Lint Code Base Tests

Requirements

This package requires:

  • PHP: ^8.0
  • ojullien/container-builder-bridge: ^1.1
  • php-di/php-di: ^6.3

For specifics, please examine the manifest composer.json file.

You may check if your PHP and extension versions match the platform requirements using composer diagnose and composer check-platform-reqs. (This requires Composer to be available as composer.)

Installation

This package is installable and PSR-4 autoloadable via Composer as ojullien/container-builder-bridge-php-di. For no dev, use composer install --no-dev and for dev, use composer install.

Alternatively, download a release, or clone this repository, then map the OJullien\ContainerBuilderBridge\PHPDI namespace to the package src/ directory.

Documentation

We do not provide exhaustive documentation. Please read the code and the comments ;)

// Instanciates the container builder
$builder = new \DI\ContainerBuilder();

// Configures the container builder if needed
$builder->enableCompilation(__DIR__ . '/tmp');
$builder->writeProxiesToFile(true, __DIR__ . '/tmp/proxies');
$builder->useAutowiring(true);
$builder->useAnnotations(false);

// Instanciates the implementation to use thru the bridge builder
$implementation = new \OJullien\ContainerBuilderBridge\PHPDI\Implementation($builder);

// Instanciates the bridge
$bridge = new \OJullien\ContainerBuilderBridge\Builder($implementation);

// Create definitions using sequences
$sequence = Sequence::getSequence();
$sequence = $sequence->withDefinition('database.host', 'localhost')
                     ->withDefinition('database.port', 5000)
                     ->withDefinition('report.recipients', ['bob@example.com','alice@example.com',])
                     ->withDefinition('factory',static function (ContainerInterface $container){...});

// Builds the PSR-11 container
$container = $bridge->getContainer($sequence);

Test

To run the unit tests at the command line, issue composer install and then composer run test at the package root. (This requires Composer to be available as composer.)

Contributing

Thanks you for taking the time to contribute. Please fork the repository and make changes as you'd like.

If you have any ideas, just open an issue and tell me what you think. Pull requests are also warmly welcome.

If you encounter any bugs, please open an issue.

Be sure to include a title and clear description,as much relevant information as possible, and a code sample or an executable test case demonstrating the expected behavior that is not occurring.

License

Container Builder Bridge PHP-DI is open-source and is licensed under the MIT license.

About

A concrete implementation of php-di/php-di to use with ojullien/container-builder-bridge abstraction.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Languages