1 | <?php |
||
19 | abstract class RedirectRoute implements RedirectRouteInterface |
||
20 | { |
||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $name; |
||
25 | |||
26 | /** |
||
27 | * Absolute uri to redirect to. |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $uri; |
||
32 | |||
33 | /** |
||
34 | * The name of a target route (for use with standard symfony routes). |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $routeName; |
||
39 | |||
40 | /** |
||
41 | * Target route to redirect to different dynamic route. |
||
42 | * |
||
43 | * @var RouteInterface |
||
44 | */ |
||
45 | protected $routeTarget; |
||
46 | |||
47 | /** |
||
48 | * Route parameters. |
||
49 | * |
||
50 | * @var array |
||
51 | */ |
||
52 | protected $parameters = array(); |
||
53 | |||
54 | /** |
||
55 | * Whether this is a permanent redirect. Defaults to true. |
||
56 | * |
||
57 | * @var bool |
||
58 | */ |
||
59 | protected $permanent = true; |
||
60 | |||
61 | /** |
||
62 | * {@inheritdoc} |
||
63 | */ |
||
64 | public function getContent() |
||
68 | |||
69 | /** |
||
70 | * {@inheritdoc} |
||
71 | */ |
||
72 | public function getRouteKey() |
||
76 | |||
77 | /** |
||
78 | * {@inheritdoc} |
||
79 | */ |
||
80 | public function setName($name) |
||
86 | |||
87 | /** |
||
88 | * {@inheritdoc} |
||
89 | */ |
||
90 | public function getName() |
||
94 | |||
95 | /** |
||
96 | * {@inheritdoc} |
||
97 | */ |
||
98 | public function setUri($uri) |
||
104 | |||
105 | /** |
||
106 | * {@inheritdoc} |
||
107 | */ |
||
108 | public function getUri() |
||
112 | |||
113 | /** |
||
114 | * {@inheritdoc} |
||
115 | */ |
||
116 | public function setRouteTarget(RouteInterface $routeTarget = null) |
||
122 | |||
123 | /** |
||
124 | * {@inheritdoc} |
||
125 | */ |
||
126 | public function getRouteTarget() |
||
130 | |||
131 | /** |
||
132 | * {@inheritdoc} |
||
133 | */ |
||
134 | public function setRouteName($routeName) |
||
140 | |||
141 | /** |
||
142 | * {@inheritdoc} |
||
143 | */ |
||
144 | public function getRouteName() |
||
148 | |||
149 | /** |
||
150 | * {@inheritdoc} |
||
151 | */ |
||
152 | public function getParameters() |
||
156 | |||
157 | /** |
||
158 | * {@inheritdoc} |
||
159 | */ |
||
160 | public function setParameters(array $parameters) |
||
166 | |||
167 | /** |
||
168 | * {@inheritdoc} |
||
169 | */ |
||
170 | public function setPermanent($permanent) |
||
176 | |||
177 | /** |
||
178 | * {@inheritdoc} |
||
179 | */ |
||
180 | public function isPermanent() |
||
184 | } |
||
185 |
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.