1 | <?php |
||
38 | class Cache implements CacheConfigurationInterface |
||
39 | { |
||
40 | |||
41 | /** |
||
42 | * The cache type. |
||
43 | * |
||
44 | * @var string |
||
45 | * @Type("string") |
||
46 | * @SerializedName("type") |
||
47 | */ |
||
48 | protected $type; |
||
49 | |||
50 | /** |
||
51 | * The cache's TTL (null === cache item NEVER times out). |
||
52 | * |
||
53 | * @var integer |
||
54 | * @Type("integer") |
||
55 | */ |
||
56 | protected $time = null; |
||
57 | |||
58 | /** |
||
59 | * The event name the listener has to be registered. |
||
60 | * |
||
61 | * @var string |
||
62 | * @Type("boolean") |
||
63 | */ |
||
64 | protected $enabled = true; |
||
65 | |||
66 | /** |
||
67 | * A reference to the parent configuration instance. |
||
68 | * |
||
69 | * @var \TechDivision\Import\Configuration\ConfigurationInterface |
||
70 | */ |
||
71 | protected $configuration; |
||
72 | |||
73 | /** |
||
74 | * Return's the cache type |
||
75 | * |
||
76 | * @return string The cache type |
||
77 | */ |
||
78 | public function getType() |
||
82 | |||
83 | /** |
||
84 | * Return's the flag whether the cache is enabled or not. |
||
85 | * |
||
86 | * The cache type cache.static is ALWAYS enabled, which is necessary e. g. |
||
87 | * for the registration processor that contains the global data. |
||
88 | * |
||
89 | * @return boolean TRUE if the cache is enabled, else FALSE |
||
90 | */ |
||
91 | public function isEnabled() |
||
95 | |||
96 | /** |
||
97 | * Return's the cache TTL in seconds. |
||
98 | * |
||
99 | * @return integer The TTL |
||
100 | */ |
||
101 | public function getTime() |
||
105 | |||
106 | /** |
||
107 | * Set's the reference to the configuration instance. |
||
108 | * |
||
109 | * @param \TechDivision\Import\Configuration\ConfigurationInterface $configuration The configuration instance |
||
110 | * |
||
111 | * @return void |
||
112 | */ |
||
113 | public function setConfiguration(ConfigurationInterface $configuration) |
||
117 | |||
118 | /** |
||
119 | * Return's the reference to the configuration instance. |
||
120 | * |
||
121 | * @return \TechDivision\Import\Configuration\ConfigurationInterface The configuration instance |
||
122 | */ |
||
123 | public function getConfiguration() |
||
127 | } |
||
128 |
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.