2017 © Pedro Peláez
 

symfony-bundle redkite-labs-bootstrap-bundle

RedKiteLabsBootstrapBundle takes care to autoload and configure bundles on a composer base application. The responsibility to configure the bundle is delegated to the bundle's author, who implements an autoloader.json file, where declares the bundle's configuration.

image

redkite-labs/redkite-labs-bootstrap-bundle

RedKiteLabsBootstrapBundle takes care to autoload and configure bundles on a composer base application. The responsibility to configure the bundle is delegated to the bundle's author, who implements an autoloader.json file, where declares the bundle's configuration.

  • Tuesday, October 28, 2014
  • by redkite-labs
  • Repository
  • 2 Watchers
  • 8 Stars
  • 5,111 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 16 Versions
  • 0 % Grown

The README.md

RedKiteLabsBootstrapBundle

RedKiteLabsBootstrapBundle takes care to autoload and configure Symfony2 bundles for an application which dependencies are managed by composer., (*1)

To autoload a bundle, without requiring to declare it in Symfony2's AppKernel, you just need to create an autoloader.json file on the bundle's top folder and let the RedKiteLabsBootstrapBundle do the hard job for you., (*2)

You can autoload your bundles by environments and you can add a base configuration to your bundle, saved in a config.yml file which comes with the bundle itself, to define the base configuration for your bundle the user should manually add to application's config.yml file., (*3)

As for configuration, you can define your routes in the routing.yml file and distribute them with the bundle., (*4)

Build Status Scrutinizer Quality Score Code Coverage, (*5)

Install the RedKiteLabsBootstrapBundle

To install the RedKiteLabsBootstrapBundle, simply require it in your composer.json:, (*6)

"require": {
    [...]
    "redkite-labs/bootbusiness-theme-bundle": "dev-master"
}

then install/update the packages:, (*7)

php composer.phar install/update

At last the bundle must be added to the AppKernel.php file:, (*8)

public function registerBundles()
{
    $bundles = array(
        new RedKiteLabs\RedKiteCms\BootstrapBundle\RedKiteLabsBootstrapBundle(),

        [...]
    );
}

The autoload.json file

The autoload.json file must be placed in bundle's top folder and it is structured as follows:, (*9)

  • bundles (mandatory)
  • routing

The mandatory bundles section contains the bundles you want to autoload. Let's see a very basic example:, (*10)

{
    "bundles" : {
        "RedKiteLabs\\Block\\BusinessDropCapBundle\\BusinessDropCapBundle" : ""
    }
}

This autoloads the BusinessDropCapBundle for the whole application's environments., (*11)

Environments

When you need to autoload a bundle only for certains environments, just add the environments option to the bundle:, (*12)

{
    "bundles" : {
        "RedKiteLabs\\Block\\BusinessDropCapBundle\\BusinessDropCapBundle" : {
            "environments" : ["dev", "test"]
        }
    }
}

The environments option enables the bundle only for the declared environments. In the example above, the BusinessDropCapBundle is enabled only for the dev and test enviroments., (*13)

The all keyword

To specifiy all the enviroments you can use the all keyword:, (*14)

{
    "bundles" : {
        "RedKiteLabs\\Block\\BusinessDropCapBundle\\BusinessDropCapBundle" : {
            "environments" : ["all"]
        }
    }
}

This is the default option used by the library when the environments one is not defined., (*15)

The overrides options

When a bundle overrides another bundle, it must be instantiated in the AppKernel after the overrided bundle., (*16)

You can implement this case in your autoload.json adding the overrides option:, (*17)

{
    "bundles" : {
        "RedKiteLabs\\Block\\BusinessDropCapBundle\\BusinessDropCapBundle" : {
            "environments" : ["dev", "test"],
            "overrides" : ["BusinessCarouselBundle"]
        }
    }
}

In this example the bundles order will be resolved instantiating the BusinessCarouselBundle before the BusinessDropCapBundle, (*18)

Autoloading a bundle without the autoloader.json file

You might wonder why we are talking about "bundles" and not just "bundle". This is quite simple to explain, in fact you could autoload a bundle when it does not implement the autoloader.json file., (*19)

Let's suppose the BusinessCarouselBundle has not the autoloader.json file and the BusinessDropCapBundle requires it. You can write the BusinessDropCapBundle's autoloader as follows to autoload it:, (*20)

