PHP code example of cocur / pli

1. Go to this page and download the library: Download cocur/pli library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cocur / pli example snippets


// 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



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;
    }
}

// src/AcmeExtension.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;
    }
}