Example #1
0
 /**
  * Property setter interceptor to handle "host" special case.
  *
  * @param string $property The property to retrieve
  * @param mixed  $value    The property value
  * 
  * @return void
  */
 public function __set($property, $value)
 {
     switch ($property) {
         case 'uri':
             if ($value == null) {
                 return;
             }
             $this->_uri = new Net_URL2($value);
             $this->_uri->normalize();
             // if we have a proxy set, URI must be absolute
             if ($this->_proxy !== null && !$this->_uri->isAbsolute()) {
                 throw new HTTP_Request2_Exception('URI must be absolute when using a proxy');
             }
             // if we use HTTP/1.0, URI must also be absolute
             if ($this->httpVersion == self::HTTP_VERSION_1_0 && !$this->_uri->isAbsolute()) {
                 throw new HTTP_Request2_Exception('URI must be absolute when using ' . self::HTTP_VERSION_1_0);
             }
             break;
         case 'proxy':
             // if we have a proxy set, URI must be absolute
             if ($this->_uri !== null && !$this->_uri->isAbsolute()) {
                 throw new HTTP_Request2_Exception('URI must be absolute when using a proxy');
             }
             $this->_proxy = $value;
             break;
         case 'connection':
             if (!$value instanceof HTTP_Connection) {
                 throw new HTTP_Request2_Exception('connection must be an instance of HTTP_Connection');
             }
             $this->_connection = $value;
             break;
         case 'path':
         case 'host':
         case 'port':
             throw new HTTP_Request2_Exception('"' . $property . '" is a read-only property');
     }
 }
Example #2
0
 /**
  * This is a regression test to test that setting "0" as path
  * does not break normalize().
  *
  * It was reported as Bug #20157 on 2013-12-27 23:42 UTC that
  * normalize() with "0" as path would not work.
  *
  * @covers Net_URL2::normalize
  * @return void
  */
 public function test20157()
 {
     $subject = 'http://example.com';
     $url = new Net_URL2($subject);
     $url->setPath('0');
     $url->normalize();
     $this->assertSame("{$subject}/0", (string) $url);
 }