| 1 | <?php |
||||
| 2 | /** |
||||
| 3 | * This file is part of Railt package. |
||||
| 4 | * |
||||
| 5 | * For the full copyright and license information, please view the LICENSE |
||||
| 6 | * file that was distributed with this source code. |
||||
| 7 | */ |
||||
| 8 | declare(strict_types=1); |
||||
| 9 | |||||
| 10 | namespace Railt\Adapters\Webonyx; |
||||
| 11 | |||||
| 12 | use GraphQL\Type\Definition\ResolveInfo; |
||||
| 13 | use Railt\Container\ContainerInterface; |
||||
|
0 ignored issues
–
show
|
|||||
| 14 | use Railt\Http\RequestInterface; |
||||
|
0 ignored issues
–
show
The type
Railt\Http\RequestInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 15 | use Railt\Reflection\Contracts\Definitions\ObjectDefinition; |
||||
|
0 ignored issues
–
show
The type
Railt\Reflection\Contrac...itions\ObjectDefinition was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 16 | use Railt\Reflection\Contracts\Definitions\TypeDefinition; |
||||
|
0 ignored issues
–
show
The type
Railt\Reflection\Contrac...initions\TypeDefinition was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 17 | use Railt\Reflection\Contracts\Dependent\FieldDefinition; |
||||
|
0 ignored issues
–
show
The type
Railt\Reflection\Contrac...pendent\FieldDefinition was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 18 | use Railt\Reflection\Contracts\Invocations\DirectiveInvocation; |
||||
|
0 ignored issues
–
show
The type
Railt\Reflection\Contrac...ons\DirectiveInvocation was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 19 | use Railt\Routing\Contracts\InputInterface; |
||||
|
0 ignored issues
–
show
The type
Railt\Routing\Contracts\InputInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 20 | use Railt\Routing\Contracts\RouterInterface; |
||||
|
0 ignored issues
–
show
The type
Railt\Routing\Contracts\RouterInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 21 | use Railt\Routing\GraphQL\RouteDirective; |
||||
|
0 ignored issues
–
show
The type
Railt\Routing\GraphQL\RouteDirective was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 22 | use Railt\Routing\Route; |
||||
|
0 ignored issues
–
show
The type
Railt\Routing\Route was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 23 | |||||
| 24 | /** |
||||
| 25 | * Class FieldResolver |
||||
| 26 | */ |
||||
| 27 | class FieldResolver |
||||
| 28 | { |
||||
| 29 | private const DIRECTIVE = RouteDirective::DIRECTIVE_NAME; |
||||
| 30 | private const DIRECTIVE_ACTION = RouteDirective\ActionArgument::ARGUMENT_NAME; |
||||
|
0 ignored issues
–
show
The type
Railt\Routing\GraphQL\Ro...irective\ActionArgument was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 31 | private const DIRECTIVE_OPERATION = RouteDirective\OperationArgument::ARGUMENT_NAME; |
||||
|
0 ignored issues
–
show
The type
Railt\Routing\GraphQL\Ro...ctive\OperationArgument was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 32 | |||||
| 33 | /** |
||||
| 34 | * @var ContainerInterface |
||||
| 35 | */ |
||||
| 36 | private $container; |
||||
| 37 | |||||
| 38 | /** |
||||
| 39 | * @var RouterInterface |
||||
| 40 | */ |
||||
| 41 | private $router; |
||||
| 42 | |||||
| 43 | /** |
||||
| 44 | * FieldResolver constructor. |
||||
| 45 | * @param ContainerInterface $container |
||||
| 46 | */ |
||||
| 47 | public function __construct(ContainerInterface $container) |
||||
| 48 | { |
||||
| 49 | $this->container = $container; |
||||
| 50 | $this->router = $container->make(RouterInterface::class); |
||||
| 51 | } |
||||
| 52 | |||||
| 53 | /** |
||||
| 54 | * @param RequestInterface $request |
||||
| 55 | * @param FieldDefinition $field |
||||
| 56 | * @return \Closure|null |
||||
| 57 | */ |
||||
| 58 | public function getCallback(RequestInterface $request, FieldDefinition $field): ?\Closure |
||||
|
0 ignored issues
–
show
The parameter
$request is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||
| 59 | { |
||||
| 60 | /** @var ObjectDefinition $object */ |
||||
| 61 | $object = $field->getParent(); |
||||
| 62 | |||||
| 63 | $this->loadRouteDirective($object, $field); |
||||
| 64 | |||||
| 65 | |||||
| 66 | if (! $this->router->has($object)) { |
||||
| 67 | return null; |
||||
| 68 | } |
||||
| 69 | |||||
| 70 | /** @var Route $route */ |
||||
| 71 | $route = $this->router->get($object); |
||||
| 72 | |||||
| 73 | // TODO Match operation |
||||
| 74 | // $request->getOperation() |
||||
| 75 | |||||
| 76 | // TODO Match method |
||||
| 77 | // $request->getMethod() |
||||
| 78 | |||||
| 79 | return function ($parent, array $arguments = [], $ctx, ResolveInfo $info) use ($route, $field) { |
||||
| 80 | return $route->call([ |
||||
| 81 | InputInterface::class => new Input($field, $info, $arguments, $parent), |
||||
| 82 | TypeDefinition::class => $field, |
||||
| 83 | 'parent' => $parent, |
||||
| 84 | ]); |
||||
| 85 | }; |
||||
| 86 | } |
||||
| 87 | |||||
| 88 | /** |
||||
| 89 | * @param ObjectDefinition $object |
||||
| 90 | * @param FieldDefinition $field |
||||
| 91 | * @return void |
||||
| 92 | */ |
||||
| 93 | private function loadRouteDirective(ObjectDefinition $object, FieldDefinition $field): void |
||||
| 94 | { |
||||
| 95 | if (! $field->hasDirective(self::DIRECTIVE)) { |
||||
| 96 | return; |
||||
| 97 | } |
||||
| 98 | |||||
| 99 | /** @var DirectiveInvocation $directive */ |
||||
| 100 | $directive = $field->getDirective(self::DIRECTIVE); |
||||
| 101 | |||||
| 102 | $urn = (string)$directive->getPassedArgument(self::DIRECTIVE_ACTION)->getPassedValue(); |
||||
| 103 | |||||
| 104 | $route = $this->router->route($object, $field->getName()) |
||||
|
0 ignored issues
–
show
|
|||||
| 105 | ->then($this->createCallback($urn)); |
||||
| 106 | |||||
| 107 | // TODO Add operations |
||||
| 108 | // TODO Add method |
||||
| 109 | } |
||||
| 110 | |||||
| 111 | /** |
||||
| 112 | * @param string $urn |
||||
| 113 | * @return \Closure |
||||
| 114 | */ |
||||
| 115 | private function createCallback(string $urn): \Closure |
||||
| 116 | { |
||||
| 117 | [$controller, $action] = \explode('@', $urn); |
||||
| 118 | |||||
| 119 | return \Closure::fromCallable([ |
||||
| 120 | $this->container->make($controller), |
||||
| 121 | $action, |
||||
| 122 | ]); |
||||
| 123 | } |
||||
| 124 | } |
||||
| 125 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths