2017 © Pedro Peláez
 

symfony-bundle base-bundle

Symfony Bundle with additional features.

image

mero/base-bundle

Symfony Bundle with additional features.

  • Saturday, June 3, 2017
  • by merorafael
  • Repository
  • 3 Watchers
  • 3 Stars
  • 1,333 Installations
  • PHP
  • 0 Dependents
  • 1 Suggesters
  • 3 Forks
  • 0 Open issues
  • 21 Versions
  • 0 % Grown

The README.md

MeroBaseBundle

SensioLabsInsight Build Status Latest Stable Version Total Downloads License, (*1)

Symfony Bundle with additional features., (*2)

Requeriments

  • PHP 5.4.9 or above
  • Symfony 2.7 or above(including Symfony 3)

Instalation with composer

  1. Open your project directory;
  2. Run composer require mero/base-bundle to add MeroBaseBundle in your project vendor;
  3. Open my/project/dir/app/AppKernel.php;
  4. Add Mero\Bundle\BaseBundle\MeroBaseBundle().

Symfony validators

Applies to Options Class Validator Description
property or method message DateRange DateRangeValidator Validates date range

Basic usage

<?php

use Mero\Bundle\BaseBundle\Validator\Constraints as MeroAssert;

class Payment
{
    /**
     * @var \DateTime Payment date
     *
     * @MeroAssert\DateRange(min="2017-01-01", max="today")
     */
    private $date;
}

Brazilian validators in the new version

The brazilian validators feature has been migrated to the package mero/br-validator-bundle., (*3)

AbstractController to Symfony Controllers

Abstract controller with basic methods for easy identification framework resources., (*4)

Name Atributes Return type Description
getCurrentRequest - Request Gets the cuurrent request
getActionName - string Gets the action name
getBundleName Request $request string Gets the bundle name
getRouteName Request $request string Gets the route name
wsResponse $data, int $status, array $headers, string $format Response Return a new JSON or XML response

Usage example:

namespace Acme\Bundle\BlogBundle\Controller;

use Mero\Bundle\BaseBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

class NewsController extends AbstractController
{

    /**
     * @Route("/", name="news")
     */
    public function indexAction(Request $request)
    {
        $routeName = $this->getRouteName($request); // Return "news"
        $actionName = $this->getActionName($request); // Return "indexAction"
        $bundleName = $this->getBundleName(); // Return "AcmeBlogBundle"
        $data = [
            'data' => [
                'news' => [
                    [
                        'title' => 'Lorem ipsum'
                    ]
                ]
            ]
        ];

        //to return JSON
        return $this->wsResponse($data, 200, [], AbstractController::WS_RESPONSE_JSON);

        //to return XML
        return $this->wsResponse($data, 200, [], AbstractController::WS_RESPONSE_XML);
    }

}

Doctrine ORM entities

Name Type Description Address
IdTrait Trait Create the primary key integer field Mero\Bundle\BaseBundle\Entity\Field\IdTrait
UuidTrait Trait Create the primary key UUID field Mero\Bundle\BaseBundle\Entity\Field\UuidTrait
CreatedTrait Trait Create field to store the creation date Mero\Bundle\BaseBundle\Entity\Field\CreatedTrait
ModifiedTrait Trait Create field to store the date of last change Mero\Bundle\BaseBundle\Entity\Field\ModifiedTrait
AbstractEntity Abstract Class Classic entity superclass using integer identifier Mero\Bundle\BaseBundle\Entity\AbstractEntity
AbstractEntityWithUuid Abstract Class Entity superclass using UUID identifier Mero\Bundle\BaseBundle\Entity\AbstractEntityWithUuid

Usage example with AbstractEntity:

namespace Acme\Bundle\BlogBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Mero\Bundle\BaseBundle\Entity\AbstractEntity;

/**
 * @ORM\Entity()
 * @ORM\Table(name="post")
 */
class Post extends AbstractEntity
{
    // Entity class with IdTrait, CreatedTrait and ModifiedTrait implemented
}

Usage example with AbstractEntityWithUuid:

namespace Acme\Bundle\BlogBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Mero\Bundle\BaseBundle\Entity\AbstractEntityWithUuid;

/**
 * @ORM\Entity()
 * @ORM\Table(name="post")
 */
class Post extends AbstractEntityWithUuid
{
    // Entity class with UuidTrait, CreatedTrait and ModifiedTrait implemented
}

Usage example with Traits:

