thecodingmachine/common-factories 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

thecodingmachine/common-factories

最新稳定版本:v0.4.1

Composer 安装命令:

composer require thecodingmachine/common-factories

包简介

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

README 文档

README

Scrutinizer Code Quality Build Status Coverage Status

Utility factories for container-interop/service-provider

Work in progress.

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.

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.

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.

Usage

Simply require this package in your package declaring your service-provider:

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

composer require thecodingmachine/common-factories

Then, you can use one of the 3 available classes:

Creating an alias

Use the Alias class to easily create an alias.

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

can easily replace:

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:

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

can easily replace:

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:

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

can easily replace:

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

统计信息

  • 总下载量: 192.54k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 9
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-05-16