1. Go to this page and download the library: Download somnambulist/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/ */
somnambulist / fractal-bundle example snippets
use League\Fractal\TransformerAbstract;
class UserTransformer extends TransformerAbstract
{
public function __construct(private AuthorizationChecker $authorizationChecker)
{
}
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, UserTransformer::class);
public function n $this->collection($user->friends(), UserTransformer::class);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.