Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
11 / 11 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
1 / 1 |
| CreateResourceFormRouteDefinition | |
100.00% |
11 / 11 |
|
100.00% |
7 / 7 |
9 | |
100.00% |
1 / 1 |
| createFrom | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| __construct | |
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 | |||
| getController | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getAction | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getOperationId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | namespace Apie\Cms\RouteDefinitions; |
| 3 | |
| 4 | use Apie\Cms\Controllers\CreateResourceFormController; |
| 5 | use Apie\Common\ActionDefinitions\ActionDefinitionInterface; |
| 6 | use Apie\Common\ActionDefinitions\CreateResourceActionDefinition; |
| 7 | use Apie\Common\ActionDefinitions\ReplaceResourceActionDefinition; |
| 8 | use Apie\Common\Actions\CreateObjectAction; |
| 9 | use Apie\Core\BoundedContext\BoundedContextId; |
| 10 | use Apie\Core\Enums\RequestMethod; |
| 11 | use Apie\Core\ValueObjects\UrlRouteDefinition; |
| 12 | use ReflectionClass; |
| 13 | |
| 14 | class CreateResourceFormRouteDefinition extends AbstractCmsRouteDefinition |
| 15 | { |
| 16 | public static function createFrom(ActionDefinitionInterface $actionDefinition): ?AbstractCmsRouteDefinition |
| 17 | { |
| 18 | if ($actionDefinition instanceof CreateResourceActionDefinition) { |
| 19 | return new self($actionDefinition->getResourceName(), $actionDefinition->getBoundedContextId()); |
| 20 | } |
| 21 | // TODO: should become PUT |
| 22 | if ($actionDefinition instanceof ReplaceResourceActionDefinition) { |
| 23 | return new self($actionDefinition->getResourceName(), $actionDefinition->getBoundedContextId()); |
| 24 | } |
| 25 | return null; |
| 26 | } |
| 27 | |
| 28 | public function __construct(ReflectionClass $class, BoundedContextId $boundedContextId) |
| 29 | { |
| 30 | parent::__construct($class, $boundedContextId); |
| 31 | } |
| 32 | |
| 33 | public function getMethod(): RequestMethod |
| 34 | { |
| 35 | return RequestMethod::GET; |
| 36 | } |
| 37 | |
| 38 | public function getUrl(): UrlRouteDefinition |
| 39 | { |
| 40 | return new UrlRouteDefinition('/resource/create/' . $this->class->getShortName()); |
| 41 | } |
| 42 | |
| 43 | public function getController(): string |
| 44 | { |
| 45 | return CreateResourceFormController::class; |
| 46 | } |
| 47 | |
| 48 | public function getAction(): string |
| 49 | { |
| 50 | return CreateObjectAction::class; |
| 51 | } |
| 52 | |
| 53 | public function getOperationId(): string |
| 54 | { |
| 55 | return 'create-resource-form-' . $this->class->getShortName(); |
| 56 | } |
| 57 | } |