Class UriFactory
Factory class for creating uri instances.
Method Summary
-
createFromSapi() protected static
Create a Uri instance from SAPI parameters.
-
createUri() public
Create a new URI.
-
getBase() protected static
Calculate the base directory and webroot directory.
-
marshalHostAndPort() protected static
Get the host and port from the Host header or SERVER_NAME/SERVER_PORT.
-
marshalRequestPath() protected static
Detect the request path from the SAPI parameters.
Uses the IIS7 UrlRewrite environment,
REQUEST_URIorORIG_PATH_INFO. -
marshalUriAndBaseFromSapi() public static
Get a new Uri instance and base info from the provided server data.
-
updatePath() protected static
Updates the request URI to remove the base directory.
Method Detail
createFromSapi() ¶ protected static
createFromSapi(array $server): Cake\Http\Uri
Create a Uri instance from SAPI parameters.
Parameters
-
array$server The SERVER data to use.
Returns
Cake\Http\UricreateUri() ¶ public
createUri(string $uri = ''): Uri
Create a new URI.
Parameters
-
string$uri optional The URI to parse.
Returns
UriThrows
InvalidArgumentExceptionIf the given URI cannot be parsed.
getBase() ¶ protected static
getBase(Psr\Http\Message\UriInterface $uri, array $server): array{base: string, webroot: string}
Calculate the base directory and webroot directory.
Parameters
-
Psr\Http\Message\UriInterface$uri The Uri instance.
-
array$server The SERVER data to use.
Returns
array{base: string, webroot: string}An array containing the base and webroot paths.
marshalHostAndPort() ¶ protected static
marshalHostAndPort(array $server): array{0: string, 1: (int|null)}
Get the host and port from the Host header or SERVER_NAME/SERVER_PORT.
Parameters
-
array$server The SERVER data to use.
Returns
array{0: string, 1: (int|null)}marshalRequestPath() ¶ protected static
marshalRequestPath(array $server): string
Detect the request path from the SAPI parameters.
Uses the IIS7 UrlRewrite environment, REQUEST_URI or ORIG_PATH_INFO.
Parameters
-
array$server The SERVER data to use.
Returns
stringmarshalUriAndBaseFromSapi() ¶ public static
marshalUriAndBaseFromSapi(array|null $server = null): array{uri: \Psr\Http\Message\UriInterface, base: string, webroot: string}
Get a new Uri instance and base info from the provided server data.
Parameters
-
array|null$server optional Array of server data to build the Uri from. $_SERVER will be used if $server parameter is null.
Returns
array{uri: \Psr\Http\Message\UriInterface, base: string, webroot: string}updatePath() ¶ protected static
updatePath(string $base, Psr\Http\Message\UriInterface $uri): Psr\Http\Message\UriInterface
Updates the request URI to remove the base directory.
Parameters
-
string$base The base path to remove.
-
Psr\Http\Message\UriInterface$uri The uri to update.
Returns
Psr\Http\Message\UriInterface