Utils
in package
Utility functions for use in templates and controllers
Table of Contents
- $mapper : Mapper
- $mapperDict : array<string|int, mixed>
- Match data from last match; implements for urlFor() route memory
- $redirect : callable
- Callback function used for redirectTo()
- __construct() : mixed
- Constructor
- arraySubtract() : mixed
- controllerScan() : array<string|int, mixed>
- Scan a directory for PHP files and use them as controllers. Used as the default scanner callback for Horde_Routes_Mapper. See the constructor of that class for more information.
- longestFirst() : int
- Callback used by usort() in controllerScan() to sort controller names by the longest first.
- printRoutes() : void
- Pretty-print a listing of the routes connected to the mapper.
- redirectTo() : mixed
- Issues a redirect based on the arguments.
- urlFor() : mixed
- Generates a URL.
- urlQuote() : mixed
- Quote a string containing a URL in a given encoding.
- _screenArgs() : mixed
- Private function that takes a dict, and screens it against the current request dict to determine what the dict should look like that is used.
- _subdomainCheck() : mixed
- Screen the kargs for a subdomain and alter it appropriately depending on the current subdomain or lack therof.
Properties
$mapper
public
Mapper
$mapper
$mapperDict
Match data from last match; implements for urlFor() route memory
public
array<string|int, mixed>
$mapperDict
= []
$redirect
Callback function used for redirectTo()
public
callable
$redirect
Methods
__construct()
Constructor
public
__construct(Mapper $mapper[, callable $redirect = null ]) : mixed
Parameters
- $mapper : Mapper
-
Mapper for these utilities
- $redirect : callable = null
-
Redirect callback for redirectTo()
Return values
mixed —arraySubtract()
public
static arraySubtract(mixed $a1, mixed $a2) : mixed
Parameters
- $a1 : mixed
- $a2 : mixed
Return values
mixed —controllerScan()
Scan a directory for PHP files and use them as controllers. Used as the default scanner callback for Horde_Routes_Mapper. See the constructor of that class for more information.
public
static controllerScan([string $dirname = null ][, string $prefix = '' ]) : array<string|int, mixed>
Given a directory with: foo.php, bar.php, baz.php Returns an array: foo, bar, baz
Parameters
- $dirname : string = null
-
Directory to scan for controller files
- $prefix : string = ''
-
Prefix controller names (optional)
Return values
array<string|int, mixed> —Array of controller names
longestFirst()
Callback used by usort() in controllerScan() to sort controller names by the longest first.
public
static longestFirst(string $fst, string $lst) : int
Parameters
- $fst : string
-
First string to compare
- $lst : string
-
Last string to compare
Return values
int —Difference of string length (first - last)
printRoutes()
Pretty-print a listing of the routes connected to the mapper.
public
printRoutes([resource|null $stream = null ][, string|null $eol = PHP_EOL ]) : void
Parameters
- $stream : resource|null = null
-
Output stream resource for printing (optional)
- $eol : string|null = PHP_EOL
-
Line ending (optional)
Return values
void —redirectTo()
Issues a redirect based on the arguments.
public
redirectTo([mixed $first = [] ][, mixed $second = [] ]) : mixed
Redirects should occur as a "302 Moved" header, however the web framework may utilize a different method.
All arguments are passed to urlFor() to retrieve the appropriate URL, then the resulting URL it sent to the redirect function as the URL.
Parameters
- $first : mixed = []
-
First argument in varargs, same as urlFor()
- $second : mixed = []
-
Second argument in varargs
Return values
mixed —Result of redirect callback
urlFor()
Generates a URL.
public
urlFor([mixed $first = [] ][, mixed $second = [] ]) : mixed
All keys given to urlFor are sent to the Routes Mapper instance for generation except for::
anchor specified the anchor name to be appened to the path
host overrides the default (current) host if provided
protocol overrides the default (current) protocol if provided
qualified creates the URL with the host/port information as
needed
The URL is generated based on the rest of the keys. When generating a new URL, values will be used from the current request's parameters (if present). The following rules are used to determine when and how to keep the current requests parameters:
- If the controller is present and begins with '/', no defaults are used
- If the controller is changed, action is set to 'index' unless otherwise specified
For example, if the current request yielded a dict (associative array) of array('controller'=>'blog', 'action'=>'view', 'id'=>2), with the standard ':controller/:action/:id' route, you'd get the following results::
urlFor(array('id'=>4)) => '/blog/view/4',
urlFor(array('controller'=>'/admin')) => '/admin',
urlFor(array('controller'=>'admin')) => '/admin/view/2'
urlFor(array('action'=>'edit')) => '/blog/edit/2',
urlFor(array('action'=>'list', id=NULL)) => '/blog/list'
Static and Named Routes
If there is a string present as the first argument, a lookup is done against the named routes table to see if there's any matching routes. The keyword defaults used with static routes will be sent in as GET query arg's if a route matches.
If no route by that name is found, the string is assumed to be a raw URL.
Should the raw URL begin with /
then appropriate SCRIPT_NAME data will
be added if present, otherwise the string will be used as the url with
keyword args becoming GET query args.
Parameters
- $first : mixed = []
- $second : mixed = []
Return values
mixed —urlQuote()
Quote a string containing a URL in a given encoding.
public
static urlQuote(string $url[, string $encoding = null ]) : mixed
Parameters
- $url : string
-
URL to encode
- $encoding : string = null
-
Encoding to use
Tags
Return values
mixed —_screenArgs()
Private function that takes a dict, and screens it against the current request dict to determine what the dict should look like that is used.
private
_screenArgs(mixed $kargs) : mixed
This is responsible for the requests "memory" of the current.
Parameters
- $kargs : mixed
Return values
mixed —_subdomainCheck()
Screen the kargs for a subdomain and alter it appropriately depending on the current subdomain or lack therof.
private
_subdomainCheck(mixed $kargs) : mixed
Parameters
- $kargs : mixed