1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author stev leibelt <[email protected]> |
4
|
|
|
* @since 2013-08-12 |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace Example\Validator; |
8
|
|
|
|
9
|
|
|
require __DIR__ . '/../../../../vendor/autoload.php'; |
10
|
|
|
|
11
|
|
|
Example::create() |
12
|
|
|
->setup() |
13
|
|
|
->andRun(); |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class Example |
17
|
|
|
* |
18
|
|
|
* @package Example\Validator |
19
|
|
|
* @author stev leibelt <[email protected]> |
20
|
|
|
* @since 2013-08-12 |
21
|
|
|
*/ |
22
|
|
|
class Example |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var \Net\Bazzline\Component\Requirement\Requirement |
26
|
|
|
* @author stev leibelt <[email protected]> |
27
|
|
|
* @since 2013-08-12 |
28
|
|
|
*/ |
29
|
|
|
private $validator; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var Table[] |
33
|
|
|
* @author stev leibelt <[email protected]> |
34
|
|
|
* @since 2013-08-12 |
35
|
|
|
*/ |
36
|
|
|
private $tables; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return Example |
40
|
|
|
* @author stev leibelt <[email protected]> |
41
|
|
|
* @since 2012-08-12 |
42
|
|
|
*/ |
43
|
|
|
public static function create() |
44
|
|
|
{ |
45
|
|
|
return new self(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return $this |
50
|
|
|
* @author stev leibelt <[email protected]> |
51
|
|
|
* @since 2013-08-12 |
52
|
|
|
*/ |
53
|
|
|
public function setup() |
54
|
|
|
{ |
55
|
|
|
$this->validator = TableValidatorCollection::create(); |
56
|
|
|
$this->tables = array(); |
57
|
|
|
|
58
|
|
|
$colors = array(0 => 'red', 1 => 'green', 2 => 'blue', 3 => 'yellow', 4 => 'orange', 5 => 'black'); |
59
|
|
|
$heights = array(0 => 50, 1 => 69, 2 => 70, 3 => 74, 4 => 81, 5 => 85, 6 => 89, 7 => 101); |
60
|
|
|
$lengths = array(0 => 40, 1 => 56, 2 => 71, 3 => 91, 4 => 100, 5 => 200, 6 => 210); |
61
|
|
|
$widths = array(0 => 47, 1 => 76, 2 => 82, 3 => 129, 4 => 132, 5 => 154, 6 => 179); |
62
|
|
|
|
63
|
|
|
$sizeOfColors = count($colors) - 1; |
64
|
|
|
$sizeOfHeight = count($heights) - 1; |
65
|
|
|
$sizeOfLengths = count($lengths) - 1; |
66
|
|
|
$sizeOfWidths = count($widths) - 1; |
67
|
|
|
|
68
|
|
|
$numberOfTables = 7; |
69
|
|
|
|
70
|
|
|
for ($iterator = 0; $iterator < $numberOfTables; $iterator++) { |
71
|
|
|
$table = new Table(); |
72
|
|
|
|
73
|
|
|
$table->setColor($colors[rand(0, $sizeOfColors)]); |
74
|
|
|
$table->setHeight($heights[rand(0, $sizeOfHeight)]); |
75
|
|
|
$table->setLength($lengths[rand(0, $sizeOfLengths)]); |
76
|
|
|
$table->setWidth($widths[rand(0, $sizeOfWidths)]); |
77
|
|
|
|
78
|
|
|
$this->tables[] = $table; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return $this; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @author stev leibelt <[email protected]> |
86
|
|
|
* @since 2013-08-12 |
87
|
|
|
*/ |
88
|
|
|
public function andRun() |
89
|
|
|
{ |
90
|
|
|
echo str_repeat('-', 48) . PHP_EOL; |
91
|
|
|
echo 'Number of tables: ' . count($this->tables) . PHP_EOL; |
92
|
|
|
echo str_repeat('-', 48) . PHP_EOL; |
93
|
|
|
echo 'Iterating over tables.' . PHP_EOL; |
94
|
|
|
foreach ($this->tables as $table) { |
95
|
|
|
/** |
96
|
|
|
* @var Table $table |
97
|
|
|
*/ |
98
|
|
|
$this->validator->setTable($table); |
|
|
|
|
99
|
|
|
echo 'Is valid table: ' . ($this->validator->isMet() ? 'yes' : 'no') . PHP_EOL; |
100
|
|
|
} |
101
|
|
|
echo str_repeat('-', 48) . PHP_EOL; |
102
|
|
|
} |
103
|
|
|
} |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: