PHP Class Habari\URL

Inheritance: extends Singleton
ファイルを表示 Open project: habari/system Class Usage Examples

Public Methods

Method Description
ajax ( string $context, array | string | object $args = [] ) : string Helper method for ajax rule
auth_ajax ( string $context, array | string | object $args = [] ) : string Helper method for auth_ajax rule
extract_args ( mixed $args, string $prefix = '' ) : array Extract the possible arguments to use in the URL from the passed variable
get ( mixed $rule_names = '', mixed $args = [], boolean $useall = true, boolean $noamp = false, boolean $prepend_site = true ) : string Builds the required pretty URL given a supplied rule name and a set of placeholder replacement values and returns the built URL.
get_active_rules ( ) : array Get the active RewriteRules that are cached in self::load_rules().
get_from_filesystem ( string $path, string | boolean $trail = false, boolean $preserve_file = false ) : string Get a fully-qualified URL from a filesystem path
get_matched_rule ( ) : RewriteRule Get the matched RewriteRule that was matched in parse().
out ( string $rule_name = null, array $args = [], boolean $useall = true, boolean $noamp = true, boolean $prepend_site = true ) : void Helper wrapper function. Outputs the URL via echo.
parse ( string $from_url ) : RewriteRule Match a URL/URI against the rewrite rules stored in the DB.
set_404 ( ) : RewriteRule Cause the matched rule to be unset in the case of a 404

Protected Methods

Method Description
instance ( ) Enables singleton working properly

Private Methods

Method Description
load_rules ( ) A simple caching mechanism to avoid reloading rule array

Method Details

ajax() public static method

Helper method for ajax rule
public static ajax ( string $context, array | string | object $args = [] ) : string
$context string The context of the ajax rule
$args array | string | object The arguments to pass to the rule's builder
return string The resultant URL

auth_ajax() public static method

Helper method for auth_ajax rule
public static auth_ajax ( string $context, array | string | object $args = [] ) : string
$context string The context of the ajax rule
$args array | string | object The arguments to pass to the rule's builder
return string The resultant URL

extract_args() public static method

Extract the possible arguments to use in the URL from the passed variable
public static extract_args ( mixed $args, string $prefix = '' ) : array
$args mixed An array of values or a URLProperties object with properties to use in the construction of a URL
$prefix string
return array Properties to use to construct a URL

get() public static method

URL::get( 'display_entries_by_date', array( 'year' => '2000', 'month' => '05', 'day' => '01', ) );
public static get ( mixed $rule_names = '', mixed $args = [], boolean $useall = true, boolean $noamp = false, boolean $prepend_site = true ) : string
$rule_names mixed string name of the rule or array of rules which would build the URL
$args mixed (optional) array or object of placeholder replacement values
$useall boolean If true (default), then all passed parameters that are not part of the built URL are tacked onto the URL as querystring
$noamp boolean
$prepend_site boolean If true (default), a full URL is returned, if false, only the path part of the URL is returned
return string

get_active_rules() public static method

Get the active RewriteRules that are cached in self::load_rules().
public static get_active_rules ( ) : array
return array RewriteRules active rules, or null

get_from_filesystem() public static method

Get a fully-qualified URL from a filesystem path
public static get_from_filesystem ( string $path, string | boolean $trail = false, boolean $preserve_file = false ) : string
$path string The filesystem path
$trail string | boolean If true, include a trailing slash. If string, append this to the requested url. Default: Add nothing.
$preserve_file boolean If true, leave the filename on the URL. Default: Remove filename.
return string URL

get_matched_rule() public static method

Get the matched RewriteRule that was matched in parse().
public static get_matched_rule ( ) : RewriteRule
return RewriteRule matched rule, or null

instance() protected static method

Enables singleton working properly
protected static instance ( )

out() public static method

Helper wrapper function. Outputs the URL via echo.
public static out ( string $rule_name = null, array $args = [], boolean $useall = true, boolean $noamp = true, boolean $prepend_site = true ) : void
$rule_name string name of the rule which would build the URL
$args array (optional) array of placeholder replacement values
$useall boolean If true (default), then all passed parameters that are not part of the built URL are tacked onto the URL as querystring
$noamp boolean
$prepend_site boolean If true (default), a full URL is returned, if false, only the path part of the URL is returned
return void

parse() public static method

This method is used by the Controller class for parsing requests, and by other classes, such as Pingback, which uses it to determine the post slug for a given URL. Returns the matched RewriteRule object, or false.
public static parse ( string $from_url ) : RewriteRule
$from_url string URL string to parse
return RewriteRule matched rule, or false

set_404() public static method

Cause the matched rule to be unset in the case of a 404
public static set_404 ( ) : RewriteRule
return RewriteRule A rewrite rule that represents a 404 error - no match on the URL requested