This bundle is not maintained anylonger because it violates several SOLID principles.
This is a bundle with some basic code I often use in my projects. Feel free to use it or enhance it.
The current version of the bundle is only compatible with Symfony 2.5+ Version 1.0 provides compatibility with older versions of Symfony
Simply run assuming you have installed composer (composer.phar or composer binary) :
php composer.phar require skwi/project-base-bundle "dev-master"
Register the bundle in app/AppKernel.php
:
// app/AppKernel.php
public function registerBundles()
{
return array(
// ...
new \Skwi\Bundle\ProjectBaseBundle\SkwiProjectBaseBundle(),
);
}
In your app/config.yml file, you may need to set up several parameters
skwi_project_base:
entity_bundle_name: FooBarBundle # Default bundle when extending BaseManager (see below)
entity_bundle_namespace: \Foo\Bundle\BarBundle # Default bundle namespace
password_encoder: sha512 # Password encoder method
pager_max_per_page: 10 # Default max items per page when using paginator in the BaseManager
kernel_root_dir: %kernel.root_dir%
This abstract class provides methods for object managed by Doctrine ORM or Doctrine ODM and MongoDb.
The idea is to extends this class to manage a specific entity. Other entities can be managed by an single manager but the $objectName
and $repository
property will be used for a default managed entity.
It's recommended for a manager extend the class and to be injected as a service.
# service.yml
mybundle.manager.poney :
class : 'Foo\\Bundle\\BarBundle\\Manager\\PoneyManager'
parent : skwi.projectbase.base_manager
calls :
- [setObjectManager, [@doctrine.orm.entity_manager]]
- [setObject, ['FooBarBundle:Poney']]
<?php
namespace Foo\Bundle\BarBundle\Manager;
use Skwi\Bundle\ProjectBaseBundle\Manager;
class PoneyManager extends BaseManager
{
#...
}
The method provided by the base manager are described in the class API documentation.
The password encoder class provides an implementation of Symfony's PasswordEncoderInterface using the algorithm defined in the app/config.yml file
It's available as a service in the container.
$encoder = $this->getContainer()->get('skwi.projectbase.password_encoder');
$encodedPassword = $encoder->encodePassword($rawPassword, $salt);
$isPasswordValid = $encoder->isPasswordValid($encodedPassword, $rawPassword, $salt);
The text helper is a static class.
# Slug a string
$sluggedString = TextHelper::slug($rawString);
Note : The slug method is quite basic at the moment, it might be enhance in a future update. Make sure to use 1.* version for compatibility.
A base twig view is provided y the bundle.
{% extends 'SkwiProjectBaseBundle::base.html.twig' %}
It loads the libraries for :
Note : The libraries are loaded form the CDN, with a local fallback for IE version inferior to IE9.
The bundle also provide preset form templates for Bootstrap 3.
{% form_theme form 'SkwiProjectBaseBundle:Form:fields.html.twig' %}
{# or #}
{% form_theme form 'SkwiProjectBaseBundle:Form:fields-horizontal.html.twig' %}
The TextExtension provides the following Twig filters
{{ string|slug # will slug the string using the bundle's TextHelper }}
{{ string|striptags # will apply the strip_tags php method to the string }}
Unit tests are written using atoum. You will get atoum, among other dependencies, when
running composer install
. To run tests, you will need to run the following command :
vendor/bin/atoum
API documentation is generated with PHPDoc and phpdoc-md
To generate it, you will need to run the following commands :
vendor/bin/phpdoc -d src/ -t src/Skwi/Bundle/ProjectBaseBundle/Resources/doc/ --template="xml"
vendor/bin/phpdocmd src/Skwi/Bundle/ProjectBaseBundle/Resources/doc/structure.xml src/Skwi/Bundle/ProjectBaseBundle/Resources/doc
- Remove or enhance the data format helper
- Enhance the slug method in text helper
- Remove twig encoder extension not very usefull
- See with last version of PHP for password encoding
- Update to symfony 2.5 with the property accessor
As of version 2.0.0, version tags are formated in a semantic way :
MAJOR.MINOR.PATCH.
- MAJOR version for incompatible API changes, likely breaking backward compatibility ;
- MINOR version for new functionality (backwards-compatible) ;
- PATCH version for backward compatible bug fixes.