PHP code example of dvasilenko / datamapper_tools

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

    

dvasilenko / datamapper_tools example snippets


use DataMapper\Tools\BaseDataMapper;

class MyDataMapper extends BaseDataMapper
{
    protected $rules = [
        'ruleCode' => [],
    ];
}
  

/**
 * Если необходимо проверить на XSD, привязка к ключу правила, значение путь к xsd файлу
 * @var array
 */
protected $xsd = [
    //'ruleCode' => '',
];

/**
 * Корневой XML документ
 * @var string
 */
protected $xml = '<?xml version="1.0" encoding="UTF-8"

use DataMapper\Tools\Contracts\ResolveInterface,
    DataMapper\Tools\Resolve\Base;

class Fio extends Base implements ResolveInterface
{
    public static function run(array $val, array $data)
    {
        $name = self::getValByKey($val['params']['name'], $data);
        $lastName = self::getValByKey($val['params']['lastName'], $data);

        return implode(' ', [$lastName, $name]);
    }
}

use MyDataMapper;

$data = [
    'client' => [
        'id' => 1,
        'name' => 'Имя',
        'lastName' => 'Фамилия',
        'dateBirth' => '2000-01-01',
        'gender' => 'man',
    ],
    'order' => [
        'id' => 1,
    ],
];

$uploadData = [
    'client' => $clientData,
    'order' => $orderData,           
];

$dataMapper = new MyDataMapper;
// Если нужен массив данных
$data = $dataMapper->getData('clientOrder', $uploadData);

$data = $dataMapper->getXmlString('clientOrders', $uploadData);