PHP code example of sonofwinter / binding-bundle

1. Go to this page and download the library: Download sonofwinter/binding-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sonofwinter / binding-bundle example snippets


    /**
     * @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;

    /**
     * @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;

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

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

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

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

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

$data = [
    'lastname' => 'Doe', 
    'firstname' => 'John', 
    'age' => 20, 
    'userEmail' => '[email protected]',
    'test' => [
        'testProps1' => 'value',
        'testProps2' => 'value'
    ]
];

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

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