Пример #1
0
 /**
  * Constructs the URI object from a string
  *
  * @param string $uriString String representation of the URI
  * @throws \InvalidArgumentException
  * @api
  */
 public function __construct($uriString)
 {
     if (!is_string($uriString)) {
         throw new \InvalidArgumentException('The URI must be a valid string.', 1176550571);
     }
     $parseUrlException = null;
     try {
         $uriParts = Unicode\Functions::parse_url($uriString);
     } catch (FlowError\Exception $exception) {
         $parseUrlException = $exception;
     }
     if (is_array($uriParts)) {
         $this->scheme = isset($uriParts['scheme']) ? $uriParts['scheme'] : null;
         $this->username = isset($uriParts['user']) ? $uriParts['user'] : null;
         $this->password = isset($uriParts['pass']) ? $uriParts['pass'] : null;
         $this->host = isset($uriParts['host']) ? $uriParts['host'] : null;
         $this->port = isset($uriParts['port']) ? $uriParts['port'] : null;
         if ($this->port === null) {
             switch ($this->scheme) {
                 case 'http':
                     $this->port = 80;
                     break;
                 case 'https':
                     $this->port = 443;
                     break;
             }
         }
         $this->path = isset($uriParts['path']) ? $uriParts['path'] : null;
         if (isset($uriParts['query'])) {
             $this->setQuery($uriParts['query']);
         }
         $this->fragment = isset($uriParts['fragment']) ? $uriParts['fragment'] : null;
     } else {
         throw new \InvalidArgumentException('The given URI "' . $uriString . '" is not a valid one.', 1351594202, $parseUrlException);
     }
 }
 /**
  * Evaluates the absolute path and filename of the resource file specified
  * by the given path.
  *
  * @param string $requestedPath
  * @param boolean $checkForExistence Whether a (non-hash) path should be checked for existence before being returned
  * @return mixed The full path and filename or FALSE if the file doesn't exist
  * @throws \InvalidArgumentException|ResourceException
  */
 protected function evaluateResourcePath($requestedPath, $checkForExistence = true)
 {
     if (substr($requestedPath, 0, strlen(self::SCHEME)) !== self::SCHEME) {
         throw new \InvalidArgumentException('The ' . __CLASS__ . ' only supports the \'' . self::SCHEME . '\' scheme.', 1256052544);
     }
     $uriParts = Functions::parse_url($requestedPath);
     if (!is_array($uriParts) || !isset($uriParts['host'])) {
         return false;
     }
     if (preg_match('/^[0-9a-f]{40}$/i', $uriParts['host']) === 1) {
         $resource = $this->resourceManager->getResourceBySha1($uriParts['host']);
         return $this->resourceManager->getStreamByResource($resource);
     }
     if (!$this->packageManager->isPackageAvailable($uriParts['host'])) {
         throw new ResourceException(sprintf('Invalid resource URI "%s": Package "%s" is not available.', $requestedPath, $uriParts['host']), 1309269952);
     }
     $package = $this->packageManager->getPackage($uriParts['host']);
     $resourceUri = Files::concatenatePaths([$package->getResourcesPath(), $uriParts['path']]);
     if ($checkForExistence === false || file_exists($resourceUri)) {
         return $resourceUri;
     }
     return false;
 }
Пример #3
0
 /**
  * @test
  */
 public function parse_urlWorksWithUTF8Chars()
 {
     $url = 'http://www.mysite.org/he/פרויקטים/ByYear.html';
     $expected = ['scheme' => 'http', 'host' => 'www.mysite.org', 'path' => '/he/פרויקטים/ByYear.html'];
     $this->assertEquals($expected, Functions::parse_url($url), 'parse_url() did not return the correct result for a unicode URL.');
 }