| 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\SDL\Standard; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Railt\Io\File; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Railt\SDL\Base\BaseDocument; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Railt\SDL\Contracts\Definitions\Definition; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Railt\SDL\Contracts\Definitions\TypeDefinition; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Railt\SDL\Standard\Directives\Deprecation; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Railt\SDL\Standard\Scalars\AnyType; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Railt\SDL\Standard\Scalars\BooleanType; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use Railt\SDL\Standard\Scalars\DateTimeType; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use Railt\SDL\Standard\Scalars\FloatType; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | use Railt\SDL\Standard\Scalars\IDType; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | use Railt\SDL\Standard\Scalars\IntType; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | use Railt\SDL\Standard\Scalars\StringType; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | use Railt\SDL\Reflection\Dictionary; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  * This class contains a Document implementation for | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  * the standard GraphQL library. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | class GraphQLDocument extends BaseDocument implements StandardType | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * The name of our document constant. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     private const DOCUMENT_NAME = 'GraphQL Standard Library'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     private $additionalTypes; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * @var Dictionary | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     private $dictionary; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      * GraphQLDocument constructor. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * @param Dictionary $dictionary | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      * @param array|string[] $additionalTypes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 | 283 |  |     public function __construct(Dictionary $dictionary, array $additionalTypes = []) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 | 283 |  |         $this->file            = File::fromSources('# Generated'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 283 |  |         $this->additionalTypes = $additionalTypes; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 | 283 |  |         $this->createStandardTypes(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 | 283 |  |         $this->dictionary = $dictionary; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 | 283 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * @return Dictionary | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 | 12 |  |     public function getDictionary(): Dictionary | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 | 12 |  |         return $this->dictionary; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * Creation and registration of types. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 | 283 |  |     private function createStandardTypes(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 | 283 |  |         foreach ($this->getStandardTypes() as $type) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |             /** @var Definition|mixed $instance */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 | 283 |  |             $instance = new $type($this); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 | 283 |  |             if ($instance instanceof TypeDefinition) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 | 283 |  |                 $this->types[$instance->getName()] = $instance; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 | 283 |  |                 $this->definitions[] = $instance; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 | 283 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      * Returns should return a list of all predefined GraphQL types. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |      * @return array|StandardType[] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 | 283 |  |     private function getStandardTypes(): array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         $standard = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |             // Scalars | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 | 283 |  |             BooleanType::class, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |             FloatType::class, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |             IDType::class, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |             IntType::class, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |             StringType::class, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |             AnyType::class, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |             DateTimeType::class, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |             // Directives | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |             Deprecation::class, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 | 283 |  |         return \array_merge($standard, $this->additionalTypes); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |      * @return string | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 114 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 115 | 1 |  |     public function getName(): string | 
            
                                                        
            
                                    
            
            
                | 116 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 117 | 1 |  |         return self::DOCUMENT_NAME; | 
            
                                                        
            
                                    
            
            
                | 118 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 119 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 120 |  |  |  |