forked from blesta/plugin-domains
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdomains_model.php
More file actions
57 lines (48 loc) · 1.82 KB
/
domains_model.php
File metadata and controls
57 lines (48 loc) · 1.82 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
<?php
use Blesta\Core\Util\Events\EventFactory;
/**
* Domain Manager Parent Model
*
* @link https://www.blesta.com Blesta
*/
class DomainsModel extends AppModel
{
/**
* Initialize the Domains plugin model.
*/
public function __construct()
{
parent::__construct();
// Auto load language for these models
Language::loadLang([Loader::fromCamelCase(get_class($this))], null, dirname(__FILE__) . DS . 'language' . DS);
}
/**
* Triggers a plugin event
*
* @param string $name The name of the event to trigger
* @param array $params An array of parameters to be held by this event (optional)
* @return array The list of parameters that were submitted along with any modifications made to them
* by the event handlers. In addition a __return__ item is included with the return array from the event.
*/
public function triggerEvent($name, array $params = [])
{
Loader::load(dirname(__FILE__) . DS . 'domains_observer.php');
$eventFactory = new EventFactory();
$eventListener = $eventFactory->listener();
$eventListener->register('Domains.' . $name, ['DomainsObserver', $name]);
$event = $eventListener->trigger($eventFactory->event('Domains.' . $name, $params));
// Get the event return value
$returnValue = $event->getReturnValue();
// Put return in a special index
$return = ['__return__' => $returnValue];
// Any return values that match the submitted params should be put in their own index to support extract() calls
if (is_array($returnValue)) {
foreach ($returnValue as $key => $data) {
if (array_key_exists($key, $params)) {
$return[$key] = $data;
}
}
}
return $return;
}
}