Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are 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
 */

/**
 * List of namespaces.
 *
 * @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.21.0
 */
class Horde_Imap_Client_Namespace_List
implements ArrayAccess, Countable, IteratorAggregate
{
    /**
     * The list of namespace objects.
     *
     * @var array
     */
    protected $_ns = array();

    /**
     * Constructor.
     *
     * @param array $ns  The list of namespace objects.
     */
    public function __construct($ns = array())
    {
        foreach ($ns as $val) {
            $this->_ns[strval($val)] = $val;
        }
    }

    /**
     * Get namespace info for a full mailbox path.
     *
     * @param string $mbox       The mailbox path.
     * @param boolean $personal  If true, will return the empty namespace only
     *                           if it is a personal namespace.
     *
     * @return mixed  The Horde_Imap_Client_Data_Namespace object for the
     *                mailbox path, or null if the path doesn't exist.
     */
    public function getNamespace($mbox, $personal = false)
    {
        $mbox = strval($mbox);

        if ($ns = $this[$mbox]) {
            return $ns;
        }

        foreach ($this->_ns as $val) {
            $mbox = $mbox . $val->delimiter;
            if (strlen($val->name) && (strpos($mbox, $val->name) === 0)) {
                return $val;
            }
        }

        return (($ns = $this['']) && (!$personal || ($ns->type === $ns::NS_PERSONAL)))
            ? $ns
            : null;
    }

    /* ArrayAccess methods. */

    /**
     */
> #[ReturnTypeWillChange]
public function offsetExists($offset) { return isset($this->_ns[strval($offset)]); } /** */
> #[ReturnTypeWillChange]
public function offsetGet($offset) { $offset = strval($offset); return isset($this->_ns[$offset]) ? $this->_ns[$offset] : null; } /** */
> #[ReturnTypeWillChange]
public function offsetSet($offset, $value) { if ($value instanceof Horde_Imap_Client_Data_Namespace) { $this->_ns[strval($value)] = $value; } } /** */
> #[ReturnTypeWillChange]
public function offsetUnset($offset) { unset($this->_ns[strval($offset)]); } /* Countable methods. */ /** */
> #[ReturnTypeWillChange]
public function count() { return count($this->_ns); } /* IteratorAggregate methods. */ /** */
> #[ReturnTypeWillChange]
public function getIterator() { return new ArrayIterator($this->_ns); } }