PHP code example of inlm / mappers

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

    

inlm / mappers example snippets

 php
$mapper = new PrefixMapper('prefix_');
$mapper = new PrefixMapper('prefix_', $fallbackMapper);
 php
$mapper = new PrefixMapper('prefix_');
echo $mapper->getTable('OrderItem'); // prints 'prefix_orderitem'

$mapper = new PrefixMapper('prefix_', new Inlm\Mappers\UnderScoreMapper);
echo $mapper->getTable('OrderItem'); // prints 'prefix_order_item'
 php
$mapper = new RowMapper;
$mapper = new RowMapper($fallbackMapper);
$mapper->registerFieldMapping($entity, $field, $fromDbValue, $toDbValue);
$mapper->registerFieldMapping(
	Model\Entity\Client::class,
	'website',
	function ($dbValue) {
		return new Website($dbValue);
	},
	function (Website $rowValue) {
		return $rowValue->getUrl();
	}
);


// multi column mapping
$mapper->registerMultiValueMapping(
	Model\OrderItem::class,
	'price',
	function (array $values, $rowField) {
		return new Price($values[$rowField . '_total'], $values[$rowField . '_currency']);
	},
	function (Price $price, $rowField) {
		return [
			$rowField . '_total' => $price->getPrice(),
			$rowField . '_currency' => $price->getCurrency(),
		];
	}
);
 php
$mapper->registerTypeField(Entities\Client::class, 'clientType');
 php
$fluent = $connection->select('*')->from('client');
$mapper->applyStiMapping($fluent, Entities\ClientCompany::class);
echo $fluent; // SELECT * FROM `client` WHERE `client`.`clientType` = 'company'