Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
8 / 8 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
| StreamMethodCallOnSingleResourceRouteDefinition | |
100.00% |
8 / 8 |
|
100.00% |
6 / 6 |
7 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getOperationId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getMethod | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getUrl | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getAction | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| createFrom | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | namespace Apie\RestApi\RouteDefinitions; |
| 3 | |
| 4 | use Apie\Common\ActionDefinitions\ActionDefinitionInterface; |
| 5 | use Apie\Common\ActionDefinitions\DownloadFilesActionDefinition; |
| 6 | use Apie\Common\Actions\StreamItemMethodAction; |
| 7 | use Apie\Core\BoundedContext\BoundedContextId; |
| 8 | use Apie\Core\Entities\EntityInterface; |
| 9 | use Apie\Core\Enums\RequestMethod; |
| 10 | use Apie\Core\ValueObjects\UrlRouteDefinition; |
| 11 | use ReflectionClass; |
| 12 | |
| 13 | /** |
| 14 | * Route definition for running method on single resource to stream a resource |
| 15 | */ |
| 16 | class StreamMethodCallOnSingleResourceRouteDefinition extends AbstractRestApiRouteDefinition |
| 17 | { |
| 18 | /** |
| 19 | * @param ReflectionClass<EntityInterface> $className |
| 20 | */ |
| 21 | public function __construct(ReflectionClass $className, BoundedContextId $boundedContextId) |
| 22 | { |
| 23 | parent::__construct($className, $boundedContextId); |
| 24 | } |
| 25 | |
| 26 | public function getOperationId(): string |
| 27 | { |
| 28 | return 'stream-single-' . $this->class->getShortName() . '-run-download'; |
| 29 | } |
| 30 | |
| 31 | public function getMethod(): RequestMethod |
| 32 | { |
| 33 | return RequestMethod::GET; |
| 34 | } |
| 35 | |
| 36 | public function getUrl(): UrlRouteDefinition |
| 37 | { |
| 38 | return new UrlRouteDefinition('/' . $this->class->getShortName() . '/{id}/download/{properties}'); |
| 39 | } |
| 40 | |
| 41 | public function getAction(): string |
| 42 | { |
| 43 | return StreamItemMethodAction::class; |
| 44 | } |
| 45 | |
| 46 | public static function createFrom(ActionDefinitionInterface $actionDefinition): ?AbstractRestApiRouteDefinition |
| 47 | { |
| 48 | if ($actionDefinition instanceof DownloadFilesActionDefinition) { |
| 49 | return new self($actionDefinition->getResourceName(), $actionDefinition->getBoundedContextId()); |
| 50 | } |
| 51 | return null; |
| 52 | } |
| 53 | } |