定制 cocur/pli 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

cocur/pli

最新稳定版本:v0.1.2

Composer 安装命令:

composer require cocur/pli

包简介

Pli is a library and set of conventions to bootstrap Console applications with Symfony Console, DependencyInjection and Config components.

README 文档

README

Pli is a library and set of conventions to bootstrap Console applications with Symfony Console, DependencyInjection and Config components.

Latest Version Build Status Scrutinizer Code Quality Code Coverage

The Symfony components are incredible powerful, but the price for this flexibility is quite a bit of bootstrapping code to set the components up. Especially when integrating Console, DependencyInjection and Config a developer has to copy and adapt a lot of code from the docs. Pli uses some assumptions (such as config files in Yaml format) to reduce the amount of code required to bootstrap a simple console application.

Developed by Florian Eckerstorfer in Vienna, Europe.

Installation

You can install Pli using Composer.

$ composer require cocur/pli

Usage

Bootstrapping a console application with Pli is a three-step process.

  1. Load configuration: Load and parse one or more Yaml config files.
  2. Build container: Create a container and invokes the extension to initialize it
  3. Create application: Creates and application and adds all command tagged with command to it. If a command implements ContainerAwareInterface the container is set on the command.

First we need our main file with the initialization of Pli. You also need a configuration and a extension class and Pli is very similar to Symfony in this regard. However, the Pli-version of an extension has far less features.

// console.php

use Cocur\Pli\Pli;

$pli = new Pli(__DIR__.'/config');
$config = $pli->loadConfiguration(new AcmeConfiguration(), ['config.yml']);
$container = $pli->buildContainer(new AcmeExtension(), $config);
$application = $pli->getApplication($container);
$application->run();
// src/AcmeConfiguration.php

<?php

use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;

class BranConfiguration implements ConfigurationInterface
{
    public function getConfigTreeBuilder()
    {
        $treeBuilder = new TreeBuilder();
        $rootNode = $treeBuilder->root('acme');

        return $treeBuilder;
    }
}

Pli also needs an extension that is used to build the container. You can set parameters, dynamically create service definitions and so on. If you want to store your service configuration in a Yaml file you can use the configDirectories property to retrieve the path to the config directory.

// src/AcmeExtension.php
<?php

use Cocur\Pli\Container\ExtensionInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;

class BranExtension implements ExtensionInterface
{
    private $configDirectories;

    public function buildContainer(ContainerBuilder $container, array $config = [])
    {
        $loader = new YamlFileLoader($container, new FileLocator($this->configDirectories));
        $loader->load('services.yml');
    }

    public function setConfigDirectories(array $configDirectories)
    {
        $this->configDirectories = $configDirectories;
    }
}

Change Log

Version 0.1.2 (5 June 2015)

  • Add parameters and compiler passes to container

Version 0.1.1 (5 June 2015)

  • Add support for multiple configuration directories

Version 0.1 (18 May 2015)

  • Initial release

License

The MIT license applies to cocur/pli. For the full copyright and license information, please view the LICENSE file distributed with this source code.

统计信息

  • 总下载量: 43
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-11-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固