1 | <?php |
||
12 | trait HasRouteCollectionTrait |
||
13 | { |
||
14 | |||
15 | /** |
||
16 | * @inheritdoc |
||
17 | * @return RouteCollection |
||
18 | */ |
||
19 | 23 | public function getRouteCollection() |
|
20 | { |
||
21 | // if (null === $this->collection) { |
||
22 | // $this->collection = $this->newRoutesCollection(); |
||
23 | // } |
||
24 | 23 | return parent::getRouteCollection(); |
|
25 | } |
||
26 | |||
27 | /** |
||
28 | * @param $name |
||
29 | * @return null|Route\Route |
||
30 | */ |
||
31 | 1 | public function getRoute($name) |
|
35 | |||
36 | /** |
||
37 | * @return RouteCollection|Route[] |
||
38 | */ |
||
39 | 16 | public function getRoutes() |
|
43 | |||
44 | /** |
||
45 | * @param Route $route |
||
46 | */ |
||
47 | 1 | public function addRoute($route) |
|
48 | { |
||
49 | 1 | $this->getRouteCollection()->addRoute($route); |
|
50 | 1 | } |
|
51 | |||
52 | /** |
||
53 | * @param $name |
||
54 | * @return bool |
||
55 | */ |
||
56 | public function connected($name) |
||
57 | { |
||
58 | return $this->hasRoute($name); |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * @param string $name |
||
63 | * @return bool |
||
64 | */ |
||
65 | public function hasRoute($name) |
||
69 | |||
70 | 21 | public function initRouteCollection() |
|
71 | { |
||
72 | 21 | $this->collection = $this->newRoutesCollection(); |
|
74 | |||
75 | /** |
||
76 | * @return RouteCollection |
||
77 | */ |
||
78 | 21 | protected function newRoutesCollection() |
|
82 | } |
||
83 |
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.