Merge pull request #17732 from civicrm/5.27
[civicrm-core.git] / Civi / Core / Event / PreEvent.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 namespace Civi\Core\Event;
13
14 /**
15 * Class AuthorizeEvent
16 * @package Civi\API\Event
17 */
18 class PreEvent extends GenericHookEvent {
19
20 /**
21 * This adapter automatically emits a narrower event.
22 *
23 * For example, `hook_civicrm_pre(Contact, ...)` will also dispatch `hook_civicrm_pre::Contact`.
24 *
25 * @param \Civi\Core\Event\PreEvent $event
26 */
27 public static function dispatchSubevent(PreEvent $event) {
28 \Civi::dispatcher()->dispatch("hook_civicrm_pre::" . $event->entity, $event);
29 }
30
31 /**
32 * One of: 'create'|'edit'|'delete'
33 *
34 * @var string
35 */
36 public $action;
37
38 /**
39 * @var string
40 */
41 public $entity;
42
43 /**
44 * @var int|null
45 */
46 public $id;
47
48 /**
49 * @var array
50 */
51 public $params;
52
53 /**
54 * Class constructor.
55 *
56 * @param string $action
57 * @param string $entity
58 * @param int $id
59 * @param array $params
60 */
61 public function __construct($action, $entity, $id, &$params) {
62 $this->action = $action;
63 $this->entity = $entity;
64 $this->id = $id;
65 $this->params = &$params;
66 }
67
68 /**
69 * @inheritDoc
70 */
71 public function getHookValues() {
72 return [$this->action, $this->entity, $this->id, &$this->params];
73 }
74
75 }