/** * @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]; }
/** * 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; }
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; }