1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the PhpBotFramework. |
5
|
|
|
* |
6
|
|
|
* PhpBotFramework is free software: you can redistribute it and/or modify |
7
|
|
|
* it under the terms of the GNU Lesser General Public License as |
8
|
|
|
* published by the Free Software Foundation, version 3. |
9
|
|
|
* |
10
|
|
|
* PhpBotFramework is distributed in the hope that it will be useful, but |
11
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13
|
|
|
* Lesser General Public License for more details. |
14
|
|
|
* |
15
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
16
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace PhpBotFramework\Entities; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* \addtogroup Core |
23
|
|
|
* @{ |
24
|
|
|
*/ |
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; |
67
|
|
|
} |
68
|
|
|
} |
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.