标题{}

在本文中

不区分大小写的字典,适用于HTTP标头

方法

姓名描述
页眉::展平将值展平为字符串
标头::getIterator获取数据的迭代器
标头::getValues获取给定标头的所有值
标题::offsetGet获取给定的标题
页眉::offsetSet设置给定项

来源

类标题扩展了CaseInsensitiveDictionary{/***获取给定的标题**不同于\WpOrg\Requests\Response\Headers::getValues(),这将返回一个字符串。如果*多个值,它根据RFC2616用逗号将它们连接起来。**避免在值中使用未加引号的逗号,例如*设置Cookie标题。**@param string$offset要检索的头的名称。*@return string | null头值*/公共函数offsetGet($offset){if(is_string($offset)){$offset=strtolower($offset);}if(!isset($this->data[$offset]){返回null;}返回$this->flature($this->数据[$offset]);}/***设置给定项**@param string$offset项目名称*@param string$value项目值**@throws\WpOrg\Requests\Exception尝试将字典用作列表(`invalidset`)*/公共函数offsetSet($offset,$value){if($offset===null){throw new Exception(“Object is a dictionary,not a list”,“invalidset”);}if(is_string($offset)){$offset=strtolower($offset);}if(!isset($this->data[$offset]){$this->data[$offset]=[];}$this->data[$offset][]=$value;}/***获取给定标头的所有值**@param string$offset要检索的头的名称。*@return数组| null头值**@throws\WpOrg\Requests\Exception\InvalidArgument当传递的参数作为数组键无效时。*/公共函数getValues($offset){if(!is_string($offset)&&!is_int($offset){throw InvalidArgument::create(1,'$offset','string|int',gettype($offset));}if(is_string($offset)){$offset=strtolower($offset);}if(!isset($this->data[$offset]){返回null;}返回$this->data[$offset];}/***将值展平为字符串**按照*RFC2616的折叠标题规则。**@param string | array$value要展平的值*@return string平坦值**@throws\WpOrg\Requests\Exception\InvalidArgument当传递的参数不是字符串或数组时。*/公共函数扁平化($value){if(is_string($value)){返回$value;}if(is_array($value)){返回内爆(',',$value);}throw InvalidArgument::create(1,“$value”,“string|array”,gettype($value));}/***获取数据的迭代器**如果存在更多值,则将内部存储的值转换为逗号分隔的字符串*键的值多于一个。**@return\ArrayIterator*/公共函数getIterator(){return new FilteredIterator($this->data,[$this,'flath']);}}

用户贡献的笔记

你必须登录在能够发表注释或反馈之前。