Example #1
0
 public function offsetSet($key, $value)
 {
     if (!$value instanceof Field) {
         throw new \InvalidArgumentException('$value must be an instance of ' . Field::class);
     }
     return parent::offsetSet($key, $value);
 }
Example #2
0
 /**
  * @param int|string $offset
  *
  * @return mixed
  */
 public function offsetGet($offset)
 {
     if (!$this->offsetExists($offset)) {
         $class = __NAMESPACE__ . '\\' . $this->type . 'Model';
         $item = new $class(array($this->parentId, $offset), 'id');
         parent::offsetSet($offset, $item);
     }
     return parent::offsetGet($offset);
 }
Example #3
0
 /**
  * Appends the specified element to the end of this collection.
  * @param  mixed
  * @return bool  true if this collection changed as a result of the call
  * @throws InvalidArgumentException, \NotSupportedException
  */
 public function append($item)
 {
     $this->beforeAdd($item);
     if (is_object($item)) {
         $key = spl_object_hash($item);
         if (parent::offsetExists($key)) {
             return FALSE;
         }
         parent::offsetSet($key, $item);
         return TRUE;
     } else {
         $key = $this->search($item);
         if ($key === FALSE) {
             parent::offsetSet(NULL, $item);
             return TRUE;
         }
         return FALSE;
     }
 }
Example #4
0
 /**
  * Replaces (or appends) the item (\ArrayAccess implementation).
  * @param  int index
  * @param  object
  * @return void
  * @throws InvalidArgumentException, \NotSupportedException, \ArgumentOutOfRangeException
  */
 public function offsetSet($index, $item)
 {
     $this->beforeAdd($item);
     if ($index === NULL) {
         // append
         parent::offsetSet(NULL, $item);
     } else {
         // replace
         $index -= $this->base;
         if ($index < 0 || $index >= count($this)) {
             throw new ArgumentOutOfRangeException();
         }
         parent::offsetSet($index, $item);
     }
 }
Example #5
0
 /**
  * Inserts (replaces) item (\ArrayAccess implementation).
  * @param  string key
  * @param  object
  * @return void
  * @throws NotSupportedException, \InvalidArgumentException
  */
 public function offsetSet($key, $item)
 {
     if (!is_scalar($key)) {
         // prevents NULL
         throw new InvalidArgumentException("Key must be either a string or an integer, " . gettype($key) . " given.");
     }
     $this->beforeAdd($item);
     parent::offsetSet($key, $item);
 }
Example #6
0
 public function offsetSet($offset, $value)
 {
     $this->load();
     parent::offsetSet($offset, $value);
 }
Example #7
0
 /**
  * Replaces (or appends) the item (ArrayAccess implementation).
  * @param  int index
  * @param  object
  * @return void
  * @throws InvalidArgumentException, NotSupportedException, ArgumentOutOfRangeException
  */
 public function offsetSet($index, $item)
 {
     // collection was not loaded before, now it is only manualy set collection
     if (!$this->isLoaded()) {
         $this->loadable = false;
     }
     return parent::offsetSet($index, $item);
 }
Example #8
0
 public function offsetSet($index, $newval)
 {
     $this->collection->offsetSet($index, $newval);
     parent::offsetSet($index, $newval);
     $this->refreshPositions();
 }