For example, let's uppose the BusinessCarouselBundle requires the PropelBundle to work and this last bundle does not implements the autoloader.json file., (*21)

In this case you can easily autoload the PropelBundle just declaring that bundle in you autoload.json file:, (*22)

{
    "bundles" : {
        "RedKiteLabs\\Block\\BusinessDropCapBundle\\BusinessDropCapBundle" : {
                "environments" : ["dev", "test"]
        },
        "RedKiteLabs\\Block\\BusinessCarouselBundle\\BusinessCarouselBundle" : ""
    }
}

If you need to enable it for specific environments, you just have to add the environments option as explained above., (*23)

Another situation could ben when a bundle implements its own environments. For example the RedKiteCmsBundle implements the rkcms and the rkcms_dev environments so we need to register many thirdy part bundles:, (*24)

{
    "bundles" : {
        "RedKiteLabs\\RedKiteCmsBundle\\RedKiteCmsBundle" : {
            "environments" : ["rkcms", "rkcms_dev", "rkcms_test", "test"]
        },
        "Propel\\PropelBundle\\PropelBundle" : {
            "environments" : ["rkcms", "rkcms_dev", "rkcms_test", "test"]
        },
        "Symfony\\Bundle\\WebProfilerBundle\\WebProfilerBundle" : {
            "environments" : ["rkcms_dev", "rkcms_test"]
        },
        "Sensio\\Bundle\\DistributionBundle\\SensioDistributionBundle" : {
            "environments" : ["rkcms_dev", "rkcms_test"]
        },
        "Sensio\\Bundle\\GeneratorBundle\\SensioGeneratorBundle" : {
            "environments" : ["rkcms", "rkcms_dev", "rkcms_test"]
        }
    }
}

The "RedKiteLabs\RedKiteCmsBundle\RedKiteCmsBundle" section enables the RedKiteCmsBundle for the "rkcms", "rkcms_dev", "rkcms_test", "test", then requires the PropelBundle for the same environments and at last requires the WebProfilerBundle, the SensioDistributionBundle and the SensioGeneratorBundle for the "rkcms_dev", "rkcms_test" environments., (*25)

Configuration files (config.yml - routing.yml)

Usually each bundle requires to add some configurations inside the application's config.yml to make it work properly. Some of these settings could be generic, ie. enabling the bundle to use assetic, while others could be specific for the application which is using that bundle., (*26)

The BootstrapBundle let the developer to define the generic settings directly with the bundle. This will produce some benefits for the final user:, (*27)

  • The bundle that requires only generic setting is ready to be used without touching the application's config.yml file
  • When the bundle is used by many applications, the generic configuration is already made
  • Less frustation for the user
  • Less frustation for the bundle's developer who has to write less documentation
  • Light config.yml file

To add a configuration that usually goes into the application's config.yml file, just add a config.yml file under the Resources/config folder of your bundle and add the required setting to it., (*28)

The BootstrapBundle takes care to copy it into the app/config/bundles/[environment] folder and load your configuration in the AppKernel class., (*29)

The same concepts are applied to the routes implemented by the bundle, so you can add a routing.yml file into the Resources/config of your bundle and the BootstrapBundle will do the rest for you., (*30)

Routing priority

When you need to assign a specific priority to routing files, you can add a routing/priority setting to your configuration file:, (*31)

{
    "bundles" : {
        "RedKiteLabs\\Block\\BusinessDropCapBundle\\BusinessDropCapBundle" : ""
    },
    "routing" : {
        "priority" : "128"
    }
}

Each bundle gets zero as routing priority when the option is not specified. To load the routing file after, specify a value higher than zero, to load the routing file before, specify a value lower than zero., (*32)

A practical example

For example, RedKiteCmsBundle uses assetic to manage its assets, so the user who want to use that bundle should add the following configuration to the config.yml file of his application:, (*33)

app/config/config.yml

assetic:
bundles: [RedKiteLabsCmsBundle]
filters:
    cssrewrite: ~
    yui_css:
        jar: %kernel.root_dir%/Resources/java/yuicompressor.jar
    yui_js:
        jar: %kernel.root_dir%/Resources/java/yuicompressor.jar

