本文整理汇总了PHP中Header::getParams方法的典型用法代码示例。如果您正苦于以下问题:PHP Header::getParams方法的具体用法?PHP Header::getParams怎么用?PHP Header::getParams使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Header
的用法示例。
在下文中一共展示了Header::getParams方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getHandshake
public function getHandshake($buffer) {
$header = new Header($buffer);
$params = $header->getParams();;
if (isset($params['Sec-WebSocket-Key'])) {
$response = "HTTP/1.1 101 Switching Protocols\r\n";
$response .= "Upgrade: websocket\r\n";
$response .= "Connection: Upgrade\r\n";
$response .= "Sec-WebSocket-Accept: $acceptKey";
$response .= "\0";
}
else {
$pattern = '/[^\d]*/';
$replacement = '';
$numkey1 = preg_replace($pattern, $replacement, $params['Sec-WebSocket-Key1']);
$numkey2 = preg_replace($pattern, $replacement, $params['Sec-WebSocket-Key2']);
$pattern = '/[^ ]*/';
$replacement = '';
$spaces1 = strlen(preg_replace($pattern, $replacement, $params['Sec-WebSocket-Key1']));
$spaces2 = strlen(preg_replace($pattern, $replacement, $params['Sec-WebSocket-Key2']));
$hashData = md5( pack("N", $numkey1/$spaces1) . pack("N", $numkey2/$spaces2) . $header->getMessage(), true);
$response = "HTTP/1.1 101 WebSocket Protocol Handshake\r\n";
$response .= "Upgrade: WebSocket\r\n";
$response .= "Connection: Upgrade\r\n";
$response .= "Sec-WebSocket-Origin: " . $params['Origin'] . "\r\n";
$response .= "Sec-WebSocket-Location: ws://" . "{$this->address}:{$this->port}" . $header->getResource() . "\r\n";
$response .= "\r\n";
$response .= $hashData;
$response .= "\0";
}
return $response;
}
示例2: InvalidArgumentException
/**
* @param Header $contentType
* @throws InvalidArgumentException
*/
function __construct(Header $contentType)
{
if (strcasecmp($contentType->name, "Content-Type")) {
throw new InvalidArgumentException("Expected Content-Type header, got " . $contentType->name);
}
$vapi = static::version();
$this->type = preg_replace("/\n\t\t\t(?:application\\/(?:vnd\\.github(?:\\.v{$vapi})?)?)\n\t\t\t(?|\n\t\t\t\t\t\\.\t\t\t\t\t([^.+]+)\n\t\t\t\t|\t(?:\\.[^.+]+)?\\+?\t(json)\n\t\t\t)/x", "\\1", current(array_keys($contentType->getParams()->params)));
}