PHP code example of falbar / trait-adapter

1. Go to this page and download the library: Download falbar/trait-adapter 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/ */

    

falbar / trait-adapter example snippets


$oExampleAdapter = ExampleAdapter::make();

$oExampleAdapter = new ExampleAdapter();

 namespace App\Classes;

use Akbsit\TraitAdapter\AdapterTrait;

/**
 * Class ExampleAdapter
 * @package App\Classes
 */
class ExampleAdapter
{
    use AdapterTrait;

    protected array $arMappingList = [
        'id',
        'name',
    ];

    /* @var int */
    public $id;

    /* @var string */
    public $name;
}

$oExampleAdapter = ExampleAdapter::make()
    ->create([
        'id'   => 10,
        'name' => 'string',
    ]);

 namespace App\Classes;

use Akbsit\TraitAdapter\AdapterTrait;

/**
 * Class ExampleAdapter
 * @package App\Classes
 */
class ExampleAdapter
{
    use AdapterTrait;

    protected array $arMappingList = [
        'id',
        'name',
    ];

    /* @var int */
    public $id;

    /* @var string */
    public $name;

    /* @return void */
    protected function setNameAttribute(): void
    {
        $this->name = $this->name . '_new_value';
    }
}

$oExampleAdapter = ExampleAdapter::make()
    ->create([
        'id'   => 10,
        'name' => 'string',
    ]);

 namespace App\Classes;

use Akbsit\TraitAdapter\AdapterTrait;

/**
 * Class ExampleAdapter
 * @package App\Classes
 */
class ExampleAdapter
{
    use AdapterTrait;

    protected array $arMappingList = [
        'id'   => 'external_id',
        'name' => 'external_name',
    ];

    /* @var int */
    public $id;

    /* @var string */
    public $name;
}

$oExampleAdapter = ExampleAdapter::make()
    ->create([
        'external_id'   => 13,
        'external_name' => 'external',
    ]);

 namespace App\Classes;

use Akbsit\TraitAdapter\AdapterTrait;

/**
 * Class ExampleAdapter
 * @package App\Classes
 */
class ExampleAdapter
{
    use AdapterTrait;

    protected array $arMappingList = [
        'id',
        'name',
    ];

    /* @var int */
    public $id;

    /* @var string */
    public $name;
}

$oExampleAdapter = ExampleAdapter::make()
    ->createCollection([
        ['id' => 1, 'name' => 'string_1'],
        ['id' => 2, 'name' => 'string_2'],
    ]);