2017 © Pedro Peláez
 

library container

Service Container component for Palmtree PHP

image

palmtree/container

Service Container component for Palmtree PHP

  • Tuesday, July 10, 2018
  • by palmtree
  • Repository
  • 1 Watchers
  • 0 Stars
  • 41 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 18 Versions
  • 52 % Grown

The README.md

:palm_tree: Palmtree Container

License Build Status Scrutinizer Code Coverage, (*1)

A PSR-11 compatible service container, (*2)

Supports environment variable parameters, factories and private services., (*3)

Requirements

  • PHP >= 7.1

For PHP >= 5.6 support use v1.0, (*4)

Installation

Use composer to add the package to your dependencies:, (*5)

composer require palmtree/container

Usage

Define parameters and services:, (*6)

# config.yml
parameters:
  database_name: 'mydb'
  database_user: 'mydb_user'
  database_password: '%env(DB_PASSWORD)%'
  env(DB_PASSWORD): 123456 # Default env parameter used if environment variable is not set

imports:
  - { resource: services.yml }
  - { resource: secrets.yml }
# services.yml
services:
  my_service:
    class: MyNamespace\MyService
    arguments: [arg1, '%database_name%']

  my_other_service:
    class: MyNamespace\MyOtherService
    arguments: ['@my_service']
    calls:
      -
        method: doThing
        arguments: [arg1, arg2]

# secrets.yml
parameters:
    secret: 'TopsyCrett'

Create container:, (*7)

<?php
use Palmtree\Container\ContainerFactory;

$container = ContainerFactory::create('config.yml');

$container->get('my_service')->myMethod();

$container->getParameter('db_username');

Advanced Usage

Factories

Services can be created by calling static factory methods. Arguments are passed to the factory method., (*8)

# services.yml
services:
  my_service:
    factory: 'MyNamespace\MyFactory:createService'
    arguments: [argForCreateService]

Private Services

Services can be defined as private, meaning they can only be used via dependency injection and cannot be retrieved from the container directly:, (*9)

# services.yml
services:
  my_service:
    class: MyNamespace\MyService
    public: false

  my_consumer:
    class: MyNamespace\MyConsumer
    arguments:
        - "@my_service"

The following will throw a ServiceNotPublicException:, (*10)

<?php
$container->get('my_service');

Whilst the following will work:, (*11)

<?php
namespace MyNamespace;

class MyConsumer {
    public function __construct(MyService $myService) {
    }
}

Prior Art

Inspired by Symfony's DependencyInjection component., (*12)

License

Released under the MIT license, (*13)

The Versions

10/07 2018

dev-master

9999999-dev

Service Container component for Palmtree PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

10/07 2018

v0.8.1

0.8.1.0

Service Container component for Palmtree PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

09/07 2018

v0.8.0

0.8.0.0

Service Container component for Palmtree PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

04/07 2018

v0.7.0

0.7.0.0

Service Container component for Palmtree PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

04/07 2018

v0.6.0

0.6.0.0

Service Container component for Palmtree PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

29/06 2018

v0.5.3

0.5.3.0

Service Container component for Palmtree PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

20/05 2018

v0.5.2

0.5.2.0

Service Container component for Palmtree PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

20/05 2018

v0.5.1

0.5.1.0

Service Container component for Palmtree PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

09/05 2018

v0.5.0

0.5.0.0

Service Container component for Palmtree PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

18/11 2017

dev-feature/refactor

dev-feature/refactor

Service Container component for Palmtree PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

14/11 2017

v0.4.0

0.4.0.0

Service Container component for Palmtree PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

13/11 2017

v0.3.3

0.3.3.0

Service Container component for Palmtree PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

13/11 2017

v0.3.2

0.3.2.0

Service Container component for Palmtree PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

12/11 2017

v0.3.1

0.3.1.0

Service Container component for Palmtree PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

12/11 2017

v0.3.0

0.3.0.0

Service Container component for Palmtree PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

12/11 2017

v0.2.0

0.2.0.0

Service Container component for Palmtree PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

12/11 2017

v0.1.1

0.1.1.0

Service Container component for Palmtree PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

02/11 2017

v0.1.0

0.1.0.0

Service Container component for Palmtree PHP

  Sources   Download

MIT

The Requires

 

The Development Requires