With the BootstrapBundle these setting have been added to RedKiteCmsBundle's config.yml file so the user is not required to manually add those settings to application's config.yml., (*34)

Enabling the routing autoloader

To enable the routing autoloader the following configuration must be added to the application's routing.yml configuration file:, (*35)

RedKiteLabsBootstrapBundle:
    resource: .
    type: bootstrap

Use the BootstrapBundle in your AppKernel

To enable the autoloading some small changes must be implemented to the AppKernel file. At the end of the registerBundles method, declare a new BundlesAutoloader object, as follows:, (*36)

public function registerBundles()
{
    $bundles = array(
        [...]
    );

    if (in_array($this->getEnvironment(), array('dev', 'test'))) {
        [...]
    }

    $bootstrapper = new \RedKiteLabs\RedKiteCms\BootstrapBundle\Core\Autoloader\BundlesAutoloader(__DIR__, $this->getEnvironment(), $bundles);
    $bundles = $bootstrapper->getBundles();

    return $bundles;
}

BundlesAutoloader requires the kernel dir, the one where the AppKernel is placed, as first argument, the current environment as second argument and the instantiated bundles as third., (*37)

Bundles are retrieved by the getBundles method and returned as usual., (*38)

To load the configurations from the app/config/bundles folder, the default registerContainerConfiguration must be changed as follows:, (*39)

public function registerContainerConfiguration(LoaderInterface $loader)
{
    $configFolder = __DIR__ . '/config/bundles/config/' . $this->getEnvironment();
    if (is_dir($configFolder)) {
        $finder = new \Symfony\Component\Finder\Finder();
        $configFiles = $finder->depth(0)->name('*.yml')->in($configFolder);
        foreach ($configFiles as $config) {
            $loader->load((string)$config);
        };
    };

    $loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
}

Autoload bundles from other folders

BundlesAutoloader can be configured to look for autoloading bundles placed inside other folders in your application., (*40)

By defaut the BundlesAutoloader looks into the src/RedKiteCms/Block and the src/RedKiteCms/Theme folders., (*41)

You can easily change that parameter, passing an array with your folders defined into to the BundlesAutoloader declaration., (*42)

For example, if you would need to tell BundlesAutoloader to look into the src/Acme just change the BundlesAutoloader instantiation as follows:, (*43)

