本文整理匯總了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)));
}