|
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
|
|
|
/** */ |
|
11
|
|
|
namespace Core\Entity; |
|
12
|
|
|
|
|
13
|
|
|
use Core\Entity\Exception\OutOfBoundsException; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Implementation of \Core\Entity\EntityInterface. |
|
17
|
|
|
* |
|
18
|
|
|
* |
|
19
|
|
|
* @var EntityInterface $this |
|
20
|
|
|
* |
|
21
|
|
|
* @author Mathias Gelhausen <[email protected]> |
|
22
|
|
|
* @since 0.25 |
|
23
|
|
|
*/ |
|
24
|
|
|
trait EntityTrait |
|
25
|
|
|
{ |
|
26
|
|
|
public function notEmpty($property, array $args=[]) |
|
|
|
|
|
|
27
|
|
|
{ |
|
28
|
|
|
$method = "get$property"; |
|
29
|
|
|
|
|
30
|
|
|
if (!method_exists($this, $method)) { |
|
31
|
|
|
throw new OutOfBoundsException("'$property' is not a valid property of '" . get_class($this) . "'"); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
$value = count($args) |
|
35
|
|
|
? call_user_func_array([ $this, $method ], $args) |
|
36
|
|
|
: $this->$method(); |
|
37
|
|
|
|
|
38
|
|
|
if (null === $value) { // is_scalar does not consider 'null' to be scalar value. |
|
39
|
|
|
return false; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
if (is_scalar($value) || is_array($value)) { |
|
43
|
|
|
return !empty($value); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
if (is_resource($value)) { |
|
47
|
|
|
return true; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/* |
|
51
|
|
|
* $value must be an object. |
|
52
|
|
|
*/ |
|
53
|
|
|
if ($value instanceOf \Countable) { |
|
54
|
|
|
return (bool) count($value); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
return true; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function hasProperty($property, $mode = self::PROPERTY_STRICT) |
|
61
|
|
|
{ |
|
62
|
|
|
$hasProperty = property_exists($this, $property); |
|
63
|
|
|
|
|
64
|
|
|
if (!$hasProperty || self::PROPERTY_FACILE === $mode) { |
|
65
|
|
|
return $hasProperty; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
$hasGetter = method_exists($this, "get$property"); |
|
69
|
|
|
|
|
70
|
|
|
if (self::PROPERTY_GETTER === $mode) { |
|
71
|
|
|
return $hasGetter; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
$hasSetter = method_exists($this, "set$property"); |
|
75
|
|
|
|
|
76
|
|
|
if (self::PROPERTY_SETTER === $mode) { |
|
77
|
|
|
return $hasSetter; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
return $hasGetter && $hasSetter; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.