项目作者: oseille

项目描述 :
A concrete implementation of league/container to use with oseille/container-builder-bridge abstraction.
高级语言: PHP
项目地址: git://github.com/oseille/container-builder-bridge-league.git
创建时间: 2020-04-27T20:35:26Z
项目社区:https://github.com/oseille/container-builder-bridge-league

开源协议:MIT License

下载


The autogenerated table of contents is here

Container Builder Bridge League

A concrete implementation of the Container Builder Bridge using league/container

Lint Code Base
Tests

Requirements

This package requires:

  • PHP: ^8.0
  • ojullien/container-builder-bridge: ^1.1
  • league/container: ^4.2

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-league. 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\League namespace to the package src/ directory.

Documentation

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

Using the default ContainerBuilderBridge\Builder:

  1. // As League\Container does not have a builder.
  2. // We instanciate and configure the PSR-11 container
  3. $builder = new \League\Container\Container();
  4. // Instanciates the implementation to use thru the bridge builder
  5. $implementation = new \OJullien\ContainerBuilderBridge\League\Implementation($builder);
  6. // Instanciates the bridge
  7. $bridge = new \OJullien\ContainerBuilderBridge\Builder($implementation);
  8. // Create definitions using sequences
  9. $sequence = Sequence::getSequence();
  10. $sequence = $sequence->withDefinition('database.host', 'localhost')
  11. ->withDefinition('database.port', 5000)
  12. ->withDefinition('report.recipients', ['bob@example.com','alice@example.com',])
  13. ->withDefinition('factory',static function (ContainerInterface $container){...});
  14. // Builds the PSR-11 container
  15. $container = $bridge->getContainer($sequence);

Using the extended ContainerBuilderBridge\League\Builder:

  1. // As League\Container does not have a builder.
  2. // We instanciate and configure the PSR-11 container
  3. $builder = new \League\Container\Container();
  4. // Instanciates the implementation to use thru the bridge builder
  5. $implementation = new \OJullien\ContainerBuilderBridge\League\Implementation($builder);
  6. // Instanciates the bridge
  7. $bridge = new \OJullien\ContainerBuilderBridge\League\Builder($implementation);
  8. // Create shared definitions using sequences
  9. $sequence = Sequence::getSequence();
  10. $sequence = $sequence->withDefinition(SomeServiceProvider::class);
  11. // Builds the PSR-11 container
  12. $container = $bridge->addSharedDefinitions($sequence);
  13. // Builds the PSR-11 container with service provider
  14. $container = $bridge->addServiceProviders(new SomeServiceProvider());

Test

To run the unit tests at the command line, issue composer install and then ./vendor/bin/phpunit 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 League is open-source and is licensed under the MIT license.