PHP code example of aol / transformers

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

    

aol / transformers example snippets




$post = ['Id' => '5', 'Title' => 'Awesome Post!', 'post_tags' => '["awesome"]'];

$transformer = new \Aol\Transformers\Transformer;
$transformer->define('id', 'Id', 'intval', 'strval');
$transformer->define('title', 'Title');
$transformer->define('tags', 'post_tags', 'json_decode', 'json_encode');

$post = $transformer->toApp($post);
// ['id' => 5, 'title' => 'Awesome Post!', 'tags' => ['awesome']];

public function define($app_name, $ext_name, callable $app_func = null, callable $ext_func, $app_args = [], $ext_args = []);



class Post extends \Aol\Transformers\Transformer
{
	public function __construct()
	{
		$this->define('id', 'Id', 'intval', 'strval');
		$this->define('title', 'Title');
		$this->define('tags', 'post_tags', 'json_decode', 'json_encode');
	}
}



class Post extends \Aol\Transformers\Transformer
{
	use \Aol\Transformers\Utilities\MysqlTrait,
		\Aol\Transformers\Utilities\UtilityTrait;
		
	public function __construct()
	{
		$this->defineId('id', 'Id');
		$this->define('title', 'Title');
		$this->defineJson('tags', 'post_tags');
	}
}