PHP code example of paymaxi / fractal-bundle

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

    

paymaxi / fractal-bundle example snippets


public function registerBundles()
{
    return [
        // ...
        new Paymaxi\FractalBundle\PaymaxiFractalBundle(),
    ];
}

class UserTransformer extends TransformerAbstract
{
    private $authorizationCheker;
    
    public function __construct(AuthorizationChecker $authorizationCheker)
    {
        $this->authorizationCheker = $authorizationCheker;
    }
    
    public function transform(User $user)
    {
        $data = [
            'id' => $user->id(),
            'name' => $user->name(),
        ];
        
        if ($this->authorizationChecker->isGranted(UserVoter::SEE_EMAIL, $user)) {
            $data['email'] = $user->email();
        }
        
        return $data;
    }
}

$resource = new Collection($users, 'app.transformer.user');

public function n $this->collection($user->friends(), 'app.transformer.user');
}