symphonycms /
symphony-2
| 1 | <?php |
||||
| 2 | /** |
||||
| 3 | * @package toolkit |
||||
| 4 | */ |
||||
| 5 | |||||
| 6 | /** |
||||
| 7 | * The abstract Event classes defines some base methods that all Events inherit. |
||||
| 8 | * It has one abstract method, `__trigger()`, which Events must implement. Event |
||||
| 9 | * execution is determined based on an action (which maps to a form action |
||||
| 10 | * from the Frontend). A load function determines whether this Event matches |
||||
| 11 | * the action and if so, call the Event's `__trigger()` to run the logic. On every page |
||||
| 12 | * load, all Event's that are attached to the page will have their load function's executed. |
||||
| 13 | * Events are called in order of their priority and if there is more than one event |
||||
| 14 | * with the same priority, in alphabetical order. An event class is saved through the |
||||
| 15 | * Symphony backend, which uses an event template defined in `TEMPLATE . /event.tpl` |
||||
| 16 | * Events implement the iEvent interface, which defines the load and about functions. |
||||
| 17 | */ |
||||
| 18 | abstract class Event |
||||
| 19 | { |
||||
| 20 | /** |
||||
| 21 | * Represents High Priority, that this event should run first |
||||
| 22 | * @var integer |
||||
| 23 | */ |
||||
| 24 | const kHIGH = 3; |
||||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||||
| 25 | |||||
| 26 | /** |
||||
| 27 | * Represents Normal Priority, that this event should run normally. |
||||
| 28 | * This is the default Event Priority |
||||
| 29 | * @var integer |
||||
| 30 | */ |
||||
| 31 | const kNORMAL = 2; |
||||
|
0 ignored issues
–
show
|
|||||
| 32 | |||||
| 33 | /** |
||||
| 34 | * Represents High Priority, that this event should run last |
||||
| 35 | * @var integer |
||||
| 36 | */ |
||||
| 37 | const kLOW = 1; |
||||
|
0 ignored issues
–
show
|
|||||
| 38 | |||||
| 39 | /** |
||||
| 40 | * Holds all the environment variables which include parameters set |
||||
| 41 | * by other Datasources or Events. |
||||
| 42 | * @var array |
||||
| 43 | */ |
||||
| 44 | protected $_env = array(); |
||||
| 45 | |||||
| 46 | /** |
||||
| 47 | * The constructor for an Event sets `$this->_env` from the given parameters |
||||
| 48 | * |
||||
| 49 | * @param array $env |
||||
| 50 | * The environment variables from the Frontend class which includes |
||||
| 51 | * any params set by Symphony or Datasources or by other Events |
||||
| 52 | */ |
||||
| 53 | public function __construct(array $env = null) |
||||
|
0 ignored issues
–
show
|
|||||
| 54 | { |
||||
| 55 | $this->_env = $env; |
||||
| 56 | } |
||||
| 57 | |||||
| 58 | /** |
||||
| 59 | * This function is required in order to edit it in the event editor page. |
||||
| 60 | * Do not overload this function if you are creating a custom event. It is only |
||||
| 61 | * used by the event editor. |
||||
| 62 | * |
||||
| 63 | * @return boolean |
||||
| 64 | * true if event can be edited, false otherwise. Defaults to false |
||||
| 65 | */ |
||||
| 66 | public static function allowEditorToParse() |
||||
| 67 | { |
||||
| 68 | return false; |
||||
| 69 | } |
||||
| 70 | |||||
| 71 | /** |
||||
| 72 | * This function is required in order to identify what section this event is for. It |
||||
| 73 | * is used in the event editor. It must remain intact. Do not overload this function in |
||||
| 74 | * custom events. |
||||
| 75 | * |
||||
| 76 | * @return integer |
||||
| 77 | */ |
||||
| 78 | public static function getSource() |
||||
| 79 | { |
||||
| 80 | return null; |
||||
| 81 | } |
||||
| 82 | |||||
| 83 | /** |
||||
| 84 | * Returns a string of HTML or an XMLElement of documentation for the current event. |
||||
| 85 | * By default this will be an example of a HTML form that can populate the chosen section and |
||||
| 86 | * any filter information. Documentation is shown in the Symphony backend when a user tries to |
||||
| 87 | * edit an event but it's `allowEditorToParse()` returns `false`. If this is not implemented by |
||||
| 88 | * the event, a default Symphony message will appear. |
||||
| 89 | * |
||||
| 90 | * @return string|XMLElement |
||||
| 91 | */ |
||||
| 92 | public static function documentation() |
||||
| 93 | { |
||||
| 94 | return __('This event has been customised and cannot be viewed from Symphony.'); |
||||
| 95 | } |
||||
| 96 | |||||
| 97 | /** |
||||
| 98 | * Returns the path to the email-notification-template by looking at the |
||||
| 99 | * `WORKSPACE/template/` directory, then at the `TEMPLATES` |
||||
| 100 | * directory for the convention `notification.*.tpl`. If the template |
||||
| 101 | * is not found, false is returned |
||||
| 102 | * |
||||
| 103 | * @param string $language |
||||
| 104 | * Language used in system |
||||
| 105 | * @return mixed |
||||
| 106 | * String, which is the path to the template if the template is found, |
||||
| 107 | * false otherwise |
||||
| 108 | */ |
||||
| 109 | public static function getNotificationTemplate($language) |
||||
| 110 | { |
||||
| 111 | $langformat = '%s/email.entrycreated.%s.tpl'; |
||||
| 112 | $defaultformat = '%s/email.entrycreated.tpl'; |
||||
| 113 | |||||
| 114 | if (file_exists($template = sprintf($langformat, WORKSPACE . '/template', $language))) { |
||||
|
0 ignored issues
–
show
|
|||||
| 115 | return $template; |
||||
| 116 | } elseif (file_exists($template = sprintf($defaultformat, WORKSPACE . '/template'))) { |
||||
| 117 | return $template; |
||||
| 118 | } elseif (file_exists($template = sprintf($langformat, TEMPLATE, $language))) { |
||||
|
0 ignored issues
–
show
|
|||||
| 119 | return $template; |
||||
| 120 | } elseif (file_exists($template = sprintf($defaultformat, TEMPLATE))) { |
||||
| 121 | return $template; |
||||
| 122 | } else { |
||||
| 123 | return false; |
||||
| 124 | } |
||||
| 125 | } |
||||
| 126 | |||||
| 127 | |||||
| 128 | /** |
||||
| 129 | * Priority determines Event importance and when it should be executed. |
||||
| 130 | * The default priority for an event is `Event::kNORMAL`, with `Event::kHIGH` and |
||||
| 131 | * `Event::kLOW` being the other available options. Events execution is `Event::kHIGH` |
||||
| 132 | * to `Event::kNORMAL` to `Event::kLOW`. If there are more than one event at the |
||||
| 133 | * same priority level, they are sorted alphabetically by event handle and executed |
||||
| 134 | * in that order for that priority. |
||||
| 135 | * |
||||
| 136 | * @see toolkit.FrontendPage#__findEventOrder() |
||||
| 137 | * @return integer |
||||
| 138 | * The available constants are `Event::kLOW`, `Event::kNORMAL` and `Event::kHIGH`. |
||||
| 139 | * Defaults to `Event::kNORMAL` |
||||
| 140 | */ |
||||
| 141 | public function priority() |
||||
| 142 | { |
||||
| 143 | return self::kNORMAL; |
||||
|
0 ignored issues
–
show
|
|||||
| 144 | } |
||||
| 145 | |||||
| 146 | /** |
||||
| 147 | * This function must be included in an event. The purpose of this function |
||||
| 148 | * is to define the logic of this particular event. It assumes that this event |
||||
| 149 | * has already been triggered from the load function |
||||
| 150 | * |
||||
| 151 | * @since Symphony 2.3 |
||||
| 152 | * @return XMLElement |
||||
| 153 | * Returns an `XMLElement` with the event information (success or failure included) |
||||
| 154 | */ |
||||
| 155 | protected function __trigger() |
||||
| 156 | { |
||||
| 157 | return $this->execute(); |
||||
|
0 ignored issues
–
show
The method
execute() does not exist on Event. Are you sure you never get this type here, but always one of the subclasses?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 158 | } |
||||
| 159 | } |
||||
| 160 |