1 | <?php |
||
25 | trait EntityAccess |
||
26 | { |
||
27 | /** @} */ |
||
28 | |||
29 | /** \brief Contains the array passed __construct */ |
||
30 | private $container; |
||
31 | |||
32 | public function __construct($data) |
||
33 | { |
||
34 | $this->container = $data; |
||
35 | } |
||
36 | |||
37 | public function offsetSet($offset, $value) |
||
38 | { |
||
39 | } |
||
40 | |||
41 | /** \brief Check that the given offset exists or not */ |
||
42 | public function offsetExists($offset) |
||
43 | { |
||
44 | <<<<<<< HEAD |
||
45 | return isset($this->container[$offset]); |
||
46 | } |
||
47 | |||
48 | public function offsetUnset($offset) { /* Log a warning */ } |
||
49 | |||
50 | /** |
||
51 | * \brief Get the given offset. |
||
52 | * @param $offset The given offset. |
||
53 | * @return Data relative to the offset. |
||
54 | */ |
||
55 | public function offsetGet($offset) |
||
56 | { |
||
57 | // Get name of the method, the class should have. Like "getText" |
||
58 | $method = Text::camelCase("get $offset"); |
||
59 | |||
60 | // If it exists, call it and return its return value |
||
61 | if (method_exists($this, $method)) { |
||
62 | return $this->{$method}(); |
||
63 | } |
||
64 | |||
65 | // If not return the data from the array after checking it is set |
||
66 | return isset($this->container[$offset]) ? $this->container[$offset] : null; |
||
69 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.