2017 © Pedro Peláez
 

library common-factories

This project provides utility factories that can be used directly in service providers complying with the container-interop/service-provider standard.

image

thecodingmachine/common-factories

This project provides utility factories that can be used directly in service providers complying with the container-interop/service-provider standard.

  • Friday, September 22, 2017
  • by mouf
  • Repository
  • 1 Watchers
  • 1 Stars
  • 36,729 Installations
  • PHP
  • 10 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 30 % Grown

The README.md

Scrutinizer Code Quality Build Status Coverage Status, (*1)

Utility factories for container-interop/service-provider

Work in progress., (*2)

This project is part of the container-interop group. It tries to find a solution for cross-framework modules (aka bundles) by the means of container-agnostic configuration., (*3)

Goal of this project

This project provides utility factories that can be used directly in service providers complying with the container-interop/service-provider standard., (*4)

Those common factories can be detected by compiled/cached containers. The aim of this package is to offer a common set of useful classes that can also be preprocessed by optimized containers for best performance., (*5)

Usage

Simply require this package in your package declaring your service-provider:, (*6)

So far, the package has the thecodingmachine vendor name. It will hopefully be migrated to container-interop/common-factories, (*7)

composer require thecodingmachine/common-factories

Then, you can use one of the 3 available classes:, (*8)

Creating an alias

Use the Alias class to easily create an alias., (*9)

public function getFactories() {
    return [
        'myAlias' => new Alias('myService')
    ]
}

can easily replace:, (*10)

public function getFactories() {
    return [
        'myAlias' => function(ContainerInterface $container) {
            return $container->get('myService');
        }
    ]
}

Creating a parameter

Use the Parameter class to put in the container a scalar (or array of scalar) entry:, (*11)

public function getFactories() {
    return [
        'DB_HOST' => new Parameter('localhost')
    ]
}

can easily replace:, (*12)

public function getFactories() {
    return [
        'DB_HOST' => function() {
            return 'localhost';
        }
    ]
}

Appending a service to an array of services

Use the AddToArray class to push a new service to an existing array:, (*13)

public function getExtensions() {
    return [
        MyTwigExtension::class => function() {
            return new MyTwigExtension();
        },
        'twig.extensions' => new AddToArray(MyTwigExtension::class)
    ]
}

can easily replace:, (*14)

public function getExtensions() {
    return [
        MyTwigExtension::class => function() {
            return new MyTwigExtension();
        },
        'twig.extensions' => function(ContainerInterface $container, array $extensions = []) {
            $extensions[] = $container->get(MyTwigExtension::class);
            return $extensions;
        }
    ]
}

The Versions

22/09 2017

dev-master

9999999-dev

This project provides utility factories that can be used directly in service providers complying with the container-interop/service-provider standard.

  Sources   Download

MIT

The Requires

 

The Development Requires

22/09 2017

v0.4.0

0.4.0.0

This project provides utility factories that can be used directly in service providers complying with the container-interop/service-provider standard.

  Sources   Download

MIT

The Requires

 

The Development Requires

22/09 2017

v0.3.1

0.3.1.0

This project provides utility factories that can be used directly in service providers complying with the container-interop/service-provider standard.

  Sources   Download

MIT

The Requires

 

The Development Requires

16/05 2016

v0.3.0

0.3.0.0

This project provides utility factories that can be used directly in service providers complying with the container-interop/service-provider standard.

  Sources   Download

MIT

The Requires

 

The Development Requires