PHP code example of bobbysciacchitano / manuel

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

    

bobbysciacchitano / manuel example snippets


 namespace App\Transformer;

use TheObject;
use Manuel\Transformer\TransformerAbstract;

class MyTransformer extends TransformerAbstract {

    /**
     * @var string
     */
    protected $type = 'customer';

    /**
     * Transform object properties.
     *
     * @param TheObject $myObject
     * @return array
     */
    public function transform(TheObject $myObject)
    {
        return array(
            'id'           => (int) $myObject->id,
            'name'         => $myObject->name,
            'email'        => $myObject->email,
            'active'       => (bool) $myObject->is_active
        );
    }

    /**
     * Define other resources to be 



use Manuel\Manager;
use Manuel\Resource;
use App\Transformer;

$manager = new Manager(new JsonAPISerializer);

// Serialize a object
$translated = $manager->translate(new Resource\Item($data, new Transfomer\MyTransformer));

// Serialize an array or collection of objects
$translated = $manager->translate(new Resource\Collection($array, new Transfomer\MyTransformer));

    /**
     * Define other resources to be    */
    public function resources(TheObject $myObject)
    {
        $this->addResource('test_item', new Item($data->item, new Transformer));

        $this->addResource('test_collection', new Collection($data->items, new Transformer));
    }

    /**
     * Define other resources to be    */
    public function resources(TheObject $myObject)
    {
        $this->addResource('test_item', new Item($data->item, new Transformer), true);

        $this->addResource('test_collection', new Collection($data->items, new Transformer), true);
    }