2017 © Pedro Peláez
 

symfony-bundle binding-bundle

This Bundle provides a binding from array to Entity with Symfony

image

sonofwinter/binding-bundle

This Bundle provides a binding from array to Entity with Symfony

  • Tuesday, July 31, 2018
  • by SonOfWinter
  • Repository
  • 1 Watchers
  • 0 Stars
  • 12 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 100 % Grown

The README.md

Installation

Open a command console, enter your project directory and execute:, (*1)

$ composer require sonofwinter/binding-bundle

Usage

Define binding properties in your entity, (*2)

For v0.3.0 and above

    /**
     * @var string
     * @Binding(key="firstname")
     */
    private $firstname;

    /**
     * @var string
     * @Binding(key="lastname", setter="setOtherName")
     */
    private $lastname;

    /**
     * @var integer
     * @Binding(key="age", type="integer")
     */
    private $age;

    /**
     * @var string
     * @Binding()
     */
    private $userEmail;

For v0.2.0 and below

    /**
     * @var string
     * @Binding(name="firstname")
     */
    private $firstname;

    /**
     * @var string
     * @Binding(name="lastname", setter="setOtherName")
     */
    private $lastname;

    /**
     * @var integer
     * @Binding(name="age", type="integer")
     */
    private $age;

    /** 
     * @var string
     * @Binding(name="userEmail")
     */
    private $userEmail;

You must defined the key|name property. It's the array value's key., (*3)

The setter property is used if you want to use another setter., (*4)

The type property is used if you want to make a type check. A BinderTypeException is throws if the type doens't correspond., (*5)

Use Binder service for bind an array to entity, (*6)

    public function __construct(BinderInterface $binder)
    {
        $this->binder = $binder;
    }

    function bind(BindableEntity $be, array $data): BindableEntity
    {
        // $data = ['lastname' => 'Doe', 'firstname' => 'John', 'age' => 20, 'userEmail' => 'some.email@mail.com'];
        $this->binder->bind($be, $data);
        return $be;
    }

New in v0.4 inclusion and exclusion

    public function bind(&$object, array $params = [], array $include = [], array $exclude = [])

$include is a key array required in $params, if one or more keys are missing, an exception is thrown, (*7)

$exclude is a key array ignored in $params. No exception was thrown is a key is present., (*8)

new in v0.5 min and max

    /**
     * @var integer
     * @Binding(key="age", type="integer", min=0, max=100)
     */
    private $age;

The min and max value check if the value is in range defined by the two properties., (*9)

If not, a specific exception was thrown, (*10)

Works with number (int/float), string (length) and array (count), (*11)

new in v0.6 child binder

    /** 
     * @var Test
     * @Binding(type="App\Entity\Test")
     */
    private $test;

A child entity can be binding when the type is set with the entity namespace., (*12)

The getter is use to get the sub entity. If the sub entity is null, it try to create him (without parameter), if fail the binder skip sub entity. So if the constructor need parameters, the sub entity must be defined before the binder action., (*13)

Exemple of data :, (*14)

$data = [
    'lastname' => 'Doe', 
    'firstname' => 'John', 
    'age' => 20, 
    'userEmail' => 'some.email@mail.com',
    'test' => [
        'testProps1' => 'value',
        'testProps2' => 'value'
    ]
];

new in v0.7 Nullable

    /** 
     * @var Test
     * @Binding(nullable=true)
     */
    private $test;

The nullable property define if a null value can be set to entity's property. The property default value is false., (*15)

V0.7.1 update

Update Symfony minimum version 4.0 -> 4.1, (*16)

V0.8.0 update

Update Symfony minimum version 4.1 -> 4.3 || 5.0, (*17)

v0.9.0 update

Adds attributes and increases minimum versions : - Symfony minimum version 5.0 - PHP minimum version 8.0, (*18)

So now, you can use attribute instead of annotation., (*19)

    #[Binding(key: "lastname", setter: "setLastname", type: "string", min: 2, max: 255)]
    private string $lastname = '';

You have to add this configuration to use it :, (*20)

    sow_binding.binding_method: attribute

You can also override Binder attribute with this configuration :, (*21)

    sow_binding.attribute_class_name: 'SOW\BindingBundle\Attribute\Binding'

The Versions

31/07 2018

dev-master

9999999-dev

This Bundle provides a binding from array to Entity with Symfony

  Sources   Download

MIT

The Requires

 

The Development Requires

by Thomas Leduc

09/07 2018

v0.3.2

0.3.2.0

This Bundle provides a binding from array to Entity with Symfony

  Sources   Download

MIT

The Requires

 

The Development Requires

by Thomas Leduc

26/06 2018

v0.3.1

0.3.1.0

This Bundle provides a binding from array to Entity with Symfony

  Sources   Download

MIT

The Requires

 

The Development Requires

by Thomas Leduc

07/06 2018

v0.3.0

0.3.0.0

This Bundle provides a binding from array to Entity with Symfony

  Sources   Download

MIT

The Requires

 

The Development Requires

by Thomas Leduc

13/05 2018

v0.2.0

0.2.0.0

This Bundle provides a binding from array to Entity with Symfony

  Sources   Download

MIT

The Requires

 

The Development Requires

by Thomas Leduc

09/04 2018

v0.1.2

0.1.2.0

This Bundle provides a binding from array to Entity with Symfony

  Sources   Download

MIT

The Requires

 

The Development Requires

by Thomas Leduc

09/04 2018

v0.1.1

0.1.1.0

This Bundle provides a binding from array to Entity with Symfony

  Sources   Download

MIT

The Requires

 

The Development Requires

by Thomas Leduc

01/02 2018

v0.1.0

0.1.0.0

This Bundle provides a binding from array to Entity with Symfony

  Sources   Download

MIT

The Requires

 

The Development Requires

by Thomas Leduc