/** * {@inheritdoc} */ public function handle(Exception $exception) { if ($this->rethrow) { throw $exception; } foreach ($this->handlers as $index => $handler) { try { if (is_string($handler)) { $handler = $this->resolver->resolve($handler); $this->handlers->offsetSet($index, $handler); } else { if (is_array($handler) && is_string($handler[0])) { $handler[0] = $this->resolver->resolve($handler[0]); $this->handlers->offsetSet($index, $handler); } } if (!$this->matchesTypehint($handler, $exception)) { continue; } $result = $this->callHandler($handler, $exception); if ($result !== null) { return $this->makeResponse($result, $exception); } } catch (Exception $newException) { return $this->handle($newException); } } return $this->makeResponse($this->defaultHandler->handle($exception), $exception); }
public function process($index, \SplDoublyLinkedList $list) { $first = $list->offsetGet($index - 1); $second = $list->offsetGet($index + 1); $result = $first * $second; $list->offsetSet($index - 1, $result); unset($list[$index]); unset($list[$index]); }
public function process($index, \SplDoublyLinkedList $list) { $first = $list->offsetGet($index - 1); $second = $list->offsetGet($index + 1); if ($second == 0) { throw new \Exception('zero division error'); } $result = $first / $second; $list->offsetSet($index - 1, $result); unset($list[$index]); unset($list[$index]); }
// valid() // 判断该链表是否有更多的值,返回bool $list->valid(); // isEmpty() // 判断该链表是否为空链表,返回bool $list->isEmpty(); // offsetExists($index) // 判断参索引是否存在,返回bool $list->offsetExists(2); // offsetGet($index) // 返回参数索引的节点值 $list->offsetGet(2); // offsetSet($index, $newValue) // 设置参数索引的节点值, $index必须在链表的键范围中。 // 当一个节点用offsetUnset删掉时时,并不能用offsetSet重新给已删掉的节点设置值,只能对当前可见的节点的值进行修改 $list->offsetSet(3, 'value6'); // offsetUnset($index) // 删除参数索引的节点 $list->offsetUnset(3); // add($index, $value); // 对指定的索引新增一个新值。 当一个节点用offsetUnset时,并没有直接删除,该节点还仍然会保存在内存中。用add可以重新给该节点设置值 $list->add(3, 'first'); // unshift($value) // 在链表的开始节点插入value作为新的开始节点 $list->unshift('second'); // shift() // 将链表的第一个移除 $list->shift(); // setIteratorMode(int $mode) // 设置链表的模式。等价于下面的情况: // IT_MODE_LIFO: 栈模式,先进后出;IT_MODE_FIFO:队列模式,先进先出
/** * @see \ArrayAccess::offsetSet() * @param int $offset * @param BufferInterface $value * @throws \InvalidArgumentException */ public function offsetSet($offset, $value) { $this->typeCheck($value); $offset = count($this) + $offset; parent::offsetSet($offset, $value); }
<?php $list = new SplDoublyLinkedList(); $a = $list->offsetSet(); if (is_null($a)) { echo 'PASS'; }
<?php $list = new SplDoublyLinkedList(); $a = $list->offsetSet(2); if (is_null($a)) { echo 'PASS'; }