Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
<?php
/**
 * Copyright 2014-2017 Horde LLC (http://www.horde.org/)
 *
 * See the enclosed file LICENSE for license information (LGPL). If you
 * did not receive this file, see http://www.horde.org/licenses/lgpl21.
 *
 * @category  Horde
 * @copyright 2014-2017 Horde LLC
 * @license   http://www.horde.org/licenses/lgpl21 LGPL 2.1
 * @package   Imap_Client
 */

/**
 * Handle IMAP alerts sent from the server.
 *
 * @author    Michael Slusarz <slusarz@horde.org>
 * @category  Horde
 * @copyright 2014-2017 Horde LLC
 * @license   http://www.horde.org/licenses/lgpl21 LGPL 2.1
 * @package   Imap_Client
 * @since     2.24.0
 */
class Horde_Imap_Client_Base_Alerts
implements SplSubject
{
    /**
     * Alert data.
     *
     * @var object
     */
    protected $_alert;

    /**
     * Observers.
     *
     * @var array
     */
    protected $_observers = array();

    /**
     * Add an alert.
     *
     * @param string $alert  The alert string.
     * @param string $type   The alert type.
     */
    public function add($alert, $type = null)
    {
        $this->_alert = new stdClass;
        $this->_alert->alert = $alert;
        if (!is_null($type)) {
            $this->_alert->type = $type;
        }

        $this->notify();
    }

    /**
     * Returns the last alert received.
     *
     * @return object  Alert information. Object with these properties:
     * <pre>
     *   - alert: (string) Alert string.
     *   - type: (string) [OPTIONAL] Alert type.
     * </pre>
     */
    public function getLast()
    {
        return $this->_alert;
    }

    /* SplSubject methods. */

    /**
     */
> #[ReturnTypeWillChange]
public function attach(SplObserver $observer) { $this->detach($observer); $this->_observers[] = $observer; } /** */
> #[ReturnTypeWillChange]
public function detach(SplObserver $observer) { if (($key = array_search($observer, $this->_observers, true)) !== false) { unset($this->_observers[$key]); } } /** * Notification is triggered internally whenever the object's internal * data storage is altered. */
> #[ReturnTypeWillChange]
public function notify() { foreach ($this->_observers as $val) { $val->update($this); } } }