|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* YAWIK |
|
4
|
|
|
* |
|
5
|
|
|
* @filesource |
|
6
|
|
|
* @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de) |
|
7
|
|
|
* @license MIT |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
/** Core Entitys */ |
|
11
|
|
|
namespace Core\Entity; |
|
12
|
|
|
|
|
13
|
|
|
use Core\Entity\Exception\OutOfBoundsException; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Concrete implementation of \Core\Entity\EntityInterface. |
|
17
|
|
|
* |
|
18
|
|
|
* Provides some magic function for accessing properties |
|
19
|
|
|
* as class members, mirroring these calls to the |
|
20
|
|
|
* getter and setter methods. |
|
21
|
|
|
* |
|
22
|
|
|
*/ |
|
23
|
|
|
abstract class AbstractEntity implements EntityInterface |
|
24
|
|
|
{ |
|
25
|
|
|
use EntityTrait; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Sets a property through the setter method. |
|
29
|
|
|
* |
|
30
|
|
|
* An exception is raised, when no setter method exists. |
|
31
|
|
|
* |
|
32
|
|
|
* @deprecated since 0.25 Use setter method directly. |
|
33
|
|
|
* @param string $property |
|
34
|
|
|
* @param mixed $value |
|
35
|
|
|
* @return mixed |
|
36
|
|
|
* @throws OutOfBoundsException |
|
37
|
|
|
*/ |
|
38
|
|
View Code Duplication |
public function __set($property, $value) |
|
|
|
|
|
|
39
|
|
|
{ |
|
40
|
|
|
// trigger_error( |
|
|
|
|
|
|
41
|
|
|
// sprintf( |
|
42
|
|
|
// 'Accessing entity properties is deprecated. Use setter method instead. ( Tried to access "%s" on %s )', |
|
43
|
|
|
// $property, get_class($this) |
|
44
|
|
|
// ), |
|
45
|
|
|
// E_USER_DEPRECATED |
|
46
|
|
|
// ); |
|
47
|
|
|
$method = "set$property"; |
|
48
|
|
|
if (method_exists($this, $method)) { |
|
49
|
|
|
return $this->$method($value); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
throw new OutOfBoundsException("'$property' is not a valid property of '" . get_class($this). "'"); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Gets a property through the getter method. |
|
57
|
|
|
* |
|
58
|
|
|
* An exception is raised, when no getter method exists. |
|
59
|
|
|
* |
|
60
|
|
|
* @deprecated since 0.25 use getter method directly. |
|
61
|
|
|
* @param string $property |
|
62
|
|
|
* @return mixed |
|
63
|
|
|
* @throws OutOfBoundsException |
|
64
|
|
|
*/ |
|
65
|
|
View Code Duplication |
public function __get($property) |
|
|
|
|
|
|
66
|
|
|
{ |
|
67
|
|
|
// $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1); |
|
|
|
|
|
|
68
|
|
|
// trigger_error( |
|
69
|
|
|
// sprintf( |
|
70
|
|
|
// 'Accessing entity properties is deprecated. Use getter method instead. ( Tried to access "%s" on %s in %s on line %s )', |
|
71
|
|
|
// $property, get_class($this), $trace[0]['file'], $trace[0]['line'] |
|
72
|
|
|
// ), |
|
73
|
|
|
// E_USER_DEPRECATED |
|
74
|
|
|
// ); |
|
75
|
|
|
$method = "get$property"; |
|
76
|
|
|
if (method_exists($this, $method)) { |
|
77
|
|
|
return $this->$method(); |
|
78
|
|
|
} |
|
79
|
|
|
throw new OutOfBoundsException("'$property' is not a valid property of '" . get_class($this) . "'"); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Checks if a property exists and has a non-empty value. |
|
84
|
|
|
* |
|
85
|
|
|
* If the property is an array, the check will return, if this |
|
86
|
|
|
* array has items or not. |
|
87
|
|
|
* |
|
88
|
|
|
* @deprecated since 0.25 Use {@link notEmpty()} |
|
89
|
|
|
* @param string $property |
|
90
|
|
|
* @return boolean |
|
91
|
|
|
*/ |
|
92
|
|
|
public function __isset($property) |
|
|
|
|
|
|
93
|
|
|
{ |
|
94
|
|
|
// trigger_error( |
|
|
|
|
|
|
95
|
|
|
// sprintf( |
|
96
|
|
|
// 'Using isset() with entity properties is deprecated. Use %s::notEmpty("%s") instead.', |
|
97
|
|
|
// get_class($this), $property |
|
98
|
|
|
// ), |
|
99
|
|
|
// E_USER_DEPRECATED |
|
100
|
|
|
// ); |
|
101
|
|
|
return $this->notEmpty($property); |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.