PHP code example of giadc / doctrine-json-api

1. Go to this page and download the library: Download giadc/doctrine-json-api 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/ */

    

giadc / doctrine-json-api example snippets


$entityReadService->findById('id123', $3', 'id456'], 'id', $yReadService->paginate($


namespace App\Bananas\Services;

use App\Common\Services\AbstractReadService;
use App\Bananas\Repositories\BananaRepositoryInterface as BananaRepo;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class RoleReadService extends AbstractReadService
{
    public function __construct(
        BananaRepo $bananaRepo
    ) {
        $this->initialize($bananaRepo, 'Banana');
    }



namespace App\Bananas\Filters;

use Giadc\DoctrineJsonApi\Filters\FilterManager;

/**
 * Class BananaFilters
 */
class BananaFilter extends FilterManager
{
    /**
     * @var array
     */
    protected $accepted = [
        'id'    => ['type' => 'id'],      // id must match exactly
        'name' => ['type' => 'keyword'], // keyword will match fuzzily
    ];
}


namespace App\Bananas\Repositories;

use App\Bananas\Banana;
use App\Bananas\Filters\BananaFilter;
use App\Bananas\Repositories\BananaRepositoryInterface;
use Doctrine\ORM\EntityManagerInterface as EntityManager;
use Giadc\DoctrineJsonApi\Interfaces\AbstractJsonApiRepositoryInterface as JsonApiInterface;
use Giadc\DoctrineJsonApi\Repositories\AbstractJsonApiDoctrineRepository as JsonApiRepository;

class RoleDoctrineRepository extends JsonApiRepository implements
JsonApiInterface,
RoleRepositoryInterface
{
    /** @var EntityManager */
    protected $em;

    /** @var string */
    protected $class;
    
    /** @var BananaFilter **/
    protected $filters;

    /**
     * Create a new BananaDoctrineRepository
     *
     * @param EntityManager $em
     * @param BananaFilters $filters
     * @return void
     */
    public function __construct(EntityManager $em, BananaFilter $filters)
    {
        $this->em      = $em;
        $this->class   = Role::class;
        $this->filters = $filters;
    }
}