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.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401]

   1  <?php
   2  /**
   3   * Copyright 2014-2017 Horde LLC (http://www.horde.org/)
   4   *
   5   * See the enclosed file LICENSE for license information (LGPL). If you
   6   * did not receive this file, see http://www.horde.org/licenses/lgpl21.
   7   *
   8   * @category  Horde
   9   * @copyright 2014-2017 Horde LLC
  10   * @license   http://www.horde.org/licenses/lgpl21 LGPL 2.1
  11   * @package   Imap_Client
  12   */
  13  
  14  /**
  15   * Handle IMAP alerts sent from the server.
  16   *
  17   * @author    Michael Slusarz <slusarz@horde.org>
  18   * @category  Horde
  19   * @copyright 2014-2017 Horde LLC
  20   * @license   http://www.horde.org/licenses/lgpl21 LGPL 2.1
  21   * @package   Imap_Client
  22   * @since     2.24.0
  23   */
  24  class Horde_Imap_Client_Base_Alerts
  25  implements SplSubject
  26  {
  27      /**
  28       * Alert data.
  29       *
  30       * @var object
  31       */
  32      protected $_alert;
  33  
  34      /**
  35       * Observers.
  36       *
  37       * @var array
  38       */
  39      protected $_observers = array();
  40  
  41      /**
  42       * Add an alert.
  43       *
  44       * @param string $alert  The alert string.
  45       * @param string $type   The alert type.
  46       */
  47      public function add($alert, $type = null)
  48      {
  49          $this->_alert = new stdClass;
  50          $this->_alert->alert = $alert;
  51          if (!is_null($type)) {
  52              $this->_alert->type = $type;
  53          }
  54  
  55          $this->notify();
  56      }
  57  
  58      /**
  59       * Returns the last alert received.
  60       *
  61       * @return object  Alert information. Object with these properties:
  62       * <pre>
  63       *   - alert: (string) Alert string.
  64       *   - type: (string) [OPTIONAL] Alert type.
  65       * </pre>
  66       */
  67      public function getLast()
  68      {
  69          return $this->_alert;
  70      }
  71  
  72      /* SplSubject methods. */
  73  
  74      /**
  75       */
  76      #[ReturnTypeWillChange]
  77      public function attach(SplObserver $observer)
  78      {
  79          $this->detach($observer);
  80          $this->_observers[] = $observer;
  81      }
  82  
  83      /**
  84       */
  85      #[ReturnTypeWillChange]
  86      public function detach(SplObserver $observer)
  87      {
  88          if (($key = array_search($observer, $this->_observers, true)) !== false) {
  89              unset($this->_observers[$key]);
  90          }
  91      }
  92  
  93      /**
  94       * Notification is triggered internally whenever the object's internal
  95       * data storage is altered.
  96       */
  97      #[ReturnTypeWillChange]
  98      public function notify()
  99      {
 100          foreach ($this->_observers as $val) {
 101              $val->update($this);
 102          }
 103      }
 104  
 105  }