2017 © Pedro Peláez
 

symfony-bundle LilaConceptsBestPracticeBundle

Simple common, starter, empty, boilerplate-bundle to show best practice bundle development for Symfony2.1. This bundle has the right directory structure, coding standards, unittests and functional tests. It uses the Travis Continuous Integration buildbot, Composer for dependency management and Twig for templating. Read the documentation and fork/clone if you wish.

image

LilaConcepts/LilaConceptsBestPracticeBundle

Simple common, starter, empty, boilerplate-bundle to show best practice bundle development for Symfony2.1. This bundle has the right directory structure, coding standards, unittests and functional tests. It uses the Travis Continuous Integration buildbot, Composer for dependency management and Twig for templating. Read the documentation and fork/clone if you wish.

  • Tuesday, November 27, 2012
  • by afjlambert
  • Repository
  • 7 Watchers
  • 79 Stars
  • 145 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 27 Forks
  • 12 Open issues
  • 1 Versions
  • 1 % Grown

The README.md

What is Best Practice Bundle?

Build Status, (*1)

This is a simple bundle to show different best practices for Symfony Bundles development. This bundle could as well be named starter-bundle, empty-bundle or boilerplate-bundle. The master-branch follows the future Symfony 2.1 release (upgrade notes)., (*2)

Use the bundle as a reference (or cheatsheet) for your own bundles. Also look at the documentation and comments in the source if you forgot how to do something., (*3)

Of course you can use this bundle as a "Boilerplate" or empty/starter bundle if you plan to build your own bundle. Fork or clone this bundle if you wish. Please search knpBundles.com before you build a new bundle. See if something simimlar is already out there., (*4)

For active developments see the Changelog., (*5)

What does this bundle do?

Bugs and Roadmap

Before providing bug-reports please read the current issues and forum first. The roadmap for the future of this bundle is described below., (*6)

Future features and documentation

Help appreciated, see enhancements under issues). Please +1 the enhancements you are interested in., (*7)

  • make /best-practice/ available for the functional test
  • clone the bundle via command as an alternative to generate:bundle
  • multiple languages / locale / i18n examples
  • provide tutorials / blog-posts (yaml, caching with Varnish, Vagrant etc.)
  • more info on cache management
  • more logging (via monolog)
  • more information on routing/paths, assetic and forms
  • custom exceptions
  • add edge side include (esi), session, validator and redirect tests
  • add mime-type tests like xml and json tests
  • use phantomjs.org for javascript tests?
  • Object-relational mapping (ORM): Propel/Doctrine entity integration?
  • html5 boilerplate?
  • make this bundle work with ZF2 too?

Requirements

  • Symfony2.1 (PHP 5.3.3 and up including Composer)
  • Twig

Installation

Add the following line to your composer.json file., (*8)

//composer.json
{
    //...

    "require": {
        //...
        "LilaConcepts/LilaConceptsBestPracticeBundle" : "dev-master"
    }

    //...
}

If you haven't allready done so, get Composer (make sure it's up-to-date)., (*9)

curl -s http://getcomposer.org/installer | php

And install the new bundle, (*10)

php composer.phar update LilaConcepts/LilaConceptsBestPracticeBundle

Configure

The final step is to add the bundle to your AppKernel.php., (*11)

<?php

    // in AppKernel::registerBundles()
    $bundles = array(
        // Dependencies
        new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
        new Symfony\Bundle\TwigBundle\TwigBundle(),
    );

    // Optionally place it in the dev and test-environments only
    if (in_array($this->getEnvironment(), array('dev', 'test'))) {
        // ...
        $bundles[] = new LilaConcepts\Bundle\LilaConceptsBestPracticeBundle\LilaConceptsBestPracticeBundle()
    }

Code Standards Fixer

Optionally you can let the PHP-CS-fixer check for coding standards on every commit. Run the following code from your Bundle project-root. Warning: check if you have a pre-commit hook allready in place so you won't override anything., (*12)

cp hooks/pre-commit-cs-fixer .git/hooks/pre-commit
chmod a+x .git/hooks/pre-commit

The hook will make sure 'php-cs-fixer.phar' from fabpot/PHP-CS-Fixer is available in your project root. It checks all the code inside your bundle. If the fixer finds an error it will abort the commit and present you with a copy-pastable command for fixing it., (*13)

An example of the output, (*14)

afjlambert@iMac:~/Sites/MyBundle (master)$ git commit -a
Coding standards are not correct, cancelling your commit.

1) LilaConceptsBestPracticeBundle.php (extra_empty_lines)

If you want to fix them run:

    php /Users/afjlambert/Sites/MyBundle/php-cs-fixer.phar fix /Users/afjlambert/Sites/MyBundle --verbose

phpDocumentor2

If you want you can generate phpDocumentor2 documentation about your module. To install run:, (*15)

mkdir -p vendor/phpdocumentor/phpdocumentor
cd vendor/phpdocumentor/phpdocumentor
git clone https://github.com/phpDocumentor/phpDocumentor2.git ./
../../../composer.phar install
cd -

And generate the doc's, (*16)