$bootstrapper = new \RedKiteLabs\BootstrapBundle\Core\Autoloader\BundlesAutoloader(__DIR__, $this->getEnvironment(), $bundles, array(__DIR__ . '/../src/Acme');

Please notice that the BundlesAutoloader assumes that your bundles are placed inside the Acme folder., (*44)

The Versions

28/10 2014

dev-master

9999999-dev http://redkite-labs.com

RedKiteLabsBootstrapBundle takes care to autoload and configure bundles on a composer base application. The responsibility to configure the bundle is delegated to the bundle's author, who implements an autoloader.json file, where declares the bundle's configuration.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by RedKite Labs

bootstrap bundle autoload redkite-labs

13/04 2014

1.1.x-dev

1.1.9999999.9999999-dev http://redkite-labs.com

RedKiteLabsBootstrapBundle takes care to autoload and configure bundles on a composer base application. The responsibility to configure the bundle is delegated to the bundle's author, who implements an autoloader.json file, where declares the bundle's configuration.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by RedKite Labs

bootstrap bundle autoload redkite-labs

13/04 2014

v1.1.4.1

1.1.4.1 http://redkite-labs.com

RedKiteLabsBootstrapBundle takes care to autoload and configure bundles on a composer base application. The responsibility to configure the bundle is delegated to the bundle's author, who implements an autoloader.json file, where declares the bundle's configuration.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by RedKite Labs

bootstrap bundle autoload redkite-labs

13/04 2014

v1.1.4.2

1.1.4.2 http://redkite-labs.com

RedKiteLabsBootstrapBundle takes care to autoload and configure bundles on a composer base application. The responsibility to configure the bundle is delegated to the bundle's author, who implements an autoloader.json file, where declares the bundle's configuration.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by RedKite Labs

bootstrap bundle autoload redkite-labs

13/04 2014

v1.1.4.3

1.1.4.3 http://redkite-labs.com

RedKiteLabsBootstrapBundle takes care to autoload and configure bundles on a composer base application. The responsibility to configure the bundle is delegated to the bundle's author, who implements an autoloader.json file, where declares the bundle's configuration.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by RedKite Labs

bootstrap bundle autoload redkite-labs

13/04 2014

v1.1.4.4

1.1.4.4 http://redkite-labs.com

RedKiteLabsBootstrapBundle takes care to autoload and configure bundles on a composer base application. The responsibility to configure the bundle is delegated to the bundle's author, who implements an autoloader.json file, where declares the bundle's configuration.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by RedKite Labs

bootstrap bundle autoload redkite-labs

13/04 2014

v1.1.6

1.1.6.0 http://redkite-labs.com

RedKiteLabsBootstrapBundle takes care to autoload and configure bundles on a composer base application. The responsibility to configure the bundle is delegated to the bundle's author, who implements an autoloader.json file, where declares the bundle's configuration.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by RedKite Labs

bootstrap bundle autoload redkite-labs

13/04 2014

1.1.3.5

1.1.3.5 http://redkite-labs.com

RedKiteLabsBootstrapBundle takes care to autoload and configure bundles on a composer base application. The responsibility to configure the bundle is delegated to the bundle's author, who implements an autoloader.json file, where declares the bundle's configuration.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by RedKite Labs

bootstrap bundle autoload redkite-labs

13/04 2014

1.1.4

1.1.4.0 http://redkite-labs.com

RedKiteLabsBootstrapBundle takes care to autoload and configure bundles on a composer base application. The responsibility to configure the bundle is delegated to the bundle's author, who implements an autoloader.json file, where declares the bundle's configuration.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by RedKite Labs

bootstrap bundle autoload redkite-labs

13/03 2014

v1.1.3

1.1.3.0 http://redkite-labs.com

RedKiteLabsBootstrapBundle takes care to autoload and configure bundles on a composer base application. The responsibility to configure the bundle is delegated to the bundle's author, who implements an autoloader.json file, where declares the bundle's configuration.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by RedKite Labs

bootstrap bundle autoload redkite-labs

13/03 2014

v1.1.3.1

1.1.3.1 http://redkite-labs.com

RedKiteLabsBootstrapBundle takes care to autoload and configure bundles on a composer base application. The responsibility to configure the bundle is delegated to the bundle's author, who implements an autoloader.json file, where declares the bundle's configuration.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by RedKite Labs

bootstrap bundle autoload redkite-labs

13/03 2014

v1.1.3.2

1.1.3.2 http://redkite-labs.com

RedKiteLabsBootstrapBundle takes care to autoload and configure bundles on a composer base application. The responsibility to configure the bundle is delegated to the bundle's author, who implements an autoloader.json file, where declares the bundle's configuration.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by RedKite Labs

bootstrap bundle autoload redkite-labs

18/01 2014

1.1.1

1.1.1.0 http://redkite-labs.com

RedKiteLabsBootstrapBundle takes care to autoload and configure bundles on a composer base application. The responsibility to configure the bundle is delegated to the bundle's author, who implements an autoloader.json file, where declares the bundle's configuration.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by RedKite Labs

bootstrap bundle autoload redkite-labs

06/12 2013

1.1.0

1.1.0.0 http://redkite-labs.com

RedKiteLabsBootstrapBundle takes care to autoload and configure bundles on a composer base application. The responsibility to configure the bundle is delegated to the bundle's author, who implements an autoloader.json file, where declares the bundle's configuration.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by RedKite Labs

bootstrap bundle autoload redkite-labs

25/08 2013

1.1.0-beta

1.1.0.0-beta http://redkite-labs.com

RedKiteLabsBootstrapBundle takes care to autoload and configure bundles on a composer base application. The responsibility to configure the bundle is delegated to the bundle's author, who implements an autoloader.json file, where declares the bundle's configuration.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by RedKite Labs

bootstrap bundle autoload redkite-labs

25/08 2013

1.1.0-RC

1.1.0.0-RC http://redkite-labs.com

RedKiteLabsBootstrapBundle takes care to autoload and configure bundles on a composer base application. The responsibility to configure the bundle is delegated to the bundle's author, who implements an autoloader.json file, where declares the bundle's configuration.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by RedKite Labs

bootstrap bundle autoload redkite-labs