Skip to content

Commit a3576a0

Browse files
committed
Fix processing data without provider
1 parent 32fdd37 commit a3576a0

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

docs/processors.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ use Sylius\Resource\Model\ResourceInterface;
127127
final class BoardGameResource implements ResourceInterface
128128
```
129129

130-
Note that in this case, you can disable providing data.
130+
Note that in that kind of operation, you can disable providing data.
131131

132132
```php
133133
// src/BoardGameBlog/Infrastructure/Sylius/Resource/BoardGameResource.php
@@ -152,6 +152,38 @@ use Sylius\Resource\Model\ResourceInterface;
152152
final class BoardGameResource implements ResourceInterface
153153
```
154154

155+
But you will also need to adapt your processor.
156+
157+
```php
158+
// src/BoardGameBlog/Infrastructure/Sylius/State/Processor/DeleteBoardGameProcessor.php
159+
160+
namespace App\BoardGameBlog\Infrastructure\Sylius\State\Processor;
161+
162+
use Sylius\Resource\Context\Option\RequestOption;
163+
use Webmozart\Assert\Assert;
164+
165+
final class DeleteBoardGameProcessor implements ProcessorInterface
166+
{
167+
public function __construct(
168+
private CommandBusInterface $commandBus,
169+
) {
170+
}
171+
172+
public function process(mixed $data, Operation $operation, Context $context): mixed
173+
{
174+
Assert::isInstanceOf($data, BoardGameResource::class);
175+
176+
// Data is not provided in this case, so you will need to get it from the HTTP request
177+
$id = $context->get(RequestOption::class)?->attributes->get('id') ?? null;
178+
Assert::notNull($id);
179+
180+
$this->commandBus->dispatch(new DeleteBoardGameCommand(new BoardGameId($id)));
181+
182+
return null;
183+
}
184+
}
185+
```
186+
155187
**[Go back to the documentation's index](index.md)**
156188

157189
**[> Next chapter: Responders](responders.md)**

docs/providers.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ final class BoardGameResource implements ResourceInterface
171171

172172
namespace App\BoardGameBlog\Infrastructure\Sylius\State\Processor;
173173

174+
use Sylius\Resource\Context\Option\RequestOption;
175+
use Webmozart\Assert\Assert;
176+
174177
final class DeleteBoardGameProcessor implements ProcessorInterface
175178
{
176179
public function __construct(
@@ -181,8 +184,12 @@ final class DeleteBoardGameProcessor implements ProcessorInterface
181184
public function process(mixed $data, Operation $operation, Context $context): mixed
182185
{
183186
Assert::isInstanceOf($data, BoardGameResource::class);
187+
188+
// Data is not provided in this case, so you will need to get it from the HTTP request
189+
$id = $context->get(RequestOption::class)?->attributes->get('id') ?? null;
190+
Assert::notNull($id);
184191

185-
$this->commandBus->dispatch(new DeleteBoardGameCommand(new BoardGameId($data->id)));
192+
$this->commandBus->dispatch(new DeleteBoardGameCommand(new BoardGameId($id)));
186193

187194
return null;
188195
}

0 commit comments

Comments
 (0)