[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/horde/framework/Horde/Support/ -> CaseInsensitiveArray.php (source)

   1  <?php
   2  /**
   3   * Copyright 2013-2014 Horde LLC (http://www.horde.org/)
   4   *
   5   * See the enclosed file COPYING for license information (BSD). If you
   6   * did not receive this file, see http://www.horde.org/licenses/bsd.
   7   *
   8   * @category  Horde
   9   * @copyright 2013-2014 Horde LLC
  10   * @license   http://www.horde.org/licenses/bsd BSD
  11   * @package   Support
  12   */
  13  
  14  /**
  15   * An array implemented as an object that contains case-insensitive keys.
  16   *
  17   * @author    Michael Slusarz <slusarz@horde.org>
  18   * @category  Horde
  19   * @copyright 2013-2014 Horde LLC
  20   * @license   http://www.horde.org/licenses/bsd BSD
  21   * @package   Support
  22   */
  23  class Horde_Support_CaseInsensitiveArray extends ArrayIterator
  24  {
  25      /**
  26       */
  27      public function offsetGet($offset)
  28      {
  29          return (is_null($offset = $this->_getRealOffset($offset)))
  30              ? null
  31              : parent::offsetGet($offset);
  32      }
  33  
  34      /**
  35       */
  36      public function offsetSet($offset, $value)
  37      {
  38          if (is_null($roffset = $this->_getRealOffset($offset))) {
  39              parent::offsetSet($offset, $value);
  40          } else {
  41              parent::offsetSet($roffset, $value);
  42          }
  43      }
  44  
  45      /**
  46       */
  47      public function offsetExists($offset)
  48      {
  49          return (is_null($offset = $this->_getRealOffset($offset)))
  50              ? false
  51              : parent::offsetExists($offset);
  52      }
  53  
  54      /**
  55       */
  56      public function offsetUnset($offset)
  57      {
  58          if (!is_null($offset = $this->_getRealOffset($offset))) {
  59              parent::offsetUnset($offset);
  60          }
  61      }
  62  
  63      /**
  64       * Determines the actual array offset given the input offset.
  65       *
  66       * @param string $offset  Input offset.
  67       *
  68       * @return string  Real offset or null.
  69       */
  70      protected function _getRealOffset($offset)
  71      {
  72          foreach (array_keys($this->getArrayCopy()) as $key) {
  73              if (strcasecmp($key, $offset) === 0) {
  74                  return $key;
  75              }
  76          }
  77  
  78          return null;
  79      }
  80  
  81  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1