public function addNotificationListener($notification_type, $notification_callback)
    {
        if (!NotificationType::isNotificationTypeValid($notification_type)) {
            $this->_logger->log(Logger::ERROR, "Invalid notification type.");
            $this->_errorHandler->handleError(new InvalidNotificationTypeException('Invalid notification type.'));
            return null;
        }

        if (!is_callable($notification_callback)) {
            $this->_logger->log(Logger::ERROR, "Invalid notification callback.");
            return null;
        }

        foreach (array_values($this->_notifications[$notification_type]) as $callback) {
            if ($notification_callback == $callback) {
                // Note: anonymous methods sent with the same body will be re-added.
                // Only variable and object methods can be checked for duplication
                $this->_logger->log(Logger::DEBUG, "Callback already added for notification type '{$notification_type}'.");
                return -1;
            }
        }

        $this->_notifications[$notification_type][$this->_notificationId] = $notification_callback;
        $this->_logger->log(Logger::INFO, "Callback added for notification type '{$notification_type}'.");
        $returnVal = $this->_notificationId++;
        return $returnVal;
    }
public function addNotificationListener($notification_type, $notification_callback)
    {
        if (!NotificationType::isNotificationTypeValid($notification_type)) {
            $this->_logger->log(Logger::ERROR, "Invalid notification type.");
            $this->_errorHandler->handleError(new InvalidNotificationTypeException('Invalid notification type.'));
            return null;
        }

        if (!is_callable($notification_callback)) {
            $this->_logger->log(Logger::ERROR, "Invalid notification callback.");
            return null;
        }

        foreach (array_values($this->_notifications[$notification_type]) as $callback) {
            if ($notification_callback == $callback) {
                // Note: anonymous methods sent with the same body will be re-added.
                // Only variable and object methods can be checked for duplication
                $this->_logger->log(Logger::DEBUG, "Callback already added for notification type '{$notification_type}'.");
                return -1;
            }
        }

        $this->_notifications[$notification_type][$this->_notificationId] = $notification_callback;
        $this->_logger->log(Logger::INFO, "Callback added for notification type '{$notification_type}'.");
        $returnVal = $this->_notificationId++;
        return $returnVal;
    }
public function addNotificationListener ( $ notification_type , $ notification_callback ) { if ( ! NotificationType :: isNotificationTypeValid ( $ notification_type ) ) { $ this -> _logger -> log ( Logger :: ERROR , "Invalid notification type." ) ; $ this -> _errorHandler -> handleError ( new InvalidNotificationTypeException ( 'Invalid notification type.' ) ) ; return null ; } if ( ! is_callable ( $ notification_callback ) ) { $ this -> _logger -> log ( Logger :: ERROR , "Invalid notification callback." ) ; return null ; } foreach ( array_values ( $ this -> _notifications [ $ notification_type ] ) as $ callback ) { if ( $ notification_callback == $ callback ) { // Note: anonymous methods sent with the same body will be re-added. // Only variable and object methods can be checked for duplication $ this -> _logger -> log ( Logger :: DEBUG , "Callback already added for notification type '{$notification_type}'." ) ; return - 1 ; } } $ this -> _notifications [ $ notification_type ] [ $ this -> _notificationId ] = $ notification_callback ; $ this -> _logger -> log ( Logger :: INFO , "Callback added for notification type '{$notification_type}'." ) ; $ returnVal = $ this -> _notificationId ++ ; return $ returnVal ; }
Adds a notification callback for a notification type to the notification center

@param string   $notification_type     One of the constants defined in NotificationType
@param callable $notification_callback A valid PHP callback

@return null  Given invalid notification type/callback
-1    Given callback has been already added
int   Notification ID for the added callback
Adds a notification callback for a notification type to the notification center