GuzzleHttp\Psr7\Uri::__construct PHP Method

__construct() public method

public __construct ( string $uri = '' )
$uri string URI to parse
    public function __construct($uri = '')
    {
        // weak type check to also accept null until we can add scalar type hints
        if ($uri != '') {
            $parts = parse_url($uri);
            if ($parts === false) {
                throw new \InvalidArgumentException("Unable to parse URI: {$uri}");
            }
            $this->applyParts($parts);
        }
    }

Usage Example

Example #1
0
 /**
  * Uri constructor.
  * Overridden constructor to achieve every
  * request to the ZOHO should have Auth Token
  *
  * @param string $uri
  * @param ConfigurationInterface $configuration
  */
 public function __construct($uri = '', ConfigurationInterface $configuration)
 {
     if ($uri != null) {
         $parts = parse_url($uri);
         if ($parts === false || !array_key_exists('query', $parts)) {
             return parent::__construct($uri . '?authtoken=' . $configuration->getAuthToken());
         }
         return parent::__construct(str_replace($parts['query'], 'authtoken=' . $configuration->getAuthToken() . '&' . $parts['query'], $uri));
     }
 }