php vendor/phpdocumentor/phpdocumentor/bin/phpdoc.php --target Resources/doc/generated/phpDocumentor

Now via your finder/browser open Resources/doc/generated/phpDocumentor/index.html., (*17)

(unit-) Test the bundle

If you want to unittest the bundle, just type this into your bundle-root:, (*18)

phpunit

If you want to get the test-coverage of your code:, (*19)

phpunit --coverage-html Resources/doc/generated/code-coverage

Now via your finder/browser open Resources/doc/generated/code-coverage/index.html., (*20)

If you want to test the bundle manually, point your browser to http://localhost/app_dev.php/best-practice/ (under development, does not work yet!), (*21)

Standalone Installation

If you want to download and unittest the code, you don't need a working Symfony project. Just run the following., (*22)

git clone https://github.com/LilaConcepts/LilaConceptsBestPracticeBundle.git
cd LilaConceptsBestPracticeBundle
curl -s http://getcomposer.org/installer | php
php composer.phar install

You should be able to unittest the bundle now., (*23)

Fork/clone the Bundle for your own use

Click the Fork button on https://github.com/LilaConcepts/LilaConceptsBestPracticeBundle. Then click on Admin and rename the bundle. Please stick with the naming conventions and use something like 'myfeature-bundle' or 'myadmin-bundle'. You are ready with the github part, it's time to clone the respository into a temporary folder and make some changes. Set your own Github URL and Bundle/Company name., (*24)

mkdir temp/ && cd temp/
BUNDLE=MainBundle
COMPANY=Acme
GITHUBURL=https://github.com/[your account name]/[your bundle name]-bundle.git

Now run the following code:, (*25)

SHORTBUNDLE=`echo ${BUNDLE} | sed 's/Bundle//'`
COMPLETENAME=${COMPANY}${SHORTBUNDLE}
LOGICALNAME=`echo ${COMPANY}_${SHORTBUNDLE} | tr '[A-Z]' '[a-z]'`
DIRNAME=`echo ${SHORTBUNDLE} | tr '[A-Z]' '[a-z]'`-bundle

git clone ${GITHUBURL} ${BUNDLE}
cd ${BUNDLE}

FILES=`find . -regex '.*/*.[php|yml]' -type f`
sed -i '' -e 's/LilaConcepts\\Bundle\\LilaConceptsBestPracticeBundle/'${COMPANY}'\\Bundle\\'${COMPANY}${BUNDLE}'/g' ${FILES}
sed -i '' -e 's/lilaconcepts_bestpractice/'${LOGICALNAME}'/g' ${FILES}
sed -i '' -e 's/LilaConceptsBestPracticeExtension/'${COMPLETENAME}Extension'/g' ${FILES}
sed -i '' -e 's/LilaConceptsBestPracticeBundle/'${COMPLETENAME}Bundle'/g' ${FILES} composer.json
sed -i '' -e 's/LilaConcepts/'${COMPANY}'/g' composer.json

mv ./DependencyInjection/LilaConceptsBestPracticeExtension.php ./DependencyInjection/${COMPLETENAME}Extension.php
mv ./LilaConceptsBestPracticeBundle.php ./${COMPLETENAME}Bundle.php

echo -e "\n\nDone, please inspect the changes and push it back to github:\n\n    git push\n\nYou will need this later for your AppKernel.php:\n\n    new ${COMPANY}\Bundle\\${BUNDLE}\\${COMPANY}${BUNDLE}()\n"

Optionally:, (*26)

curl -s http://getcomposer.org/installer | php
php composer.phar install

Now you can test your bundle. Be sure to update the following files before pushing it back to Github: - composer.json - README.md - LICENCE - CONTRIBUTORS.md - CHANGELOG's - Resource/doc/*, (*27)

Push it back to Github:, (*28)

git add .
git commit -a -m "Initial checkin"
git push

Head over to Packagist and submit your Bundle. Optional: setup a Github Service Hook so packagist will be informed automatically., (*29)

Now install your bundle following these instructions with your own packagist name of course. You can remove the temp/ directory we created and work inside the vendor/.../Bundle/YourBundle directory., (*30)

Documentation

For more information see Resources/doc/index.rst. Feel free to fix typo's., (*31)

Contributing

First of all, many thanks to all the contributors and people who inspired us. If you like to help making Best Practice Bundle better, or if you see anything that's wrong, send me a personal message or provide a bug report under issues. Even better if you could send a pull-request. If you have any further questions please head over to the forum., (*32)

Licence

This bundle is released under the MIT Licence by Lila Concepts B.V., see the LICENCE-file for more information. Lila Concepts B.V. is a dutch organisation and the creator of Aandelen Kopen and Beleggen voor Beginners amongst other sites., (*33)

The Versions

27/11 2012

dev-master

9999999-dev

Simple common, starter, empty, boilerplate-bundle to show best practice bundle development for Symfony2.1. This bundle has the right directory structure, coding standards, unittests and functional tests. It uses the Travis Continuous Integration buildbot, Composer for dependency management and Twig for templating. Read the documentation and fork/clone if you wish.

  Sources   Download

MIT

The Requires

 

development bundle symfony