-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] Try to use DataProvider instead of auto-binding with Doctrine a…
…nnotat… (#118) * Try to use DataProvider instead of auto-binding with Doctrine annotations * fix partially #117
- Loading branch information
Showing
3 changed files
with
97 additions
and
0 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,35 @@ | ||
<?php | ||
namespace App\DataProvider; | ||
|
||
|
||
use ApiPlatform\Core\DataProvider\CollectionDataProviderInterface; | ||
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; | ||
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; | ||
use App\Entity\Ping; | ||
|
||
class PingDataProvider implements ItemDataProviderInterface, CollectionDataProviderInterface, RestrictedDataProviderInterface | ||
{ | ||
public function supports(string $resourceClass, string $operationName = null, array $context = []): bool | ||
{ | ||
return Ping::class === $resourceClass; | ||
} | ||
|
||
public function getItem(string $resourceClass, $id, string $operationName = null, array $context = []) | ||
{ | ||
$pong = new Ping(); | ||
$pong->setId(1); | ||
|
||
return $pong; | ||
} | ||
|
||
public function getCollection(string $resourceClass, string $operationName = null, array $context = []) | ||
{ | ||
$pongOne = new Ping(); | ||
$pongOne->setId(1); | ||
$pongTwo = new Ping(); | ||
$pongTwo->setId(2); | ||
|
||
return [$pongOne, $pongTwo]; | ||
} | ||
|
||
} |
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\ApiProperty; | ||
use ApiPlatform\Core\Annotation\ApiResource; | ||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
/** | ||
* Class Ping | ||
* @ApiResource( | ||
* itemOperations={ | ||
* "get"={"method"="GET"} | ||
* }, | ||
* collectionOperations={ | ||
* "get"={"method"="GET"} | ||
* } | ||
* ) | ||
* @package App\Ping | ||
*/ | ||
class Ping | ||
{ | ||
/** | ||
* @Assert\Uuid() | ||
* @ApiProperty(identifier=true) | ||
* @var int | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $pong = 'pong'; | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getId(): int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* @param int $id | ||
* @return Ping | ||
*/ | ||
public function setId(int $id): Ping | ||
{ | ||
$this->id = $id; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getPong() | ||
{ | ||
return $this->pong; | ||
} | ||
} |