PHP code example of matthiasnoback / symfony-bundle-plugins

1. Go to this page and download the library: Download matthiasnoback/symfony-bundle-plugins 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/ */

    

matthiasnoback / symfony-bundle-plugins example snippets


use Matthias\BundlePlugins\BundleWithPlugins;

class DemoBundle extends BundleWithPlugins
{
    protected function getAlias()
    {
        return 'demo';
    }
}

use Matthias\BundlePlugins\BundlePlugin;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;

class FooPlugin implements BundlePlugin
{
    public function name()
    {
        return 'foo';
    }

    public function load(
        array $pluginConfiguration, 
        ContainerBuilder $container
    ) {
        // load specific service definitions for this plugin,
        // just like you would do in a bundle extension
        
        $loader = new YamlFileLoader($container, new FileLocator(__DIR__));
        $loader->load('foo.yml');
        
        // $pluginConfiguration contains just the values that are relevant 
        // for this plugin
    }

    public function addConfiguration(ArrayNodeDefinition $pluginNode)
    {
        // add plugin-specific configuration nodes, 
        // just like you would do in a bundle extension
    
        $pluginNode
            ->children()
                ->scalarNode('foo')
                ->isRequired()
            ->end();
    }
}

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        return array(
            ...,
            new DemoBundle(array(new FooPlugin()))
        );
    }
}

class DemoBundle
{
    ...
    
    protected function alwaysRegisteredPlugins()
    {
        return array(new CorePlugin());
    }
}

class FooPlugin implements BundlePlugin
{
    ...
    
    public function build(ContainerBuilder $container)
    {
        $container->addCompilerPass(...);
    }
}

class FooPlugin implements BundlePlugin
{
    ...
    
    public function boot(ContainerInterface $container)
    {
        // runtime initialization (will run when the kernel itself is 
        // booted)
    }
}