本文整理汇总了PHP中Zend_Http_CookieJar::getMatchingCookies方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Http_CookieJar::getMatchingCookies方法的具体用法?PHP Zend_Http_CookieJar::getMatchingCookies怎么用?PHP Zend_Http_CookieJar::getMatchingCookies使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Http_CookieJar
的用法示例。
在下文中一共展示了Zend_Http_CookieJar::getMatchingCookies方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _prepareHeaders
/**
* Prepare the request headers
*
* @return array
*/
protected function _prepareHeaders()
{
$headers = array();
// Set the host header
if (!isset($this->headers['host'])) {
$host = $this->uri->getHost();
// If the port is not default, add it
if (!($this->uri->getScheme() == 'http' && $this->uri->getPort() == 80 || $this->uri->getScheme() == 'https' && $this->uri->getPort() == 443)) {
$host .= ':' . $this->uri->getPort();
}
$headers[] = "Host: {$host}";
}
// Set the connection header
if (!isset($this->headers['connection'])) {
if (!$this->config['keepalive']) {
$headers[] = "Connection: close";
}
}
// Set the Accept-encoding header if not set - depending on whether
// zlib is available or not.
if (!isset($this->headers['accept-encoding'])) {
if (function_exists('gzinflate')) {
$headers[] = 'Accept-encoding: gzip, deflate';
} else {
$headers[] = 'Accept-encoding: identity';
}
}
// Set the Content-Type header
if (($this->method == self::POST || $this->method == self::PUT) && (!isset($this->headers[strtolower(self::CONTENT_TYPE)]) && isset($this->enctype))) {
$headers[] = self::CONTENT_TYPE . ': ' . $this->enctype;
}
// Set the user agent header
if (!isset($this->headers['user-agent']) && isset($this->config['useragent'])) {
$headers[] = "User-Agent: {$this->config['useragent']}";
}
// Set HTTP authentication if needed
if (is_array($this->auth)) {
$auth = self::encodeAuthHeader($this->auth['user'], $this->auth['password'], $this->auth['type']);
$headers[] = "Authorization: {$auth}";
}
// Load cookies from cookie jar
if (isset($this->cookiejar)) {
$cookstr = $this->cookiejar->getMatchingCookies($this->uri, true, Zend_Http_CookieJar::COOKIE_STRING_CONCAT);
if ($cookstr) {
$headers[] = "Cookie: {$cookstr}";
}
}
// Add all other user defined headers
foreach ($this->headers as $header) {
list($name, $value) = $header;
if (is_array($value)) {
$value = implode(', ', $value);
}
$headers[] = "{$name}: {$value}";
}
return $headers;
}
示例2: prepare_headers
/**
* Prepare the request headers
*
* @return array
*/
protected function prepare_headers()
{
$headers = array();
// Set the host header
if (!isset($this->headers['host'])) {
$host = $this->uri->getHost();
// If the port is not default, add it
if (!($this->uri->getScheme() == 'http' && $this->uri->getPort() == 80 || $this->uri->getScheme() == 'https' && $this->uri->getPort() == 443)) {
$host .= ':' . $this->uri->getPort();
}
$headers[] = "Host: {$host}";
}
// Set the connection header
if (!isset($this->headers['connection'])) {
if (!$this->config['keepalive']) {
$headers[] = "Connection: close";
}
}
// Set the content-type header
if ($this->method == self::POST && (!isset($this->headers['content-type']) && isset($this->enctype))) {
$headers[] = "Content-type: {$this->enctype}";
}
// Set the user agent header
if (!isset($this->headers['user-agent']) && isset($this->config['useragent'])) {
$headers[] = "User-agent: {$this->config['useragent']}";
}
// Set HTTP authentication if needed
if (is_array($this->auth)) {
$auth = self::encodeAuthHeader($this->auth['user'], $this->auth['password'], $this->auth['type']);
$headers[] = "Authorization: {$auth}";
}
// Load cookies from cookie jar
if (isset($this->cookiejar)) {
$cookstr = $this->cookiejar->getMatchingCookies($this->uri, true, Zend_Http_CookieJar::COOKIE_STRING_CONCAT);
if ($cookstr) {
$headers[] = "Cookie: {$cookstr}";
}
}
// Add all other user defined headers
foreach ($this->headers as $name => $value) {
if (is_array($value)) {
$value = implode(', ', $value);
}
$headers[] = ucfirst($name) . ": {$value}";
}
return $headers;
}
示例3: testMatchPathWithTrailingSlash
/**
* Make sure that paths with trailing slashes are matched as well as paths with no trailing slashes
*/
public function testMatchPathWithTrailingSlash()
{
$jar = new Zend_Http_CookieJar();
$cookies = array(Zend_Http_Cookie::fromString('foo1=bar1; domain=.example.com; path=/a/b'), Zend_Http_Cookie::fromString('foo2=bar2; domain=.example.com; path=/a/b/'));
foreach ($cookies as $cookie) {
$jar->addCookie($cookie);
}
$cookies = $jar->getMatchingCookies('http://www.example.com/a/b/file.txt');
$this->assertTrue(is_array($cookies));
$this->assertEquals(2, count($cookies));
}
示例4: _prepareHeaders
/**
* Prepare the request headers
*
* @return array
*/
protected function _prepareHeaders()
{
$uri = $this->uri;
$headers = array();
// Set the host header
if (!isset($this->headers["host"])) {
$host = $uri->host;
$port = (int) $uri->port;
// If the port is not default, add it
if (!($uri->scheme === "http" && $port === 80 || $uri->scheme === "https" && $port === 443)) {
$host .= ":" . $port;
}
$headers[] = "Host: {$host}";
}
// Set the connection header
if (!isset($this->headers["connection"])) {
if (!$this->config["keepalive"]) {
$headers[] = "Connection: close";
}
}
// Set the Accept-encoding header if not set - depending on whether
// zlib is available or not.
if (!isset($this->headers["accept-encoding"])) {
if (function_exists("gzinflate")) {
$headers[] = "Accept-encoding: gzip, deflate";
} else {
$headers[] = "Accept-encoding: identity";
}
}
// Set the Content-Type header
if ($this->method === self::POST && (!isset($this->headers[strtolower(self::CONTENT_TYPE)]) && isset($this->enctype))) {
$headers[] = self::CONTENT_TYPE . ": " . $this->enctype;
}
// Set the user agent header
if (!isset($this->headers["user-agent"]) && isset($this->config["useragent"])) {
$headers[] = "User-Agent: {$this->config['useragent']}";
}
// Set HTTP authentication if needed
if (is_array($this->auth)) {
$auth = self::encodeAuthHeader($this->auth["user"], $this->auth["password"], $this->auth["type"]);
$headers[] = "Authorization: {$auth}";
}
// Load cookies from cookie jar
if (isset($this->cookiejar)) {
$cookstr = $this->cookiejar->getMatchingCookies($uri, true, Sabel_Http_CookieJar::COOKIE_STRING_CONCAT);
if ($cookstr) {
$headers[] = "Cookie: {$cookstr}";
}
}
// Add all other user defined headers
foreach ($this->headers as $header) {
list($name, $value) = $header;
if (is_array($value)) {
$value = implode(", ", $value);
}
$headers[] = "{$name}: {$value}";
}
return $headers;
}
示例5: testGetMatchingCookiesAsStrings
/**
* Test we can get all matching cookies for a request, and return as strings array / concat
*/
public function testGetMatchingCookiesAsStrings()
{
$jar = new Zend_Http_CookieJar();
$cookies = array(Zend_Http_Cookie::fromString('foo1=bar1; domain=.foo.com; path=/path; expires=' . date(DATE_COOKIE, time() + 3600)), Zend_Http_Cookie::fromString('foo2=bar2; domain=.foo.com; path=/; expires=' . date(DATE_COOKIE, time() + 3600)), Zend_Http_Cookie::fromString('foo3=bar3; domain=.foo.com; path=/; expires=' . date(DATE_COOKIE, time() - 3600)), Zend_Http_Cookie::fromString('foo4=bar4; domain=.foo.com; path=/;'), Zend_Http_Cookie::fromString('foo5=bar5; domain=.foo.com; path=/; secure; expires=' . date(DATE_COOKIE, time() + 3600)), Zend_Http_Cookie::fromString('foo6=bar6; domain=.foo.com; path=/otherpath; expires=' . date(DATE_COOKIE, time() + 3600)), Zend_Http_Cookie::fromString('foo7=bar7; domain=www.foo.com; path=/path; expires=' . date(DATE_COOKIE, time() + 3600)), Zend_Http_Cookie::fromString('foo8=bar8; domain=subdomain.foo.com; path=/path; expires=' . date(DATE_COOKIE, time() + 3600)));
foreach ($cookies as $cookie) {
$jar->addCookie($cookie);
}
$this->assertEquals(8, count($jar->getAllCookies()), 'Cookie count is expected to be 8');
$cookies = $jar->getMatchingCookies('http://www.foo.com/path/file.txt', true, Zend_Http_CookieJar::COOKIE_STRING_ARRAY);
$this->assertType('array', $cookies, '$cookies is expected to be an array, but it is not');
$this->assertType('string', $cookies[0], '$cookies[0] is expected to be a string');
$cookies = $jar->getMatchingCookies('http://www.foo.com/path/file.txt', true, Zend_Http_CookieJar::COOKIE_STRING_CONCAT);
$this->assertType('string', $cookies, '$cookies is expected to be a string');
}
示例6: _getMatchCookieValue
private function _getMatchCookieValue($name, $domain, Zend_Http_CookieJar $jar)
{
$cookies = $jar->getMatchingCookies($domain);
foreach ($cookies as $cookie) {
/* @var $cookie Zend_Http_Cookie */
if ($cookie->getName() == $name) {
return $cookie->getValue();
}
}
return false;
}