Overview

Packages

  • Horde
    • Routes
  • Routes

Classes

  • Horde_Routes_Exception
  • Horde_Routes_Mapper
  • Horde_Routes_Printer
  • Horde_Routes_Route
  • Horde_Routes_Utils
  • Overview
  • Package
  • Class
  • Tree

Class Horde_Routes_Utils

Utility functions for use in templates and controllers

Package: Routes
Located at Horde/Routes/Utils.php
Methods summary
public
# __construct( Horde_Routes_Mapper $mapper, callable $redirect = null )

Constructor

Constructor

Parameters

$mapper
Mapper for these utilities
$redirect
Redirect callback for redirectTo()
public
# urlFor( mixed $first = array(), mixed $second = array() )

Generates a URL.

Generates a URL.

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.

public mixed
# redirectTo( mixed $first = array(), mixed $second = array() )

Issues a redirect based on the arguments.

Issues a redirect based on the arguments.

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
First argument in varargs, same as urlFor()
$second
Second argument in varargs

Returns

mixed
Result of redirect callback
public
# printRoutes( stream|null $stream = null, string|null $eol = PHP_EOL )

Pretty-print a listing of the routes connected to the mapper.

Pretty-print a listing of the routes connected to the mapper.

Parameters

$stream
Output stream for printing (optional)
$eol
Line ending (optional)
public static array
# controllerScan( string $dirname = null, string $prefix = '' )

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.

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.

Given a directory with: foo.php, bar.php, baz.php Returns an array: foo, bar, baz

Parameters

$dirname
Directory to scan for controller files
$prefix
Prefix controller names (optional)

Returns

array
Array of controller names
public static
# urlQuote( string $url, string $encoding = null )

Quote a string containing a URL in a given encoding.

Quote a string containing a URL in a given encoding.

Parameters

$url
URL to encode
$encoding
Encoding to use
public static integer
# longestFirst( string $fst, string $lst )

Callback used by usort() in controllerScan() to sort controller names by the longest first.

Callback used by usort() in controllerScan() to sort controller names by the longest first.

Parameters

$fst
First string to compare
$lst
Last string to compare

Returns

integer
Difference of string length (first - last)
public static
# arraySubtract( mixed $a1, mixed $a2 )
Properties summary
public Horde_Routes_Mapper $mapper
#
public array $mapperDict

Match data from last match; implements for urlFor() route memory

Match data from last match; implements for urlFor() route memory

# array()
public callable $redirect

Callback function used for redirectTo()

Callback function used for redirectTo()

#
API documentation generated by ApiGen