|
| 1 | +<?php |
| 2 | + |
| 3 | + |
| 4 | +namespace TheCodingMachine\GraphQL\Controllers; |
| 5 | + |
| 6 | +use phpDocumentor\Reflection\Type; |
| 7 | +use phpDocumentor\Reflection\Types\Array_; |
| 8 | +use phpDocumentor\Reflection\Types\Mixed; |
| 9 | +use phpDocumentor\Reflection\Types\Object_; |
| 10 | +use phpDocumentor\Reflection\Types\String_; |
| 11 | +use Psr\Container\ContainerInterface; |
| 12 | +use Roave\BetterReflection\Reflection\ReflectionClass; |
| 13 | +use Roave\BetterReflection\Reflection\ReflectionMethod; |
| 14 | +use Doctrine\Common\Annotations\Reader; |
| 15 | +use phpDocumentor\Reflection\Types\Integer; |
| 16 | +use TheCodingMachine\GraphQL\Controllers\Annotations\Query; |
| 17 | +use Youshido\GraphQL\Field\Field; |
| 18 | +use Youshido\GraphQL\Type\ListType\ListType; |
| 19 | +use Youshido\GraphQL\Type\NonNullType; |
| 20 | +use Youshido\GraphQL\Type\Scalar\IntType; |
| 21 | +use Youshido\GraphQL\Type\Scalar\StringType; |
| 22 | +use Youshido\GraphQL\Type\TypeInterface; |
| 23 | +use Youshido\GraphQL\Type\Union\UnionType; |
| 24 | + |
| 25 | +/** |
| 26 | + * A query provider that looks into all controllers of your application to fetch queries. |
| 27 | + */ |
| 28 | +class AggregateControllerQueryProvider implements QueryProviderInterface |
| 29 | +{ |
| 30 | + /** |
| 31 | + * @var Reader |
| 32 | + */ |
| 33 | + private $annotationReader; |
| 34 | + /** |
| 35 | + * @var TypeMapperInterface |
| 36 | + */ |
| 37 | + private $typeMapper; |
| 38 | + /** |
| 39 | + * @var HydratorInterface |
| 40 | + */ |
| 41 | + private $hydrator; |
| 42 | + /** |
| 43 | + * @var array|\string[] |
| 44 | + */ |
| 45 | + private $controllers; |
| 46 | + /** |
| 47 | + * @var ContainerInterface |
| 48 | + */ |
| 49 | + private $container; |
| 50 | + |
| 51 | + /** |
| 52 | + * @param string[] $controllers A list of controllers name in the container. |
| 53 | + */ |
| 54 | + public function __construct(array $controllers, ContainerInterface $container, Reader $annotationReader, TypeMapperInterface $typeMapper, HydratorInterface $hydrator) |
| 55 | + { |
| 56 | + $this->controllers = $controllers; |
| 57 | + $this->container = $container; |
| 58 | + $this->annotationReader = $annotationReader; |
| 59 | + $this->typeMapper = $typeMapper; |
| 60 | + $this->hydrator = $hydrator; |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * @return Field[] |
| 65 | + */ |
| 66 | + public function getQueries(): array |
| 67 | + { |
| 68 | + $queryList = []; |
| 69 | + |
| 70 | + foreach ($this->controllers as $controllerName) { |
| 71 | + $controller = $this->container->get($controllerName); |
| 72 | + $queryProvider = new ControllerQueryProvider($controller, $this->container, $this->annotationReader, $this->typeMapper, $this->hydrator); |
| 73 | + $queryList = array_merge($queryList, $queryProvider->getQueries()); |
| 74 | + } |
| 75 | + |
| 76 | + return $queryList; |
| 77 | + } |
| 78 | +} |
0 commit comments