PHP code example of ac / model-traits

1. Go to this page and download the library: Download ac/model-traits 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/ */

    

ac / model-traits example snippets


use AC\ModelTraits\AutoGetterSetterTrait;

class MyModel
{
    use AutoGetterSetterTrait;

    private $id;
    protected $name;
    protected $age;

    public function __construct($id = null)
    {
        $this->id = $id;
    }
}

$m = new MyModel(5);
$m->setName('John');
$m->setAge(23);

echo $m->getId();       //5
echo $m->getName();     //John
echo $m->getAge();      //23

use AC\ModelTraits\AnnotatedGetterSetterTrait;
use AC\ModelTraits\Annotation as MT;

class MyModel
{
    use AnnotatedGetterSetterTrait;

    /**
     * @MT\Getter
     */
    private $id

    /**
     * @MT\GetterAndSetter
     */
    private $name;

    /**
     * @MT\GetterAndSetter
     */
    protected $age;
}

use AC\ModelTraits\GetterSetterTrait
use AC\ModelTraits\ArrayFactoryTrait;

class MyModel
{
    use ArrayFactoryTrait, GetterSetterTrait;

    private $id;
    protected $name;
    protected $description;
}

$m = MyModel::createFromArray([
    'id' => 5,
    'name' => 'John',
    'age' => 23
]);

echo $m->getId();       //5
echo $m->getName();     //John
echo $m->getAge();      //23