1 | <?php |
||
18 | class SchemaFactory |
||
19 | { |
||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $cacheKey = 'Arthem:GraphQL:Mapping'; |
||
24 | |||
25 | /** |
||
26 | * @var CacheDriverInterface |
||
27 | */ |
||
28 | private $cacheDriver; |
||
29 | |||
30 | /** |
||
31 | * @var DriverInterface |
||
32 | */ |
||
33 | private $driver; |
||
34 | |||
35 | /** |
||
36 | * @var TypeResolver |
||
37 | */ |
||
38 | private $typeResolver; |
||
39 | |||
40 | /** |
||
41 | * @var ResolverInterface[] |
||
42 | */ |
||
43 | private $resolveFactories = []; |
||
44 | |||
45 | /** |
||
46 | * @var MappingNormalizer |
||
47 | */ |
||
48 | private $normalizer; |
||
49 | |||
50 | /** |
||
51 | * @var MappingGuesserManager |
||
52 | */ |
||
53 | private $guesser; |
||
54 | |||
55 | /** |
||
56 | * @param DriverInterface $driver |
||
57 | * @param TypeResolver $typeResolver |
||
58 | * @param MappingGuesserManager|null $guesser |
||
59 | */ |
||
60 | public function __construct( |
||
71 | |||
72 | /** |
||
73 | * @param CacheDriverInterface $cacheDriver |
||
74 | */ |
||
75 | public function setCacheDriver(CacheDriverInterface $cacheDriver = null) |
||
79 | |||
80 | /** |
||
81 | * @return Schema |
||
82 | */ |
||
83 | public function createSchema() |
||
104 | |||
105 | /** |
||
106 | * @return SchemaContainer |
||
107 | */ |
||
108 | private function getSchemaContainer() |
||
119 | |||
120 | /** |
||
121 | * @return SchemaContainer |
||
122 | */ |
||
123 | private function loadSchemaContainer() |
||
138 | |||
139 | /** |
||
140 | * @param InterfaceType $type |
||
141 | * @return GQLDefinition\InterfaceType |
||
142 | */ |
||
143 | private function createInterface(InterfaceType $type) |
||
152 | |||
153 | /** |
||
154 | * @param FieldContainer $type |
||
155 | * @return GQLDefinition\ObjectType |
||
156 | */ |
||
157 | private function createType(FieldContainer $type) |
||
174 | |||
175 | /** |
||
176 | * @param Field[] $fields |
||
177 | */ |
||
178 | private function prepareFields(array $fields) |
||
202 | |||
203 | /** |
||
204 | * @param ResolverInterface $factory |
||
205 | */ |
||
206 | public function addResolver(ResolverInterface $factory) |
||
210 | } |
||
211 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.