Build Status Scrutinizer Quality Score Latest Stable Version Total Downloads

SensioLabsInsight PrestaComposerPublicBundle on Knpbundles

Overview

The goal of this bundle is to provide a simple way to include public 3rd-party libraries (javascripts, css, pictures …) into your projects and keep its up-to-date.

  1. Add the library to composer.json
  2. Configure the library in PrestaComposerPublicBundle
  3. Use the library as any other assets in the project.

Installation

Get the code

The easiest way is to use composer :

php composer.phar require presta/composer-public-bundle --no-update
php composer.phar update presta/composer-public-bundle

Append the following commands to post install/update’s section of composer.json like this :

"scripts": {
    "post-install-cmd": [
        "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
        "Presta\\ComposerPublicBundle\\Composer\\ScriptHandler::ComposerPublic",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
    ],
    "post-update-cmd": [
        "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
        "Presta\\ComposerPublicBundle\\Composer\\ScriptHandler::ComposerPublic",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
    ]
},

Update your Kernel

<?php
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            ...,
            new Presta\ComposerPublicBundle\PrestaComposerPublicBundle()
        );
    }
}

Usage

Add a library

For example, i want to add a jQuery plugin into my project. Unfortunatly the library is not in packagist.

So as explain in the composer documentation, edit composer.json :

{
    ...
    "repositories": [
        {
            "type": "package",
            "package": {
                "name": "wesnolte/Pajinate",
                "version": "1.0.0",
                "source": {
                    "url": "https://github.com/wesnolte/Pajinate.git",
                    "type": "git",
                    "reference": "master"
                }
            }
        }
    ],
    ...
}

And then add it to the require section :

{
    ...
    "require": {
        ...
        "wesnolte/Pajinate": "1.0.*"
    },
    ...
}

Finally you need to add an entry for this library in the PrestaComposerPublicBundle configuration.

Eg. app/config/config.yml:

presta_composer_public:
    symlink: true
    blend:
        wesnolte/Pajinate:
            vendor: wesnolte
            name: Pajinate
            path: /

Or shortly:

presta_composer_public:
    blend:
        wesnolte/Pajinate: ~

Launch the command app/console config:dump-reference PrestaComposerPublicBundle for more details.

By default, assets from vendor/wesnolte/Pajinate (for example) were hard copy to Ressources/public/ of the prestaComposerPublicBundle.

If symlink: true option is set and OS was able to use it, a symlink replace hard copy.

Blend it

Finally you only need to install your vendors:

composer.phar install

or manually launch symfony command:

app/console  presta:composer-public

Include assets

{# layout.html.twig #}
{%javascripts
        ...
    '@PrestaComposerPublicBundle/Resources/public/wesnolte/Pajinate/jquery.pajinate.js'
%}
    <script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}

Example

PrestaCMSCKEditorBundle use PrestaComposerPublicBundle to integrate CKEditor in PrestaCMS with SonataMedia and page links.

For a ready to use demonstration of those bundle you should check the prestacms-sandbox available on github.

Sandbox is also deployed for a live demonstration :

How to get help and support

If you need help on one of our bundle, please register to our google group and ask you question. You can open issues on github too.


Want do contribute ? Just fork and edit it!