本文整理汇总了PHP中Collection::offsetSet方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::offsetSet方法的具体用法?PHP Collection::offsetSet怎么用?PHP Collection::offsetSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Collection
的用法示例。
在下文中一共展示了Collection::offsetSet方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: offsetSet
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);
}
示例2: offsetGet
/**
* @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);
}
示例3: append
/**
* 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;
}
}
示例4: offsetSet
/**
* 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);
}
}
示例5: offsetSet
/**
* 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);
}
示例6: offsetSet
public function offsetSet($offset, $value)
{
$this->load();
parent::offsetSet($offset, $value);
}
示例7: offsetSet
/**
* 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);
}
示例8: offsetSet
public function offsetSet($index, $newval)
{
$this->collection->offsetSet($index, $newval);
parent::offsetSet($index, $newval);
$this->refreshPositions();
}