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   * List of namespaces.
  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.21.0
  23   */
  24  class Horde_Imap_Client_Namespace_List
  25  implements ArrayAccess, Countable, IteratorAggregate
  26  {
  27      /**
  28       * The list of namespace objects.
  29       *
  30       * @var array
  31       */
  32      protected $_ns = array();
  33  
  34      /**
  35       * Constructor.
  36       *
  37       * @param array $ns  The list of namespace objects.
  38       */
  39      public function __construct($ns = array())
  40      {
  41          foreach ($ns as $val) {
  42              $this->_ns[strval($val)] = $val;
  43          }
  44      }
  45  
  46      /**
  47       * Get namespace info for a full mailbox path.
  48       *
  49       * @param string $mbox       The mailbox path.
  50       * @param boolean $personal  If true, will return the empty namespace only
  51       *                           if it is a personal namespace.
  52       *
  53       * @return mixed  The Horde_Imap_Client_Data_Namespace object for the
  54       *                mailbox path, or null if the path doesn't exist.
  55       */
  56      public function getNamespace($mbox, $personal = false)
  57      {
  58          $mbox = strval($mbox);
  59  
  60          if ($ns = $this[$mbox]) {
  61              return $ns;
  62          }
  63  
  64          foreach ($this->_ns as $val) {
  65              $mbox = $mbox . $val->delimiter;
  66              if (strlen($val->name) && (strpos($mbox, $val->name) === 0)) {
  67                  return $val;
  68              }
  69          }
  70  
  71          return (($ns = $this['']) && (!$personal || ($ns->type === $ns::NS_PERSONAL)))
  72              ? $ns
  73              : null;
  74      }
  75  
  76      /* ArrayAccess methods. */
  77  
  78      /**
  79       */
  80      #[ReturnTypeWillChange]
  81      public function offsetExists($offset)
  82      {
  83          return isset($this->_ns[strval($offset)]);
  84      }
  85  
  86      /**
  87       */
  88      #[ReturnTypeWillChange]
  89      public function offsetGet($offset)
  90      {
  91          $offset = strval($offset);
  92  
  93          return isset($this->_ns[$offset])
  94              ? $this->_ns[$offset]
  95              : null;
  96      }
  97  
  98      /**
  99       */
 100      #[ReturnTypeWillChange]
 101      public function offsetSet($offset, $value)
 102      {
 103          if ($value instanceof Horde_Imap_Client_Data_Namespace) {
 104              $this->_ns[strval($value)] = $value;
 105          }
 106      }
 107  
 108      /**
 109       */
 110      #[ReturnTypeWillChange]
 111      public function offsetUnset($offset)
 112      {
 113          unset($this->_ns[strval($offset)]);
 114      }
 115  
 116      /* Countable methods. */
 117  
 118      /**
 119       */
 120      #[ReturnTypeWillChange]
 121      public function count()
 122      {
 123          return count($this->_ns);
 124      }
 125  
 126      /* IteratorAggregate methods. */
 127  
 128      /**
 129       */
 130      #[ReturnTypeWillChange]
 131      public function getIterator()
 132      {
 133          return new ArrayIterator($this->_ns);
 134      }
 135  
 136  }