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
|
|
|
trait EntityAccess |
22
|
|
|
{ |
23
|
|
|
/** \brief Contains the array passed __construct */ |
24
|
|
|
private $container; |
25
|
|
|
|
26
|
14 |
|
public function __construct($data) |
27
|
|
|
{ |
28
|
14 |
|
$this->container = $data; |
29
|
14 |
|
} |
30
|
|
|
|
31
|
|
|
public function offsetSet($offset, $value) |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** \brief Check that the given offset exists or not */ |
36
|
10 |
|
public function offsetExists($offset) |
37
|
|
|
{ |
38
|
10 |
|
return isset($this->container[$offset]); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function offsetUnset($offset) { /* Log a warning */ } |
|
|
|
|
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* \brief Get the given offset. |
45
|
|
|
* @param $offset The given offset. |
46
|
|
|
* @return Data relative to the offset. |
47
|
|
|
*/ |
48
|
7 |
|
public function offsetGet($offset) |
49
|
|
|
{ |
50
|
|
|
// Get name of the method, the class should have. Like "getText" |
51
|
7 |
|
$method = Text::camelCase("get $offset"); |
52
|
|
|
|
53
|
|
|
// If it exists, call it and return its return value |
54
|
7 |
|
if (method_exists($this, $method)) { |
55
|
3 |
|
return $this->{$method}(); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
// If not return the data from the array after checking it is set |
59
|
6 |
|
return isset($this->container[$offset]) ? $this->container[$offset] : null; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.