Ejemplo n.º 1
0
 /**
  * Inserts an assoc element to container
  *
  * @param string  $key
  * @param mixed   $value
  * @param integer $pos
  *
  * @return DataContainer
  *
  * @throws RuntimeException
  */
 public function insertAssoc($key, $value, $pos = null)
 {
     if ($pos === null) {
         $this->set($key, $value);
     } else {
         if ($this->readOnly) {
             throw new \RuntimeException('Changing values on this Data Container is not allowed.');
         }
         $this->isModified = true;
         if (abs($pos) > count($this->data)) {
             $pos = count($this->data) * min(1, max(-1, $pos));
         }
         if ($key === null) {
             Arr::insert($this->data, $value, $pos);
         } else {
             Arr::insertAssoc($this->data, array($key => $value), $pos);
         }
     }
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * @covers Fuel\Common\Arr::insert
  * @expectedException  \InvalidArgumentException
  * @group Common
  */
 public function testInsertException()
 {
     $people = array("Jack", "Jill");
     Arr::insert($people, "something", 5);
 }