-
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.
- Loading branch information
Showing
8 changed files
with
229 additions
and
7 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
App\Entity\Comment: | ||
comment_{1..1000}: | ||
author: <name()> | ||
content: <text()> |
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,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\DataProvider; | ||
|
||
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; | ||
use ApiPlatform\Core\DataProvider\SubresourceDataProviderInterface; | ||
use App\Entity\Comment; | ||
|
||
final class CommentSubresourceDataProvider implements SubresourceDataProviderInterface, RestrictedDataProviderInterface | ||
{ | ||
private $alreadyInvoked = false; | ||
private $subresourceDataProvider; | ||
|
||
public function __construct(SubresourceDataProviderInterface $subresourceDataProvider) | ||
{ | ||
$this->subresourceDataProvider = $subresourceDataProvider; | ||
} | ||
|
||
public function supports(string $resourceClass, string $operationName = null, array $context = []): bool | ||
{ | ||
return false === $this->alreadyInvoked && $resourceClass === Comment::class; | ||
} | ||
|
||
public function getSubresource(string $resourceClass, array $identifiers, array $context, string $operationName = null) | ||
{ | ||
$this->alreadyInvoked = true; | ||
|
||
return $this->subresourceDataProvider->getSubresource($resourceClass, $identifiers, $context, $operationName); | ||
} | ||
} |
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,77 @@ | ||
<?php | ||
|
||
namespace App\Entity; | ||
|
||
use ApiPlatform\Core\Annotation\ApiResource; | ||
use App\Repository\CommentRepository; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ApiResource() | ||
* @ORM\Entity(repositoryClass=CommentRepository::class) | ||
*/ | ||
class Comment | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\GeneratedValue | ||
* @ORM\Column(type="integer") | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* @ORM\Column(type="string", length=255) | ||
*/ | ||
private $author; | ||
|
||
/** | ||
* @ORM\Column(type="text") | ||
*/ | ||
private $content; | ||
|
||
/** | ||
* @ORM\ManyToOne(targetEntity=Movie::class, inversedBy="comments") | ||
*/ | ||
private $movie; | ||
|
||
public function getId(): ?int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getAuthor(): ?string | ||
{ | ||
return $this->author; | ||
} | ||
|
||
public function setAuthor(string $author): self | ||
{ | ||
$this->author = $author; | ||
|
||
return $this; | ||
} | ||
|
||
public function getContent(): ?string | ||
{ | ||
return $this->content; | ||
} | ||
|
||
public function setContent(string $content): self | ||
{ | ||
$this->content = $content; | ||
|
||
return $this; | ||
} | ||
|
||
public function getMovie(): ?Movie | ||
{ | ||
return $this->movie; | ||
} | ||
|
||
public function setMovie(?Movie $movie): self | ||
{ | ||
$this->movie = $movie; | ||
|
||
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
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\Comment; | ||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | ||
use Doctrine\Persistence\ManagerRegistry; | ||
|
||
/** | ||
* @method Comment|null find($id, $lockMode = null, $lockVersion = null) | ||
* @method Comment|null findOneBy(array $criteria, array $orderBy = null) | ||
* @method Comment[] findAll() | ||
* @method Comment[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) | ||
*/ | ||
class CommentRepository extends ServiceEntityRepository | ||
{ | ||
public function __construct(ManagerRegistry $registry) | ||
{ | ||
parent::__construct($registry, Comment::class); | ||
} | ||
|
||
// /** | ||
// * @return Comment[] Returns an array of Comment objects | ||
// */ | ||
/* | ||
public function findByExampleField($value) | ||
{ | ||
return $this->createQueryBuilder('c') | ||
->andWhere('c.exampleField = :val') | ||
->setParameter('val', $value) | ||
->orderBy('c.id', 'ASC') | ||
->setMaxResults(10) | ||
->getQuery() | ||
->getResult() | ||
; | ||
} | ||
*/ | ||
|
||
/* | ||
public function findOneBySomeField($value): ?Comment | ||
{ | ||
return $this->createQueryBuilder('c') | ||
->andWhere('c.exampleField = :val') | ||
->setParameter('val', $value) | ||
->getQuery() | ||
->getOneOrNullResult() | ||
; | ||
} | ||
*/ | ||
} |