コード例 #1
0
ファイル: Optgroup.php プロジェクト: fuelphp/fieldset
 /**
  * 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);
 }
コード例 #2
0
ファイル: Row.php プロジェクト: fuelphp/common
 /**
  * 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);
 }
コード例 #3
0
ファイル: Select.php プロジェクト: fuelphp/fieldset
 /**
  * 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;
 }
コード例 #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);
 }
コード例 #5
0
ファイル: DataContainer.php プロジェクト: fuelphp/session
 /**
  * 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));
 }
コード例 #6
0
ファイル: FlashContainer.php プロジェクト: fuelphp/session
 /**
  * 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);
 }
コード例 #7
0
ファイル: ToggleGroup.php プロジェクト: fuelphp/fieldset
 /**
  * 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);
 }
コード例 #8
0
ファイル: DataContainer.php プロジェクト: fuelphp/display
 /**
  * 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;
 }
コード例 #9
0
ファイル: DataContainerTest.php プロジェクト: fuelphp/common
 /**
  * @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());
 }
コード例 #10
0
ファイル: ModelCollection.php プロジェクト: atabak/orm
 /**
  * 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);
 }
コード例 #11
0
ファイル: Model.php プロジェクト: 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);
 }