DispatcherAwareTrait.php
1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/**
* Part of the Joomla Framework Event Package
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\Event;
/**
* Defines the trait for a Dispatcher Aware Class.
*
* @since 1.2.0
*/
trait DispatcherAwareTrait
{
/**
* Event Dispatcher
*
* @var DispatcherInterface
* @since 1.2.0
*/
private $dispatcher;
/**
* Get the event dispatcher.
*
* @return DispatcherInterface
*
* @since 1.2.0
* @throws \UnexpectedValueException May be thrown if the dispatcher has not been set.
*/
public function getDispatcher()
{
if ($this->dispatcher)
{
return $this->dispatcher;
}
throw new \UnexpectedValueException('Dispatcher not set in ' . __CLASS__);
}
/**
* Set the dispatcher to use.
*
* @param DispatcherInterface $dispatcher The dispatcher to use.
*
* @return $this
*
* @since 1.2.0
*/
public function setDispatcher(DispatcherInterface $dispatcher)
{
$this->dispatcher = $dispatcher;
return $this;
}
}