Ejemplo n.º 1
0
 /**
  * Override the DataContainer's set function to enable type checking.
  *
  * @param string $key
  * @param Option $value
  *
  * @return $this
  *
  * @throws InvalidArgumentException
  *
  * @since 2.0
  */
 public function set($key, $value)
 {
     if (!$value instanceof Option) {
         throw new InvalidArgumentException('Only Options can be added to an Optgroup.');
     }
     return parent::set($key, $value);
 }
Ejemplo n.º 2
0
 /**
  * Overrides the set method from DataContainer to ensure only Cells can be added
  *
  * @throws \InvalidArgumentException
  */
 public function set($key, $value)
 {
     if (!$value instanceof Cell) {
         throw new \InvalidArgumentException('Only Cells can be added to Rows');
     }
     parent::set($key, $value);
 }
Ejemplo n.º 3
0
 /**
  * Override the DataContainer's set function to enable type checking.
  *
  * @param  string $key
  * @param  Option|Optgroup $value
  *
  * @return $this
  *
  * @throws \InvalidArgumentException
  *
  * @since 2.0
  */
 public function set($key, $value)
 {
     if (!$value instanceof Option && !$value instanceof Optgroup) {
         throw new \InvalidArgumentException('Only Options or Optgroups can be added to a Select.');
     }
     parent::set($key, $value);
     return $this;
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdocs}
  */
 public function merge($arg)
 {
     $arguments = array_map(function ($array) {
         if ($array instanceof DataContainer) {
             return $array->getContents();
         }
         return $array;
     }, func_get_args());
     $arguments = call_user_func_array('Arr::merge', $arguments);
     $this->validate($arguments);
     return parent::merge($arguments);
 }
Ejemplo n.º 5
0
 /**
  * Deletes data from the container
  *
  * @param string $key
  *
  * @return boolean
  */
 public function delete($key)
 {
     // and delete the key itself
     return parent::delete($this->prefixKey($key));
 }
Ejemplo n.º 6
0
 /**
  * Replaces the container's data
  *
  * @param array $data
  *
  * @throws \RuntimeException
  */
 public function setContents(array $data)
 {
     // make sure we have our expire data key
     if (isset($data[static::EXPIRE_DATA_KEY])) {
         // process the expiration settings
         foreach ($data[static::EXPIRE_DATA_KEY] as $key => $expiration) {
             // if it was set on the last request, make it as loaded
             if ($expiration[1] === static::EXPIRE_STATE_NEW) {
                 $data[static::EXPIRE_DATA_KEY][$key][1] = static::EXPIRE_STATE_LOADED;
             } elseif ($expiration[0] === EXPIRE_ON_REQUEST and $expiration[1] === static::EXPIRE_STATE_LOADED) {
                 unset($data[static::EXPIRE_DATA_KEY][$key]);
                 \Arr::delete($data, $this->prefixKey($key));
             }
         }
     } else {
         // not set, create an empty one to start with
         $data[static::EXPIRE_DATA_KEY] = array();
     }
     // store the data
     parent::setContents($data);
 }
Ejemplo n.º 7
0
 /**
  * Extends DataContainer's set method to ensure only Toggle objects can be added.
  *
  * @param string $key
  * @param mixed  $value
  *
  * @return $this
  *
  * @throws \InvalidArgumentException
  *
  * @since 2.0
  */
 public function set($key, $value)
 {
     if (!$value instanceof Toggle) {
         throw new \InvalidArgumentException('You can only add Toggle objects to a ToggleGroup.');
     }
     return parent::set($key, $value);
 }
Ejemplo n.º 8
0
 /**
  * Sets view data
  *
  * @param string|array $key
  * @param mixed        $value
  * @param boolean      $filter
  *
  * @return $this
  */
 public function set($key, $value = null, $filter = null)
 {
     parent::set($key, $value);
     if (is_array($key)) {
         if (is_bool($value)) {
             $filter = $value;
         }
         foreach ($key as $_key => $_value) {
             $this->filterIndex[$_key] = $filter;
         }
     } else {
         $this->filterIndex[$key] = $filter;
     }
     return $this;
 }
Ejemplo n.º 9
0
 /**
  * @group Common
  */
 public function testParents()
 {
     $p = new DataContainer();
     $c = new DataContainer();
     $this->assertEquals(null, $c->getParent());
     $this->assertFalse($c->hasParent());
     $this->assertEquals($c, $c->setParent($p));
     $this->assertEquals($p, $c->getParent());
     $this->assertTrue($c->hasParent());
     $this->assertEquals($c, $c->disableParent());
     $this->assertFalse($c->hasParent());
     $this->assertEquals($c, $c->enableParent());
     $this->assertTrue($c->hasParent());
     $this->assertEquals($c, $c->setParent(null));
     $this->assertFalse($c->hasParent());
 }
Ejemplo n.º 10
0
 /**
  * The given value must be an instance of the $modelClass
  *
  * @inheritdoc
  */
 public function set($key, $value)
 {
     $targetClass = $this->getModelClass();
     if (!is_object($value) or !$value instanceof $targetClass) {
         $actualClass = gettype($value);
         if (is_object($value)) {
             $actualClass = get_class($value);
         }
         throw new InvalidArgumentException('ORM-005: Invalid model instance. Expecting [' . $this->getModelClass() . '] got [' . $actualClass . ']');
     }
     if ($value->getProvider() === null and $this->getProvider() !== null) {
         $value->setProvider($this->getProvider());
     }
     return parent::set($key, $value);
 }
Ejemplo n.º 11
0
Archivo: Model.php Proyecto: atabak/orm
 /**
  * {@inheritdoc}
  */
 public function get($key = null, $default = null)
 {
     // Check if the property requested is a relation
     if ($this->provider !== null and $this->provider->hasRelation($key)) {
         return $this->loadRelations($key);
     }
     // Not a relation so throw the call up to the parent
     return parent::get($key, $default);
 }