Elgg\EventsService::trigger PHP Method

trigger() public method

Triggers an Elgg event.
See also: elgg_trigger_event
See also: elgg_trigger_after_event
public trigger ( $event, $type, $object = null, array $options = [] )
$options array
    public function trigger($event, $type, $object = null, array $options = array())
    {
        $options = array_merge(array(self::OPTION_STOPPABLE => true, self::OPTION_DEPRECATION_MESSAGE => '', self::OPTION_DEPRECATION_VERSION => ''), $options);
        $events = $this->hasHandler($event, $type);
        if ($events && $options[self::OPTION_DEPRECATION_MESSAGE]) {
            elgg_deprecated_notice($options[self::OPTION_DEPRECATION_MESSAGE], $options[self::OPTION_DEPRECATION_VERSION], 2);
        }
        $events = $this->getOrderedHandlers($event, $type);
        $args = array($event, $type, $object);
        foreach ($events as $callback) {
            if (!is_callable($callback)) {
                if ($this->logger) {
                    $this->logger->warn("handler for event [{$event}, {$type}] is not callable: " . $this->inspector->describeCallable($callback));
                }
                continue;
            }
            if ($this->timer && $type === 'system' && $event !== 'shutdown') {
                $callback_as_string = $this->inspector->describeCallable($callback) . "()";
                $this->timer->begin(["[{$event},{$type}]", $callback_as_string]);
                $return = call_user_func_array($callback, $args);
                $this->timer->end(["[{$event},{$type}]", $callback_as_string]);
            } else {
                $return = call_user_func_array($callback, $args);
            }
            if (!empty($options[self::OPTION_STOPPABLE]) && $return === false) {
                return false;
            }
        }
        return true;
    }

Usage Example

コード例 #1
0
ファイル: Annotations.php プロジェクト: elgg/elgg
 /**
  * Update an annotation.
  *
  * @param int    $annotation_id Annotation ID
  * @param string $name          Name of annotation
  * @param string $value         Value of annotation
  * @param string $value_type    Type of value
  * @param int    $owner_guid    Owner of annotation
  * @param int    $access_id     Access level of annotation
  *
  * @return bool
  */
 function update($annotation_id, $name, $value, $value_type, $owner_guid, $access_id)
 {
     $annotation_id = (int) $annotation_id;
     $annotation = $this->get($annotation_id);
     if (!$annotation) {
         return false;
     }
     if (!$annotation->canEdit()) {
         return false;
     }
     $name = trim($name);
     $value_type = detect_extender_valuetype($value, $value_type);
     $owner_guid = (int) $owner_guid;
     if ($owner_guid == 0) {
         $owner_guid = $this->session->getLoggedInUserGuid();
     }
     $access_id = (int) $access_id;
     $sql = "UPDATE {$this->db->prefix}annotations\n\t\t\t(name, value, value_type, access_id, owner_guid)\n\t\t\tVALUES\n\t\t\t(:name, :value, :value_type, :access_id, :owner_guid)\n\t\t\tWHERE id = :annotation_id";
     $result = $this->db->updateData($sql, false, [':name' => $name, ':value' => $value, ':value_type' => $value_type, ':access_id' => $access_id, ':owner_guid' => $owner_guid, ':annotation_id' => $annotation_id]);
     if ($result !== false) {
         // @todo add plugin hook that sends old and new annotation information before db access
         $obj = $this->get($annotation_id);
         $this->events->trigger('update', 'annotation', $obj);
     }
     return $result;
 }
All Usage Examples Of Elgg\EventsService::trigger