RdbAdmin Module

Url
in package

URL class.

Tags
since
0.1

Table of Contents

Properties

$Container  : Container

Methods

__construct()  : mixed
Class constructor.
buildUrl()  : string
Build URL from `parse_url()` function.
getAppBasedPath()  : string
Get application based path without trailing slash.
getCurrentUrl()  : string
Get current URL.
getDomainProtocol()  : string
Get domain with protocol. Example: https://mydomain.com
getPath()  : string
Get path of current URL but related from public URL without any query string and no trailing slash.
getPublicModuleUrl()  : string
Get public/Modules URL from specific module path.
getPublicUrl()  : string
Get public URL.
getQuerystring()  : string
Get current query string (?param=value) with question mark sign (?) if it is not empty.
getSegment()  : string
Get the specific URL segment.
getSegments()  : array<string|int, mixed>
Get URL segments.
rawUrlEncodeAllParts()  : string
Encode all parts of the URL.
rawUrlEncodeFragment()  : string
Encode the fragment (#anchor) on the URL use `rawurlencode()`.
rawUrlEncodeQuerystring()  : string
Use `RFC 3986` to encode the query string (same as `rawurlencode` function).
rawUrlEncodeSegments()  : string
Use `rawurlencode()` to encode multiple segments.
rawUrlEncodeUsernamePassword()  : string
Encode the username and password on the URL use `rawurlencode()`.
removeQuerystring()  : string
Remove query string.
removeUnsafeUrlCharacters()  : string
Remove unsafe URL characters but not URL encode.

Properties

Methods

__construct()

Class constructor.

public __construct([Container $Container = null ]) : mixed
Parameters
$Container : Container = null

The DI container class. This is only required for some method, leave null if you don't use it.

buildUrl()

Build URL from `parse_url()` function.

public buildUrl(array<string|int, mixed> $parsedUrl) : string
Parameters
$parsedUrl : array<string|int, mixed>

The value from parse_url() function.

Tags
since
1.0.5
Return values
string

Return built URL.

getAppBasedPath()

Get application based path without trailing slash.

public getAppBasedPath([bool $raw = false ]) : string

For example: if you install this framework on /myapp sub folder then it will return /myapp.
If you install this framework on root folder then it will return empty string.
If you install this framework on /myapp and URL contain index.php such as http://localhost/myapp/index.php, it will return /myapp/index.php.

Parameters
$raw : bool = false

Set to true if you want to get the current URL exactly the same as you see in the address bar.
Set to false to get only real url without language locale URL.
For example: If the URL in address bar is '/installDir/en-US'.
If the 'en-US' is default language and it is set to hide default language...
Set $raw to true will show url segments as see in address bar (maybe visible language locale URL or not depend on configuration), set to false will show just '/installDir'.
If the 'en-US' is default language and it is set to show default language...
Set $raw to true will show language locale URL as see in address bar, set to false will show just '/installDir'.

Return values
string

Return application based path without trailing slash. It can return empty string if it is installed on root folder.

getCurrentUrl()

Get current URL.

public getCurrentUrl([bool $raw = false ]) : string
Parameters
$raw : bool = false

Set to true if you want to get the current URL exactly the same as you see in the address bar.
Set to false to get only real URL without language locale URL.
For example: If the URL in address bar is '/installDir/en-US'.
If the 'en-US' is default language and it is set to hide default language...
Set $raw to true will show URL segments as see in address bar (maybe visible language locale URL or not depend on configuration), set to false will show just '/installDir'.
If the 'en-US' is default language and it is set to show default language...
Set $raw to true will show language locale URL as see in address bar, set to false will show just '/installDir'.

Return values
string

Return current URL without query string and without trailing slash. Example: /installDir/public/my-current-uri

getDomainProtocol()

Get domain with protocol. Example: https://mydomain.com

public getDomainProtocol([bool|null $forceHttps = null ]) : string
Parameters
$forceHttps : bool|null = null

Set to true to force use HTTPS, false to force use HTTP. Default is null to auto detect current protocol. (since 1.1.2)

Return values
string

getPath()

Get path of current URL but related from public URL without any query string and no trailing slash.

public getPath() : string
Return values
string

Return the URL path. Example: URL is http://localhost/myapp/index.php/mycontroller/method will be /mycontroller/method. This can return empty string if nothing after app based path.

getPublicModuleUrl()

Get public/Modules URL from specific module path.

public getPublicModuleUrl(string $modulePath) : string

This method require class constructor to contain \Rdb\System\Container object.

Example: If you install this framework on /myapp and your index.php (public folder) is in /myapp URL.
If your module is Contact then it will return /myapp/Modules/Contact.

Parameters
$modulePath : string

The full path to any files in your module.

Return values
string

Return the URL start with /app-based-path and follow with your public URL with /Modules/ModuleName. This will not return trailing slash.

getPublicUrl()

Get public URL.

public getPublicUrl() : string

Example: If you install this framework on /myapp and your index.php (public folder) is in /myapp URL.
It will be return /myapp.

Tags
since
1.0.3
Return values
string

Return the URL start with /app-based-path. This will not return trailing slash.

getQuerystring()

Get current query string (?param=value) with question mark sign (?) if it is not empty.

public getQuerystring() : string

The query string will be automatically url encoded.

Return values
string

Return query string value with question mark sign (?) if not empty.

getSegment()

Get the specific URL segment.

public getSegment(int $number) : string
Parameters
$number : int

Segment number to get. Start from 1.

Tags
since
1.0.6
Return values
string

Return value of the selected URL segment.

getSegments()

Get URL segments.

public getSegments() : array<string|int, mixed>
Tags
since
1.0.6
Return values
array<string|int, mixed>

Return all URL segments except language URL if the configuration file was use detect language on the URL.

rawUrlEncodeAllParts()

Encode all parts of the URL.

public rawUrlEncodeAllParts(string $url) : string

This will not encode username:password, path or segments, query string, fragment.

Parameters
$url : string

The original URL without encoded.

Tags
since
1.0.5
Return values
string

Return URL encoded only fragment.

rawUrlEncodeFragment()

Encode the fragment (#anchor) on the URL use `rawurlencode()`.

public rawUrlEncodeFragment(string $url) : string

This will not encode other parts.

Parameters
$url : string

The original URL without encoded.

Tags
since
1.0.5
Return values
string

Return URL encoded only fragment.

rawUrlEncodeQuerystring()

Use `RFC 3986` to encode the query string (same as `rawurlencode` function).

public rawUrlEncodeQuerystring(string $url) : string

It will be encode only query string (Example: name1=value1&name2=value2&arr[]=valuearr1).
The argument separator (&) is depend on the URL input, if it contains &amp; then it will be return as-is. Otherwise it will be return as setting in arg_separator.output.

Parameters
$url : string

The original URL without encoded.

Tags
since
1.0.4
Return values
string

Return URL encoded only query string.

rawUrlEncodeSegments()

Use `rawurlencode()` to encode multiple segments.

public rawUrlEncodeSegments(string $url) : string

It will not encode slash (/) to %2F. It will also not encode the query string.
Example: The URL is 'hello/สวัสดี/ลาก่อน' the result will be 'hello/%E0%B8%AA%E0%B8%A7%E0%B8%B1%E0%B8%AA%E0%B8%94%E0%B8%B5/%E0%B8%A5%E0%B8%B2%E0%B8%81%E0%B9%88%E0%B8%AD%E0%B8%99'.
'hello/สวัสดี?query=string' the result will be 'hello/%E0%B8%AA%E0%B8%A7%E0%B8%B1%E0%B8%AA%E0%B8%94%E0%B8%B5?query=string'.

Parameters
$url : string

The original URL without encoded.

Tags
since
1.0.1
Return values
string

Return URL encoded only in each segments but not slash.

rawUrlEncodeUsernamePassword()

Encode the username and password on the URL use `rawurlencode()`.

public rawUrlEncodeUsernamePassword(string $url) : string

This will not encode other parts.

Parameters
$url : string

The original URL without encoded.

Tags
since
1.0.5
Return values
string

Return URL encoded only username and password.

removeQuerystring()

Remove query string.

public removeQuerystring(string $url) : string
Parameters
$url : string
Return values
string

removeUnsafeUrlCharacters()

Remove unsafe URL characters but not URL encode.

public removeUnsafeUrlCharacters(string $name[, bool $alphanumOnly = false ]) : string

This will not remove new line (if $alphanumOnly is false).

Parameters
$name : string

The URL name.

$alphanumOnly : bool = false

Alpha-numeric only or not. Default is false (not).

Tags
since
1.0.2
link

URL specific.

link

Reference.

link

Reference.

link

Multiple line regular expression reference.

returns

string Return formatted URL name.

Return values
string

        
On this page

Search results