Elgg  Version 3.0
Hook.php
Go to the documentation of this file.
1 <?php
2 
4 
6 
12 class Hook implements \Elgg\Hook {
13 
14  private $dic;
15  private $name;
16  private $type;
17  private $value;
18  private $params;
19 
20  const EVENT_TYPE = 'hook';
21 
31  public function __construct(PublicContainer $dic, $name, $type, $value, $params) {
32  $this->dic = $dic;
33  $this->name = $name;
34  $this->type = $type;
35  $this->value = $value;
36  $this->params = $params;
37  }
38 
42  public function getName() {
43  return $this->name;
44  }
45 
49  public function getType() {
50  return $this->type;
51  }
52 
56  public function getValue() {
57  return $this->value;
58  }
59 
68  public function setValue($value) {
69  $this->value = $value;
70  }
71 
75  public function getParams() {
76  return $this->params;
77  }
78 
82  public function getParam($key, $default = null) {
83  if (!is_array($this->params)) {
84  return $default;
85  }
86 
87  return array_key_exists($key, $this->params) ? $this->params[$key] : $default;
88  }
89 
93  public function getEntityParam() {
94  if (isset($this->params['entity']) && $this->params['entity'] instanceof \ElggEntity) {
95  return $this->params['entity'];
96  }
97 
98  return null;
99  }
100 
104  public function getUserParam() {
105  if (isset($this->params['user']) && $this->params['user'] instanceof \ElggUser) {
106  return $this->params['user'];
107  }
108 
109  return null;
110  }
111 
115  public function elgg() {
116  return $this->dic;
117  }
118 
122  public function toLegacyArgs() {
123  return [$this->name, $this->type, $this->value, $this->params];
124  }
125 }
getType()
{Get the type of the hook.string}
Definition: Hook.php:49
$data value
Definition: default.php:27
setValue($value)
Update the value.
Definition: Hook.php:68
getValue()
{Get the current value of the hook.mixed}
Definition: Hook.php:56
getParam($key, $default=null)
{Get an element of the params array.If the params array is not an array, the default will always be r...
Definition: Hook.php:82
elgg()
{Get the DI container.PublicContainer}
Definition: Hook.php:115
getName()
{Get the name of the hook.string}
Definition: Hook.php:42
Models an event passed to hook handlers.
Definition: Hook.php:12
getParams()
{Get the parameters passed to the trigger call.mixed}
Definition: Hook.php:75
The object passed to invokable class name handlers.
Definition: Hook.php:12
getEntityParam()
{Gets the "entity" key from the params if it holds an Elgg entity.|null}
Definition: Hook.php:93
$default
Definition: checkbox.php:35
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
Definition: summary.php:55
$site name
getUserParam()
{Gets the "user" key from the params if it holds an Elgg user.|null}
Definition: Hook.php:104
__construct(PublicContainer $dic, $name, $type, $value, $params)
Constructor.
Definition: Hook.php:31