Ejemplo n.º 1
0
 /**
  * @inheritdoc
  */
 public function benchmark($count, $uri)
 {
     $start = microtime(true);
     $memory = memory_get_usage();
     $uriParser = new UriParser();
     foreach ($this->generateUri($count, $uri) as $url) {
         $uriParser->parse($url);
     }
     return ['memory' => memory_get_usage() - $memory, 'duration' => microtime(true) - $start];
 }
Ejemplo n.º 2
0
 /**
  * Format a URI authority according to the Formatter properties
  *
  * @param UriInterface|Uri $uri
  *
  * @return string
  */
 protected function formatAuthority($uri)
 {
     if ('' == $uri->getHost()) {
         return '';
     }
     $components = $this->uriParser->parse((string) $uri);
     $port = $components['port'];
     if (!empty($port)) {
         $port = ':' . $port;
     }
     return '//' . $this->uriParser->buildUserInfo($components['user'], $components['pass']) . $this->formatHost(new Host($components['host'])) . $port;
 }
Ejemplo n.º 3
0
 /**
  * Returns the environment user info
  *
  * @param array $server the environment server typically $_SERVER
  *
  * @return string
  */
 protected static function fetchServerUserInfo(array $server)
 {
     $server += ['PHP_AUTH_USER' => null, 'PHP_AUTH_PW' => null, 'HTTP_AUTHORIZATION' => null];
     $parser = new UriParser();
     if (!empty($server['HTTP_AUTHORIZATION']) && 0 === strpos(strtolower($server['HTTP_AUTHORIZATION']), 'basic')) {
         $res = explode(':', base64_decode(substr($server['HTTP_AUTHORIZATION'], 6)), 2);
         $login = array_shift($res);
         $pass = array_shift($res);
         return $parser->buildUserInfo(rawurlencode($login), rawurlencode($pass));
     }
     return $parser->buildUserInfo(rawurlencode($server['PHP_AUTH_USER']), rawurlencode($server['PHP_AUTH_PW']));
 }
Ejemplo n.º 4
0
 private function validateSubjectResource($resource)
 {
     if (strpos($resource, 'acct:') === 0) {
         $resource = preg_replace('/@/', '%40', $resource, 1);
         $parseable = preg_replace('/^acct:/', 'acct://', $resource, 1);
     } else {
         $parseable = $resource;
     }
     $parser = new UriParser();
     $default = array('scheme' => null, 'user' => null, 'host' => null);
     $parts = array_merge($default, $parser->parse($parseable));
     if ($parts['scheme'] === null) {
         if ($parts['host'] !== null && $parts['user'] !== null) {
             $parts['scheme'] = 'acct';
         } else {
             $parts['scheme'] = 'https';
         }
     }
     if ($parts['scheme'] === null || $parts['host'] === null) {
         throw new BadRequestHttpException("Invalid resource");
     }
     return $resource;
 }