1 | <?php |
||
12 | class PhpDriver extends AbstractDriver |
||
13 | { |
||
14 | /** |
||
15 | * The classes (resources) from config.php |
||
16 | * @var array |
||
17 | */ |
||
18 | protected $classes = []; |
||
19 | |||
20 | /** |
||
21 | * Whether the classes have been read in |
||
22 | * @var bool |
||
23 | */ |
||
24 | protected $classesLoaded = false; |
||
25 | |||
26 | |||
27 | 20 | public function __construct($paths) |
|
31 | |||
32 | /** |
||
33 | * Factory method for the Annotation Driver |
||
34 | * |
||
35 | * @param array|string $paths |
||
36 | * @return self |
||
37 | */ |
||
38 | 10 | public static function create($paths = []) |
|
42 | |||
43 | /** |
||
44 | * Get all the metadata class names known to this driver. |
||
45 | * @return array |
||
46 | * @throws DrestException |
||
47 | * @throws DriverException |
||
48 | */ |
||
49 | 9 | public function getAllClassNames() |
|
74 | |||
75 | /** |
||
76 | * Load metadata for a class name |
||
77 | * @param object|string $className - Pass in either the class name, or an instance of that class |
||
78 | * @return Mapping\ClassMetaData|null $metaData - return null if metadata couldn't be populated from annotations |
||
79 | * @throws DrestException |
||
80 | */ |
||
81 | 5 | public function loadMetadataForClass($className) |
|
114 | |||
115 | /** |
||
116 | * Does the class contain a drest resource object |
||
117 | * |
||
118 | * @param string $className |
||
119 | * @return bool |
||
120 | */ |
||
121 | public function isDrestResource($className) |
||
129 | |||
130 | |||
131 | /** |
||
132 | * Process the method |
||
133 | * @param $resource |
||
134 | * @param Mapping\ClassMetaData $metadata |
||
135 | * @throws DrestException |
||
136 | */ |
||
137 | 1 | protected function processMethods($resource, Mapping\ClassMetaData $metadata) |
|
159 | } |
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.