This repository was archived by the owner on Oct 22, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +46
-63
lines changed
Expand file tree Collapse file tree 4 files changed +46
-63
lines changed Original file line number Diff line number Diff line change 99use Pavlusha311245 \UnitPhpSdk \Enums \ApplicationTypeEnum ;
1010use Pavlusha311245 \UnitPhpSdk \Exceptions \UnitException ;
1111use Pavlusha311245 \UnitPhpSdk \Interfaces \ApplicationInterface ;
12+ use Pavlusha311245 \UnitPhpSdk \Traits \HasListeners ;
1213
1314abstract class ApplicationAbstract implements ApplicationInterface
1415{
15- private ? Listener $ _listener = null ;
16+ use HasListeners ;
1617
1718 private string $ _type ;
1819
@@ -264,20 +265,4 @@ public function parseFromArray(array $data): void
264265 $ this ->setLimits (new RequestLimit ($ data ['limits ' ]));
265266 }
266267 }
267-
268- /**
269- * @param Listener $listener
270- */
271- public function setListener (Listener $ listener ): void
272- {
273- $ this ->_listener = $ listener ;
274- }
275-
276- /**
277- * @return Listener
278- */
279- public function getListener (): ?Listener
280- {
281- return $ this ->_listener ;
282- }
283268}
Original file line number Diff line number Diff line change 44
55use Pavlusha311245 \UnitPhpSdk \Config \Routes \RouteBlock ;
66use Pavlusha311245 \UnitPhpSdk \Interfaces \RouteInterface ;
7+ use Pavlusha311245 \UnitPhpSdk \Traits \HasListeners ;
78
89/**
910 * This class presents "routes" section from config
1011 */
1112class Route implements RouteInterface
1213{
14+ use HasListeners;
15+
1316 private array $ _routeBlocks ;
1417
1518 private array $ _listeners = [];
@@ -23,30 +26,6 @@ public function __construct(
2326 }
2427 }
2528
26- /**
27- * @inheritDoc
28- */
29- public function hasListeners (): bool
30- {
31- return !empty ($ this ->_listeners );
32- }
33-
34- /**
35- * @inheritDoc
36- */
37- public function setListener (Listener $ listener ): void
38- {
39- $ this ->_listeners [$ listener ->getListener ()] = $ listener ;
40- }
41-
42- /**
43- * @inheritDoc
44- */
45- public function getListeners (): array
46- {
47- return $ this ->_listeners ;
48- }
49-
5029 /**
5130 * @inheritDoc
5231 */
Original file line number Diff line number Diff line change @@ -13,28 +13,6 @@ interface RouteInterface
1313 */
1414 public function getName (): string ;
1515
16- /**
17- * Get listeners linked to route;
18- *
19- * @return mixed
20- */
21- public function getListeners (): array ;
22-
23- /**
24- * Setup new listener
25- *
26- * @param Listener $listener
27- * @return void
28- */
29- public function setListener (Listener $ listener ): void ;
30-
31- /**
32- * Check if listeners are empty or not
33- *
34- * @return bool
35- */
36- public function hasListeners (): bool ;
37-
3816 /**
3917 * Get route blocks
4018 *
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Pavlusha311245 \UnitPhpSdk \Traits ;
4+
5+ use Pavlusha311245 \UnitPhpSdk \Config \Listener ;
6+
7+ trait HasListeners
8+ {
9+ private array $ _listeners = [];
10+
11+ /**
12+ * Setup new listener
13+ *
14+ * @param Listener $listener
15+ * @return void
16+ */
17+ public function setListener (Listener $ listener ): void
18+ {
19+ $ this ->_listeners [$ listener ->getListener ()] = $ listener ;
20+ }
21+
22+ /**
23+ * Get listeners linked to object;
24+ *
25+ * @return mixed
26+ */
27+ public function getListeners (): array
28+ {
29+ return $ this ->_listeners ;
30+ }
31+
32+ /**
33+ * Check if listeners are empty or not
34+ *
35+ * @return bool
36+ */
37+ public function hasListeners (): bool
38+ {
39+ return !empty ($ this ->_listeners );
40+ }
41+ }
You can’t perform that action at this time.
0 commit comments