-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FurnitureDataProvider using collectionDataProvider
- Loading branch information
Showing
6 changed files
with
159 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
App\Entity\Furniture: | ||
furniture_{1..1000}: | ||
name: <word(10, 700)> | ||
isPublished: '<numberBetween(0, 1)>' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace App\DataProvider; | ||
|
||
use ApiPlatform\Core\DataProvider\CollectionDataProviderInterface; | ||
use ApiPlatform\Core\DataProvider\ContextAwareCollectionDataProviderInterface; | ||
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; | ||
use App\Entity\Furniture; | ||
|
||
class FurnitureDataProvider implements ContextAwareCollectionDataProviderInterface, RestrictedDataProviderInterface | ||
{ | ||
private $collectionDataProvider; | ||
|
||
public function __construct(CollectionDataProviderInterface $collectionDataProvider) | ||
{ | ||
$this->collectionDataProvider = $collectionDataProvider; | ||
} | ||
|
||
public function supports(string $resourceClass, string $operationName = null, array $context = []): bool | ||
{ | ||
return $resourceClass === Furniture::class; | ||
} | ||
|
||
public function getCollection(string $resourceClass, string $operationName = null, array $context = []) | ||
{ | ||
return $this->collectionDataProvider->getCollection($resourceClass, $operationName, $context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace App\Entity; | ||
|
||
use ApiPlatform\Core\Annotation\ApiResource; | ||
use App\Repository\FurnitureRepository; | ||
use Doctrine\ORM\Mapping as ORM; | ||
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter; | ||
|
||
/** | ||
* @ApiResource() | ||
* @ORM\Entity(repositoryClass=FurnitureRepository::class) | ||
*/ | ||
class Furniture | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\GeneratedValue | ||
* @ORM\Column(type="integer") | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* @ORM\Column(type="string", length=255) | ||
*/ | ||
private $name; | ||
|
||
/** | ||
* @ORM\Column(type="boolean") | ||
*/ | ||
private $isPublished; | ||
|
||
public function getId(): ?int | ||
{ | ||
return $this->id; | ||
} | ||
public function getName(): ?string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function setName(string $name): self | ||
{ | ||
$this->name = $name; | ||
|
||
return $this; | ||
} | ||
|
||
public function getIsPublished(): ?bool | ||
{ | ||
return $this->isPublished; | ||
} | ||
|
||
public function setIsPublished(bool $isPublished): self | ||
{ | ||
$this->isPublished = $isPublished; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace App\Repository; | ||
|
||
use App\Entity\Furniture; | ||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | ||
use Doctrine\Persistence\ManagerRegistry; | ||
|
||
/** | ||
* @method Furniture|null find($id, $lockMode = null, $lockVersion = null) | ||
* @method Furniture|null findOneBy(array $criteria, array $orderBy = null) | ||
* @method Furniture[] findAll() | ||
* @method Furniture[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) | ||
*/ | ||
class FurnitureRepository extends ServiceEntityRepository | ||
{ | ||
public function __construct(ManagerRegistry $registry) | ||
{ | ||
parent::__construct($registry, Furniture::class); | ||
} | ||
|
||
// /** | ||
// * @return Furniture[] Returns an array of Furniture objects | ||
// */ | ||
/* | ||
public function findByExampleField($value) | ||
{ | ||
return $this->createQueryBuilder('f') | ||
->andWhere('f.exampleField = :val') | ||
->setParameter('val', $value) | ||
->orderBy('f.id', 'ASC') | ||
->setMaxResults(10) | ||
->getQuery() | ||
->getResult() | ||
; | ||
} | ||
*/ | ||
|
||
/* | ||
public function findOneBySomeField($value): ?Furniture | ||
{ | ||
return $this->createQueryBuilder('f') | ||
->andWhere('f.exampleField = :val') | ||
->setParameter('val', $value) | ||
->getQuery() | ||
->getOneOrNullResult() | ||
; | ||
} | ||
*/ | ||
} |