namespace Acme\Bundle\BlogBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Mero\Bundle\BaseBundle\Entity\IdTrait;

/**
 * @ORM\Entity()
 * @ORM\Table(name="post")
 */
class Post
{
    use IdTrait;
}

Twig extensions

Country

Gets name of the country based on the ISO 3166-1 alpha 2. Example: entity.getCountry() is a value generated by the type of form country., (*5)

{# Returns the country name in the server language #}
{{ entity.getCountry()|country() }}

{# Returns the country name in english #}
{{ entity.getCountry()|country('en_US') }}

{# Returns the country name in portuguese #}
{{ entity.getCountry()|country('pt_BR') }}

Language

Gets name of the language based on the unicode language identifier. Example: entity.getLanguage() is a value generated by the type of form language., (*6)

{# Returns the language name in the server language #}
{{ entity.getLanguage()|language() }}

{# Returns the language name in english #}
{{ entity.getLanguage()|language('en_US') }}

{# Returns the language name in portuguese #}
{{ entity.getLanguage()|language('pt_BR') }}

Helpers

className

Gets name of the class. This helper was added to facilitate applications using PHP 5.4. Use of this feature is discouraged if you are using PHP 5.5 or above due to the native implementation added in the language., (*7)

namespace Acme\Bundle\BlogBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Mero\Bundle\BaseBundle\Helper\ClassNameTrait;

/**
 * @ORM\Entity()
 * @ORM\Table(name="post")
 */
class Post
{
    use ClassNameTrait;
}

Post::className(); // Return "Post" using ClassNameTrait for PHP 5.4
Post::class // Return "Post" if you are using PHP 5.5 or above

The Versions

03/06 2017

dev-master

9999999-dev https://github.com/merorafael/MeroBaseBundle

Symfony Bundle with additional features.

  Sources   Download

MIT

The Requires

 

The Development Requires

symfony base sf mero

29/05 2017

2.3.0

2.3.0.0 https://github.com/merorafael/MeroBaseBundle

Bundle with additional features for Symfony.

  Sources   Download

MIT

The Requires

  • php >=5.4.9
  • ext-intl *

 

The Development Requires

symfony base sf mero

23/01 2016

1.2.5

1.2.5.0 https://github.com/merorafael/MeroBaseBundle

Bundle base to accelerate creation of basic resources.

  Sources   Download

MIT

The Requires

 

The Development Requires

symfony2 doctrine base mero

15/07 2015
03/07 2015
02/07 2015
01/07 2015
30/06 2015
12/06 2015

2.0.0alpha1

2.0.0.0-alpha1 https://github.com/merorafael/MeroBaseBundle

Bundle base to accelerate creation of basic resources.

  Sources   Download

MIT

The Requires

 

sf2 symfony base sf mero

27/05 2015

1.2.0

1.2.0.0 https://github.com/merorafael/MeroBaseBundle

Bundle base to accelerate creation of basic resources.

  Sources   Download

MIT

The Requires

 

symfony2 doctrine base mero

19/05 2015

1.1.2

1.1.2.0 https://github.com/merorafael/MeroBaseBundle

Bundle base to accelerate creation of basic resources.

  Sources   Download

MIT

The Requires

 

symfony2 doctrine base mero

18/05 2015

1.1.1

1.1.1.0 https://github.com/merorafael/MeroBaseBundle

Bundle base to accelerate creation of basic resources.

  Sources   Download

MIT

The Requires

 

symfony2 doctrine base mero

20/04 2015

1.1.0

1.1.0.0 https://github.com/merorafael/MeroBaseBundle

Bundle base to accelerate creation of basic resources.

  Sources   Download

MIT

The Requires

 

symfony2 doctrine base mero

19/03 2015

1.0.2

1.0.2.0 https://github.com/merorafael/MeroBaseBundle

Bundle base to accelerate creation of basic resources.

  Sources   Download

MIT

The Requires

 

symfony2 doctrine base mero

04/03 2015

1.0.1

1.0.1.0 https://github.com/merorafael/MeroBaseBundle

Bundle base to accelerate creation of basic resources.

  Sources   Download

MIT

The Requires

 

symfony2 doctrine base mero

24/02 2015

1.0.0

1.0.0.0 https://github.com/merorafael/MeroBaseBundle

Bundle base to accelerate creation of basic resources.

  Sources   Download

MIT

The Requires

 

symfony2 doctrine base mero