1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Tidal/WampWatch package. |
5
|
|
|
* (c) 2016 Timo Michna <timomichna/yahoo.de> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Tidal\WampWatch\Model\Property\Collection; |
13
|
|
|
|
14
|
|
|
use Tidal\WampWatch\Model\Contract; |
15
|
|
|
use Tidal\WampWatch\Model\Contract\Property\ObjectCollectionInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class HasProceduresTrait. |
19
|
|
|
* |
20
|
|
|
* Important! Classes using this trait have to also use trait |
21
|
|
|
* Tidal\WampWatch\Model\Behavior\Property\HasCollectionsTrait |
22
|
|
|
* for this trait to work; |
23
|
|
|
*/ |
24
|
|
|
trait HasProceduresTrait |
25
|
|
|
{ |
26
|
|
|
protected static $proceduresPropertyName = 'procedures'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var ObjectCollectionInterface |
30
|
|
|
*/ |
31
|
|
|
private $procedures; |
32
|
|
|
|
33
|
|
|
public function addProcedure(Contract\ProcedureInterface $procedure) |
34
|
|
|
{ |
35
|
|
|
$this->getProcedures()->set($procedure->getUri(), $procedure); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return ObjectCollectionInterface |
40
|
|
|
*/ |
41
|
|
|
private function getProcedures() |
42
|
|
|
{ |
43
|
|
|
return $this->getCollection(static::$proceduresPropertyName); |
|
|
|
|
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function hasProcedure($uri) |
47
|
|
|
{ |
48
|
|
|
return $this->getProcedures()->has($uri); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param string $uri |
53
|
|
|
* |
54
|
|
|
* @return Contract\ProcedureInterface |
55
|
|
|
*/ |
56
|
|
|
public function getProcedure($uri) |
57
|
|
|
{ |
58
|
|
|
return $this->getProcedures()->get($uri); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param string $uri |
63
|
|
|
*/ |
64
|
|
|
public function removeProcedure($uri) |
65
|
|
|
{ |
66
|
|
|
$this->getProcedures()->offsetUnset($uri); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return \Generator |
71
|
|
|
*/ |
72
|
|
|
public function listProcedures() |
73
|
|
|
{ |
74
|
|
|
foreach ($this->getProcedures()->getIterator() as $uri => $procedure) { |
75
|
|
|
yield $uri => $procedure; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param ObjectCollectionInterface $procedures |
81
|
|
|
*/ |
82
|
|
|
private function setProcedures(ObjectCollectionInterface $procedures) |
83
|
|
|
{ |
84
|
|
|
$this->initCollection(static::$proceduresPropertyName, $procedures); |
|
|
|
|
85
|
|
|
$procedures->setObjectConstrain(Contract\ProcedureInterface::class); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.