Namespaces

  • Latte
    • Loaders
    • Macros
    • Runtime
  • Nette
    • Application
      • Responses
      • Routers
      • UI
    • Bridges
      • ApplicationDI
      • ApplicationLatte
      • ApplicationTracy
      • CacheDI
      • CacheLatte
      • DatabaseDI
      • DatabaseTracy
      • DITracy
      • FormsDI
      • FormsLatte
      • Framework
      • HttpDI
      • HttpTracy
      • MailDI
      • ReflectionDI
      • SecurityDI
      • SecurityTracy
    • Caching
      • Storages
    • ComponentModel
    • Database
      • Conventions
      • Drivers
      • Table
    • DI
      • Config
        • Adapters
      • Extensions
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
      • Traits
    • Reflection
    • Security
    • Tokenizer
    • Utils
  • Tracy
    • Bridges
      • Nette
  • none

Classes

  • ArrayHash
  • ArrayList
  • Arrays
  • Callback
  • DateTime
  • FileSystem
  • Finder
  • Html
  • Image
  • Json
  • ObjectHelpers
  • ObjectMixin
  • Paginator
  • Random
  • Reflection
  • SafeStream
  • Strings
  • TokenIterator
  • Tokenizer
  • Validators

Interfaces

  • IHtmlString

Exceptions

  • AssertionException
  • ImageException
  • JsonException
  • RegexpException
  • TokenizerException
  • UnknownImageFileException
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Other releases
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Nette Framework (https://nette.org)
  5:  * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
  6:  */
  7: 
  8: namespace Nette\Utils;
  9: 
 10: use Nette;
 11: 
 12: 
 13: /**
 14:  * Provides the base class for a generic list (items can be accessed by index).
 15:  */
 16: class ArrayList implements \ArrayAccess, \Countable, \IteratorAggregate
 17: {
 18:     use Nette\SmartObject;
 19: 
 20:     private $list = [];
 21: 
 22: 
 23:     /**
 24:      * Returns an iterator over all items.
 25:      * @return \ArrayIterator
 26:      */
 27:     public function getIterator()
 28:     {
 29:         return new \ArrayIterator($this->list);
 30:     }
 31: 
 32: 
 33:     /**
 34:      * Returns items count.
 35:      * @return int
 36:      */
 37:     public function count()
 38:     {
 39:         return count($this->list);
 40:     }
 41: 
 42: 
 43:     /**
 44:      * Replaces or appends a item.
 45:      * @param  int|null
 46:      * @param  mixed
 47:      * @return void
 48:      * @throws Nette\OutOfRangeException
 49:      */
 50:     public function offsetSet($index, $value)
 51:     {
 52:         if ($index !== null && !is_int($index)) {
 53:             trigger_error('Index is not integer.', E_USER_NOTICE);
 54:         }
 55:         if ($index === null) {
 56:             $this->list[] = $value;
 57: 
 58:         } elseif ($index < 0 || $index >= count($this->list)) {
 59:             throw new Nette\OutOfRangeException('Offset invalid or out of range');
 60: 
 61:         } else {
 62:             $this->list[(int) $index] = $value;
 63:         }
 64:     }
 65: 
 66: 
 67:     /**
 68:      * Returns a item.
 69:      * @param  int
 70:      * @return mixed
 71:      * @throws Nette\OutOfRangeException
 72:      */
 73:     public function offsetGet($index)
 74:     {
 75:         if (!is_int($index)) {
 76:             trigger_error('Index is not integer.', E_USER_NOTICE);
 77:         }
 78:         if ($index < 0 || $index >= count($this->list)) {
 79:             throw new Nette\OutOfRangeException('Offset invalid or out of range');
 80:         }
 81:         return $this->list[(int) $index];
 82:     }
 83: 
 84: 
 85:     /**
 86:      * Determines whether a item exists.
 87:      * @param  int
 88:      * @return bool
 89:      */
 90:     public function offsetExists($index)
 91:     {
 92:         return $index >= 0 && $index < count($this->list);
 93:     }
 94: 
 95: 
 96:     /**
 97:      * Removes the element at the specified position in this list.
 98:      * @param  int
 99:      * @return void
100:      * @throws Nette\OutOfRangeException
101:      */
102:     public function offsetUnset($index)
103:     {
104:         if (!is_int($index)) {
105:             trigger_error('Index is not integer.', E_USER_NOTICE);
106:         }
107:         if ($index < 0 || $index >= count($this->list)) {
108:             throw new Nette\OutOfRangeException('Offset invalid or out of range');
109:         }
110:         array_splice($this->list, (int) $index, 1);
111:     }
112: 
113: 
114:     /**
115:      * Prepends a item.
116:      * @param  mixed
117:      * @return void
118:      */
119:     public function prepend($value)
120:     {
121:         $first = array_slice($this->list, 0, 1);
122:         $this->offsetSet(0, $value);
123:         array_splice($this->list, 1, 0, $first);
124:     }
125: }
126: 
Nette 2.4-20180918 API API documentation generated by ApiGen 2.8.0