当前位置: 首页>>代码示例>>PHP>>正文


PHP Zend_Http_Cookie::fromString方法代码示例

本文整理汇总了PHP中Zend_Http_Cookie::fromString方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Http_Cookie::fromString方法的具体用法?PHP Zend_Http_Cookie::fromString怎么用?PHP Zend_Http_Cookie::fromString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend_Http_Cookie的用法示例。


在下文中一共展示了Zend_Http_Cookie::fromString方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addCookie

 public function addCookie($cookie, $ref_uri = null)
 {
     if (is_string($cookie)) {
         if ($this->_encodeCookie) {
             $cookie = Zend_Http_Cookie::fromString($cookie, $ref_uri);
         } else {
             $cookie = Zend_Http_Cookie::fromString($cookie, $ref_uri, false);
         }
     }
     if ($cookie instanceof Zend_Http_Cookie) {
         $domain = $cookie->getDomain();
         $path = $cookie->getPath();
         if (!isset($this->cookies[$domain])) {
             $this->cookies[$domain] = array();
         }
         if (!isset($this->cookies[$domain][$path])) {
             $this->cookies[$domain][$path] = array();
         }
         $this->cookies[$domain][$path][$cookie->getName()] = $cookie;
         $this->_rawCookies[] = $cookie;
     } else {
         require_once 'Zend/Http/Exception.php';
         throw new Zend_Http_Exception('Supplient argument is not a valid cookie string or object');
     }
 }
开发者ID:sb15,项目名称:zend-ex-legacy,代码行数:25,代码来源:CookieJar.php

示例2: setCookie

 /**
  * Add a cookie to the request. If the client has no Cookie Jar, the cookies
  * will be added directly to the headers array as "Cookie" headers.
  *
  * @param Zend_Http_Cookie|string $cookie
  * @param string|null $value If "cookie" is a string, this is the cookie value.
  * @return Zend_Http_Client
  * @throws Zend_Http_Client_Exception
  */
 public function setCookie($cookie, $value = null)
 {
     Zend_Loader::loadClass('Zend_Http_Cookie');
     if (is_array($cookie)) {
         foreach ($cookie as $c => $v) {
             if (is_string($c)) {
                 $this->setCookie($c, $v);
             } else {
                 $this->setCookie($v);
             }
         }
         return $this;
     }
     if ($value !== null && $this->config['encodecookies']) {
         $value = urlencode($value);
     }
     if (isset($this->cookiejar)) {
         if ($cookie instanceof Zend_Http_Cookie) {
             $this->cookiejar->addCookie($cookie);
         } elseif (is_string($cookie) && $value !== null) {
             $cookie = Zend_Http_Cookie::fromString("{$cookie}={$value}", $this->uri, $this->config['encodecookies']);
             $this->cookiejar->addCookie($cookie);
         }
     } else {
         if ($cookie instanceof Zend_Http_Cookie) {
             $name = $cookie->getName();
             $value = $cookie->getValue();
             $cookie = $name;
         }
         if (preg_match("/[=,; \t\r\n\v\f]/", $cookie)) {
             /** @see Zend_Http_Client_Exception */
             require_once 'Zend/Http/Client/Exception.php';
             throw new Zend_Http_Client_Exception("Cookie name cannot contain these characters: =,; \t\r\n\v\f ({$cookie})");
         }
         $value = addslashes($value);
         if (!isset($this->headers['cookie'])) {
             $this->headers['cookie'] = array('Cookie', '');
         }
         $this->headers['cookie'][1] .= $cookie . '=' . $value . '; ';
     }
     return $this;
 }
开发者ID:abdulhadikaryana,项目名称:kebudayaan,代码行数:51,代码来源:Client.php

示例3: addCookie

 /**
  * Add a cookie to the jar. Cookie should be passed either as a Zend_Http_Cookie object
  * or as a string - in which case an object is created from the string.
  *
  * @param Zend_Http_Cookie|string $cookie
  * @param Zend_Uri_Http|string $red_uri Optional reference URI (for domain, path, secure)
  */
 public function addCookie($cookie, $ref_uri = null)
 {
     if (is_string($cookie)) {
         $cookie = Zend_Http_Cookie::fromString($cookie, $ref_uri);
     }
     if ($cookie instanceof Zend_Http_Cookie) {
         $domain = $cookie->getDomain();
         $path = $cookie->getPath();
         if (!isset($this->cookies[$domain])) {
             $this->cookies[$domain] = array();
         }
         if (!isset($this->cookies[$domain][$path])) {
             $this->cookies[$domain][$path] = array();
         }
         $this->cookies[$domain][$path][$cookie->getName()] = $cookie;
     } else {
         throw Zend::exception('Zend_Http_Exception', 'Supplient argument is not a valid cookie string or object');
     }
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:26,代码来源:CookieJar.php

示例4: testIteratorAndCountable

 public function testIteratorAndCountable()
 {
     $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);
     }
     foreach ($jar as $cookie) {
         $this->assertTrue($cookie instanceof Zend_Http_Cookie);
     }
     $this->assertEquals(2, count($jar));
     $this->assertFalse($jar->isEmpty());
     $jar->reset();
     $this->assertTrue($jar->isEmpty());
 }
