2017 © Pedro Peláez
 

symfony-bundle static-entity-bundle

Add Symfony3 ParamConverter and FormType to StaticEntity

image

byscripts/static-entity-bundle

Add Symfony3 ParamConverter and FormType to StaticEntity

  • Wednesday, April 13, 2016
  • by Byscripts
  • Repository
  • 1 Watchers
  • 0 Stars
  • 280 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 10 Versions
  • 0 % Grown

The README.md

Byscripts Static Entity Bundle

This bundle brings ParamConverter and FormType supports to Symfony 3 and Symfony 4 for the StaticEntity library., (*1)

If you just need to use StaticEntity, and don't need the FormType and ParamConverter support, then this bundle is NOT required., (*2)

You can use StaticEntity in your project like any other library., (*3)

This 4.x branch supports Symfony 3 and Symfony 4, (*4)

Use branch 3.x for SymfonyFrameworkBundle 3.x (Used by Symfony 2.4+), (*5)

For support of SensioFrameworkBundle 2.x (Used by Symfony 2.3), use the 1.x branch, (*6)

Installation

Add the package in your composer.json

At command line, run composer require byscripts/static-entity-bundle:~4.0, (*7)

Enable the Bundle

Symfony 3

Add Byscripts\Bundle\StaticEntityBundle\ByscriptsStaticEntityBundle to the app/AppKernel.php file., (*8)

Symfony 4

Add Byscripts\Bundle\StaticEntityBundle\ByscriptsStaticEntityBundle::class => ['all' => true] to the config/bundles.php file., (*9)

Usage

Create a static entity

First, create a static entity on your project (for example, in src/AppBundle/StaticEntity), (*10)

<?php

namespace AppBundle\StaticEntity;

use Byscripts\StaticEntity\StaticEntity;

class Civility extends StaticEntity
{
    private $name;
    private $shortName;

    public static function getDataSet()
    {
        return array(
            'mr' => array('name' => 'Mister', 'shortName' => 'Mr'),
            'mrs' => array('name' => 'Misses', 'shortName' => 'Mrs'),
        );
    }
}

For more details on usage of Static Entities, look at StaticEntity README.md, (*11)

Use the FormType

$builder->add('civility', StaticEntityType, $parameters);

List of parameters

| class | required | FQCN of the static entity | null | | function | optional | The function to use to get SE instances | getAll |, (*12)

StaticEntityType extends the native ChoiceType and can use any of its options., (*13)

Use the ParamConverter

class MyController
{
    public function myAction(Civility $civility)
    {
        $name = $civility->getName();
    }
}

The Versions