/** * Overloads offsetSet to restrict value type * @param int|string $key * @param \Nimbles\Http\Cookie $value * @return void * @throws \Nimbles\Http\Cookie\Exception\InvalidInstance */ public function offsetSet($key, $value) { if (is_string($value)) { $value = new Cookie(array('name' => $key, 'value' => $value)); } if (!$value instanceof Cookie) { throw new Cookie\Exception\InvalidInstance('Invalid value, must be an instance of Nimbles\\Http\\Cookie'); } if (null === $value->getName()) { $value->setName($key); } return parent::offsetSet($value->getName(), $value); }