Prado\TComponent::raiseEvent PHP Метод

raiseEvent() публичный Метод

This method represents the happening of an event and will invoke all attached event handlers for the event in {@link TPriorityList} order. This method does not handle intra-object/behavior dynamic 'dy' events. There are ways to handle event responses. By defailt {@link EVENT_RESULT_FILTER}, all event responses are stored in an array, filtered for null responses, and returned. If {@link EVENT_RESULT_ALL} is specified, all returned results will be stored along with the sender and param in an array $result[] = array('sender'=>$sender,'param'=>$param,'response'=>$response); If {@link EVENT_RESULT_FEED_FORWARD} is specified, then each handler result is then fed forward as the parameters for the next event. This allows for events to filter data directly by affecting the event parameters If a callable function is set in the response type or the post function filter is specified then the result of each called event handler is post processed by the callable function. Used in combination with {@link EVENT_RESULT_FEED_FORWARD}, any event (and its result) can be chained. When raising a global 'fx' event, registered handlers in the global event list for {@link GLOBAL_RAISE_EVENT_LISTENER} are always added into the set of event handlers. In this way, these global events are always raised for every global 'fx' event. The registered handlers for global raiseEvent events have priorities. Any registered global raiseEvent event handlers with a priority less than zero are added before the main event handlers being raised and any registered global raiseEvent event handlers with a priority equal or greater than zero are added after the main event handlers being raised. In this way all {@link GLOBAL_RAISE_EVENT_LISTENER} handlers are always called for every raised 'fx' event. Behaviors may implement the following functions: public function dyPreRaiseEvent($name,$sender,$param,$responsetype,$postfunction[, $chain]) { return $name; //eg, the event name may be filtered/changed } public function dyIntraRaiseEventTestHandler($handler,$sender,$param,$name[, $chain]) { return true; //should this particular handler be executed? true/false } public function dyIntraRaiseEventPostHandler($name,$sender,$param,$handler,$response[, $chain]) { contains the per handler response } public function dyPostRaiseEvent($responses,$name,$sender,$param,$responsetype,$postfunction[, $chain]) { return $responses; } to be executed when raiseEvent is called. The 'intra' dynamic events are called per handler in the handler loop. dyPreRaiseEvent has the effect of being able to change the event being raised. This intra object/behavior event returns the name of the desired event to be raised. It will pass through if no dynamic event is specified, or if the original event name is returned. dyIntraRaiseEventTestHandler returns true or false as to whether a specific handler should be called for a specific raised event (and associated event arguments) dyIntraRaiseEventPostHandler does not return anything. This allows behaviors to access the results of an event handler in the per handler loop. dyPostRaiseEvent returns the responses. This allows for any post processing of the event results from the sum of all event handlers When handling a catch-all {@link __dycall}, the method name is the name of the event and the parameters are the sender, the param, and then the name of the event.
public raiseEvent ( $name, $sender, $param, $responsetype = null, $postfunction = null ) : mixed
Результат mixed the results of the event
    public function raiseEvent($name, $sender, $param, $responsetype = null, $postfunction = null)
    {
        $p = $param;
        if (is_callable($responsetype)) {
            $postfunction = $responsetype;
            $responsetype = null;
        }
        if ($responsetype === null) {
            $responsetype = TEventResults::EVENT_RESULT_FILTER;
        }
        $name = strtolower($name);
        $responses = array();
        $name = $this->dyPreRaiseEvent($name, $sender, $param, $responsetype, $postfunction);
        if ($this->hasEventHandler($name) || $this->hasEventHandler(TComponent::GLOBAL_RAISE_EVENT_LISTENER)) {
            $handlers = $this->getEventHandlers($name);
            $handlerArray = $handlers->toArray();
            if (strncasecmp($name, 'fx', 2) === 0 && $this->hasEventHandler(TComponent::GLOBAL_RAISE_EVENT_LISTENER)) {
                $globalhandlers = $this->getEventHandlers(TComponent::GLOBAL_RAISE_EVENT_LISTENER);
                $handlerArray = array_merge($globalhandlers->toArrayBelowPriority(0), $handlerArray, $globalhandlers->toArrayAbovePriority(0));
            }
            $response = null;
            foreach ($handlerArray as $handler) {
                if ($this->dyIntraRaiseEventTestHandler($handler, $sender, $param, $name) === false) {
                    continue;
                }
                if (is_string($handler)) {
                    if (($pos = strrpos($handler, '.')) !== false) {
                        $object = $this->getSubProperty(substr($handler, 0, $pos));
                        $method = substr($handler, $pos + 1);
                        if (method_exists($object, $method) || strncasecmp($method, 'dy', 2) === 0 || strncasecmp($method, 'fx', 2) === 0) {
                            if ($method == '__dycall') {
                                $response = $object->__dycall($name, array($sender, $param, $name));
                            } else {
                                $response = $object->{$method}($sender, $param, $name);
                            }
                        } else {
                            throw new TInvalidDataValueException('component_eventhandler_invalid', get_class($this), $name, $handler);
                        }
                    } else {
                        $response = call_user_func($handler, $sender, $param, $name);
                    }
                } else {
                    if (is_callable($handler, true)) {
                        list($object, $method) = $handler;
                        if (is_string($object)) {
                            $response = call_user_func($handler, $sender, $param, $name);
                        } else {
                            if (($pos = strrpos($method, '.')) !== false) {
                                $object = $this->getSubProperty(substr($method, 0, $pos));
                                $method = substr($method, $pos + 1);
                            }
                            if (method_exists($object, $method) || strncasecmp($method, 'dy', 2) === 0 || strncasecmp($method, 'fx', 2) === 0) {
                                if ($method == '__dycall') {
                                    $response = $object->__dycall($name, array($sender, $param, $name));
                                } else {
                                    $response = $object->{$method}($sender, $param, $name);
                                }
                            } else {
                                throw new TInvalidDataValueException('component_eventhandler_invalid', get_class($this), $name, $handler[1]);
                            }
                        }
                    } else {
                        throw new TInvalidDataValueException('component_eventhandler_invalid', get_class($this), $name, gettype($handler));
                    }
                }
                $this->dyIntraRaiseEventPostHandler($name, $sender, $param, $handler, $response);
                if ($postfunction) {
                    $response = call_user_func_array($postfunction, array($sender, $param, $this, $response));
                }
                if ($responsetype & TEventResults::EVENT_RESULT_ALL) {
                    $responses[] = array('sender' => $sender, 'param' => $param, 'response' => $response);
                } else {
                    $responses[] = $response;
                }
                if ($response !== null && $responsetype & TEventResults::EVENT_RESULT_FEED_FORWARD) {
                    $param = $response;
                }
            }
        } else {
            if (strncasecmp($name, 'on', 2) === 0 && !$this->hasEvent($name)) {
                throw new TInvalidOperationException('component_event_undefined', get_class($this), $name);
            }
        }
        if ($responsetype & TEventResults::EVENT_RESULT_FILTER) {
            $responses = array_filter($responses);
        }
        $responses = $this->dyPostRaiseEvent($responses, $name, $sender, $param, $responsetype, $postfunction);
        return $responses;
    }