PHP code example of symfonyid / symfony-bundle-plugins

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

    

symfonyid / symfony-bundle-plugins example snippets


use Symfonian\Indonesia\BundlePlugins\PluginBundle;

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

use Symfonian\Indonesia\BundlePlugins\PluginBundle;
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 PluginBundle
{
    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 PluginBundle
{
    ...

    public function build(ContainerBuilder $container)
    {
        $container->addCompilerPass(...);
    }
}

class FooPlugin implements PluginBundle
{
    ...

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