1 | <?php |
||
25 | class ElasticsearchRouteProvider implements RouteProviderInterface |
||
26 | { |
||
27 | /** |
||
28 | * @var array Route map configuration to map Elasticsearch types and Controllers |
||
29 | */ |
||
30 | private $routeMap; |
||
31 | |||
32 | /** |
||
33 | * @var Manager |
||
34 | */ |
||
35 | private $manager; |
||
36 | |||
37 | /** |
||
38 | * @var MetadataCollector |
||
39 | */ |
||
40 | private $collector; |
||
41 | |||
42 | /** |
||
43 | * ElasticsearchRouteProvider constructor. |
||
44 | * |
||
45 | * @param MetadataCollector $collector |
||
46 | * @param array $routeMap |
||
47 | */ |
||
48 | public function __construct($collector, array $routeMap = []) |
||
53 | |||
54 | /** |
||
55 | * Returns Elasticsearch manager instance that was set in app/config.yml. |
||
56 | * |
||
57 | * @return Manager |
||
58 | */ |
||
59 | public function getManager() |
||
63 | |||
64 | /** |
||
65 | * @param Manager $manager |
||
66 | */ |
||
67 | public function setManager(Manager $manager) |
||
71 | |||
72 | /** |
||
73 | * @inheritDoc |
||
74 | */ |
||
75 | public function getRouteCollectionForRequest(Request $request) |
||
97 | |||
98 | /** |
||
99 | * @inheritDoc |
||
100 | */ |
||
101 | public function getRouteByName($name) |
||
107 | |||
108 | private function getRouteFromDocument($document) |
||
131 | |||
132 | /** |
||
133 | * @inheritDoc |
||
134 | */ |
||
135 | public function getRoutesByNames($names) |
||
140 | } |
||
141 |
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.