开发者ID:JeancarloPerez,项目名称:booking-system,代码行数:15,代码来源:CookieJarTest.php

示例5: testSetCookieObjectJar

 /**
  * Make sure we can set cookie objects with a jar
  *
  */
 public function testSetCookieObjectJar()
 {
     $this->client->setUri($this->baseuri . 'testCookies.php');
     $this->client->setCookieJar();
     $refuri = $this->client->getUri();
     $cookies = array(Zend_Http_Cookie::fromString('chocolate=chips', $refuri), Zend_Http_Cookie::fromString('crumble=apple', $refuri));
     $strcookies = array();
     foreach ($cookies as $c) {
         $this->client->setCookie($c);
         $strcookies[$c->getName()] = $c->getValue();
     }
     $res = $this->client->request();
     $this->assertEquals($res->getBody(), serialize($strcookies), 'Response body does not contain the expected cookies');
 }
开发者ID:lortnus,项目名称:zf1,代码行数:18,代码来源:SocketTest.php

示例6: testFromStringFalse

 public function testFromStringFalse()
 {
     $cookie = Zend_Http_Cookie::fromString('foo; domain=www.exmaple.com');
     $this->assertEquals(false, $cookie, 'fromString was expected to fail and return false');
     $cookie = Zend_Http_Cookie::fromString('=bar; secure; domain=foo.nl');
     $this->assertEquals(false, $cookie, 'fromString was expected to fail and return false');
     $cookie = Zend_Http_Cookie::fromString('fo;o=bar; secure; domain=foo.nl');
     $this->assertEquals(false, $cookie, 'fromString was expected to fail and return false');
 }
开发者ID:lortnus,项目名称:zf1,代码行数:9,代码来源:CookieTest.php

示例7: 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');
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:17,代码来源:CookieJarTest.php

示例8: testZF5690OverflowingExpiryDate

 /**
  * Test that cookies with far future expiry date (beyond the 32 bit unsigned int range) are
  * not mistakenly marked as 'expired'
  *
  * @link http://framework.zend.com/issues/browse/ZF-5690
  */
 public function testZF5690OverflowingExpiryDate()
 {
     $expTime = "Sat, 29-Jan-2039 00:54:42 GMT";
     $cookie = Zend_Http_Cookie::fromString("foo=bar; domain=.example.com; expires={$expTime}");
     $this->assertFalse($cookie->isExpired(), 'Expiry: ' . $cookie->getExpiryTime());
 }
开发者ID:SustainableCoastlines,项目名称:loveyourwater,代码行数:12,代码来源:CookieTest.php

示例9: setCookie

    /**
     * Add a cookie to the request. If the client has no Cookie Jar, the cookies
     * will be added directly to the headers array as "Cookie" headers.
     *
     * @param Zend_Http_Cookie|string $cookie
     * @param string|null $value If "cookie" is a string, this is the cookie value.
     * @return Zend_Http_Client
     */
    public function setCookie($cookie, $value = null)
    {
        if (! class_exists('Zend_Http_Cookie'))
            require_once 'Zend/Http/Cookie.php';

        if (is_array($cookie)) {
            foreach ($cookie as $c => $v) {
                if (is_string($c)) {
                    $this->setCookie($c, $v);
                } else {
                    $this->setCookie($v);
                }
            }

            return $this;
        }

        if ($value !== null) $value = urlencode($value);

        if (isset($this->cookiejar)) {
            if ($cookie instanceof Zend_Http_Cookie) {
                $this->cookiejar->addCookie($cookie);
            } elseif (is_string($cookie) && $value !== null) {
                $cookie = Zend_Http_Cookie::fromString("{$cookie}={$value}", $this->uri);
                $this->cookiejar->addCookie($cookie);
            }
        } else {
            if ($cookie instanceof Zend_Http_Cookie) {
                $name = $cookie->getName();
                $value = $cookie->getValue();
                $cookie = $name;
            }

            if (preg_match("/[=,; \t\r\n\013\014]/", $cookie))
                throw new Zend_Http_Client_Exception("Cookie name cannot contain these characters: =,; \t\r\n\013\014 ({$cookie})");

            $value = addslashes($value);

            if (! isset($this->headers['cookie'])) $this->headers['cookie'] = '';
            $this->headers['cookie'] .= $cookie . '=' . $value . '; ';
        }

        return $this;
    }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:52,代码来源:Client.php

示例10: 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->assertType('array', $cookies);
 	$this->assertEquals(2, count($cookies));    	
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:17,代码来源:CookieJarTest.php


注:本文中的Zend_Http_Cookie::fromString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。