1000 search results

31 lines | src/State/DragonTreasureStateProcessor.php
// ... lines 1 - 10
#[AsDecorator('api_platform.doctrine.orm.state.persist_processor')]
class DragonTreasureStateProcessor implements ProcessorInterface
{
// ... lines 14 - 17
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): void
{
if ($data instanceof DragonTreasure && $data->getOwner() === null && $this->security->getUser()) {
$data->setOwner($this->security->getUser());
}
// ... lines 23 - 28
}
}
See Code Block in Script
Love API-Platform, using it as much as possible now. I also use the Symfony proxy, to make my domains easier to work with (symfony proxy:domain:add my-project, then use https://my-project.wip). Can you suggest how to call fetch with a…
Tac-Tacelosky
Tac-Tacelosky
Read Full Comment
79 lines | composer.json
{
// ... lines 2 - 3
"require": {
// ... lines 5 - 7
"api-platform/core": "^2.1",
// ... lines 9 - 16
"symfony/asset": "5.1.*",
"symfony/console": "5.1.*",
"symfony/dotenv": "5.1.*",
"symfony/expression-language": "5.1.*",
"symfony/flex": "^1.1",
"symfony/framework-bundle": "5.1.*",
"symfony/http-client": "5.1.*",
"symfony/monolog-bundle": "^3.4",
"symfony/security-bundle": "5.1.*",
"symfony/twig-bundle": "5.1.*",
"symfony/validator": "5.1.*",
"symfony/webpack-encore-bundle": "^1.6",
"symfony/yaml": "5.1.*",
// ... line 30
},
// ... lines 32 - 71
"extra": {
"symfony": {
// ... line 74
"require": "5.1.*"
}
}
}
See Code Block in Script
What api-platform version is this podcast about?
Emmanuel B.
Emmanuel B.
Read Full Comment
166 lines | src/Entity/DragonTreasure.php
// ... lines 1 - 4
use ApiPlatform\Doctrine\Orm\Filter\BooleanFilter;
use ApiPlatform\Metadata\ApiFilter;
// ... lines 7 - 38
#[ApiFilter(BooleanFilter::class, properties: ['isPublished'])]
class DragonTreasure
{
// ... lines 42 - 164
}
See Code Block in Script
232 lines | src/Entity/DragonTreasure.php
// ... lines 1 - 11
use ApiPlatform\Metadata\Link;
// ... lines 13 - 55
#[ApiResource(
uriTemplate: '/users/{user_id}/treasures.{_format}',
shortName: 'Treasure',
operations: [new GetCollection()],
uriVariables: [
'user_id' => new Link(
// ... lines 62 - 63
),
],
)]
// ... lines 67 - 70
class DragonTreasure
{
// ... lines 73 - 230
}
See Code Block in Script
232 lines | src/Entity/DragonTreasure.php
// ... lines 1 - 11
use ApiPlatform\Metadata\Link;
// ... lines 13 - 55
#[ApiResource(
uriTemplate: '/users/{user_id}/treasures.{_format}',
shortName: 'Treasure',
operations: [new GetCollection()],
uriVariables: [
'user_id' => new Link(
// ... line 62
fromClass: User::class,
),
],
)]
// ... lines 67 - 70
class DragonTreasure
{
// ... lines 73 - 230
}
See Code Block in Script
232 lines | src/Entity/DragonTreasure.php
// ... lines 1 - 11
use ApiPlatform\Metadata\Link;
// ... lines 13 - 55
#[ApiResource(
uriTemplate: '/users/{user_id}/treasures.{_format}',
shortName: 'Treasure',
operations: [new GetCollection()],
uriVariables: [
'user_id' => new Link(
fromProperty: 'dragonTreasures',
fromClass: User::class,
),
],
)]
// ... lines 67 - 70
class DragonTreasure
{
// ... lines 73 - 230
}
See Code Block in Script
235 lines | src/Entity/DragonTreasure.php
// ... lines 1 - 11
use ApiPlatform\Metadata\Link;
// ... lines 13 - 55
#[ApiResource(
uriTemplate: '/users/{user_id}/treasures.{_format}',
shortName: 'Treasure',
operations: [new GetCollection()],
uriVariables: [
'user_id' => new Link(
fromProperty: 'dragonTreasures',
fromClass: User::class,
),
],
normalizationContext: [
'groups' => ['treasure:read'],
],
)]
// ... lines 70 - 73
class DragonTreasure
{
// ... lines 76 - 233
}
See Code Block in Script
189 lines | src/Entity/User.php
// ... lines 1 - 7
use ApiPlatform\Metadata\Link;
// ... lines 9 - 24
#[ApiResource(
uriTemplate: '/treasures/{treasure_id}/owner.{_format}',
// ... line 27
uriVariables: [
'treasure_id' => new Link(
fromProperty: 'owner',
fromClass: DragonTreasure::class,
),
],
// ... line 34
)]
// ... lines 36 - 38
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
// ... lines 41 - 187
}
See Code Block in Script
189 lines | src/Entity/User.php
// ... lines 1 - 6
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\Link;
// ... lines 9 - 24
#[ApiResource(
uriTemplate: '/treasures/{treasure_id}/owner.{_format}',
operations: [new Get()],
uriVariables: [
'treasure_id' => new Link(
fromProperty: 'owner',
fromClass: DragonTreasure::class,
),
],
normalizationContext: ['groups' => ['user:read']],
)]
// ... lines 36 - 38
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
// ... lines 41 - 187
}
See Code Block in Script
68 lines | src/ApiResource/UserApi.php
// ... lines 1 - 9
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
// ... lines 15 - 20
#[ApiResource(
// ... line 22
operations: [
new Get(),
new GetCollection(),
new Post(
// ... line 27
),
new Patch(),
new Delete(),
],
// ... lines 32 - 35
)]
// ... lines 37 - 39
class UserApi
{
// ... lines 42 - 66
}
See Code Block in Script
68 lines | src/ApiResource/UserApi.php
// ... lines 1 - 9
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
// ... lines 15 - 20
#[ApiResource(
// ... line 22
operations: [
new Get(),
new GetCollection(),
new Post(
validationContext: ['groups' => ['Default', 'postValidation']],
),
new Patch(),
new Delete(),
],
// ... lines 32 - 35
)]
// ... lines 37 - 39
class UserApi
{
// ... lines 42 - 66
}
See Code Block in Script
46 lines | src/ApiResource/UserApi.php
// ... lines 1 - 7
use ApiPlatform\Metadata\ApiProperty;
// ... lines 9 - 24
class UserApi
{
// ... lines 27 - 35
#[ApiProperty(readable: false)]
public ?string $password = null;
// ... lines 38 - 44
}
See Code Block in Script
16 lines | src/ApiResource/UserApi.php
// ... lines 1 - 4
use ApiPlatform\Doctrine\Orm\State\CollectionProvider;
// ... lines 6 - 7
#[ApiResource(
shortName: 'User',
provider: CollectionProvider::class,
)]
class UserApi
{
public ?int $id = null;
}
See Code Block in Script
19 lines | src/ApiResource/UserApi.php
// ... lines 1 - 4
use ApiPlatform\Doctrine\Orm\State\CollectionProvider;
use ApiPlatform\Doctrine\Orm\State\Options;
// ... line 7
use App\Entity\User;
#[ApiResource(
shortName: 'User',
provider: CollectionProvider::class,
stateOptions: new Options(entityClass: User::class),
)]
class UserApi
{
public ?int $id = null;
}
See Code Block in Script
33 lines | src/ApiResource/UserApi.php
// ... lines 1 - 4
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
// ... line 6
use ApiPlatform\Metadata\ApiFilter;
// ... lines 8 - 16
#[ApiFilter(SearchFilter::class, properties: [
'username' => 'partial',
])]
class UserApi
{
// ... lines 22 - 31
}
See Code Block in Script
66 lines | src/State/DailyQuestStateProvider.php
// ... lines 1 - 6
use ApiPlatform\State\Pagination\TraversablePaginator;
// ... lines 8 - 13
class DailyQuestStateProvider implements ProviderInterface
{
// ... lines 16 - 21
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
{
if ($operation instanceof CollectionOperationInterface) {
$quests = $this->createQuests();
return new TraversablePaginator(
new \ArrayIterator($quests),
1,
10,
count($quests),
);
}
// ... lines 34 - 37
}
// ... lines 39 - 64
}
See Code Block in Script
80 lines | src/State/DailyQuestStateProvider.php
// ... lines 1 - 6
use ApiPlatform\State\Pagination\Pagination;
// ... lines 8 - 14
class DailyQuestStateProvider implements ProviderInterface
{
public function __construct(
private DragonTreasureRepository $treasureRepository,
private Pagination $pagination,
)
{
}
// ... lines 23 - 78
}
See Code Block in Script
80 lines | src/State/DailyQuestStateProvider.php
// ... lines 1 - 6
use ApiPlatform\State\Pagination\Pagination;
// ... lines 8 - 14
class DailyQuestStateProvider implements ProviderInterface
{
public function __construct(
private DragonTreasureRepository $treasureRepository,
private Pagination $pagination,
)
{
}
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
{
if ($operation instanceof CollectionOperationInterface) {
$currentPage = $this->pagination->getPage($context);
$itemsPerPage = $this->pagination->getLimit($operation, $context);
$offset = $this->pagination->getOffset($operation, $context);
$totalItems = $this->countTotalQuests();
dd($currentPage, $itemsPerPage, $offset, $totalItems);
// ... lines 32 - 40
}
// ... lines 42 - 45
}
// ... lines 47 - 78
}
See Code Block in Script