PHP code example of api-skeletons / laravel-hal-doctrine
1. Go to this page and download the library: Download api-skeletons/laravel-hal-doctrine 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/ */
api-skeletons / laravel-hal-doctrine example snippets
namespace App\HAL;
use ApiSkeletons\Laravel\HAL\HydratorManager as HALHydratorManager;
final class HydratorManager extends HALHydratorManager
{
public function __construct()
{
$this->classHydrators = [
// This wildcard entry is used as an example and may not be exactly what you need
'*' => \ApiSkeletons\Laravel\HAL\Doctrine\DoctrineHydrator::class,
];
}
}
use App\Hal\HydratorManager;
public function fetch(Entity\Artist $artist): array
{
return (new HydratorManager())->extract($artist)->toArray();
}
use ApiSkeletons\Doctrine\QueryBuilder\Filter\Applicator;
public function fetchAll(EntityManager $entityManager): array
{
$applicator = new Applicator($entityManager, Entity\Album::class);
$queryBuilder = $applicator($_REQUEST['filter']);
return (new HydratorManager())
->paginate('albums', collect($queryBuilder->getQuery()->getResult()))->toArray();
}