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_Mapper

The mapper class handles URL generation and recognition for web applications

The mapper class is built by handling associated arrays of information and passing associated arrays back to the application for it to handle and dispatch the appropriate scripts.

Package: Routes
Located at Horde/Routes/Mapper.php
Methods summary
public
# __construct( mixed $kargs = array() )

Constructor.

Constructor.

Keyword arguments ($kargs): controllerScan (callback) Function to return an array of valid controllers redirect (callback) Function to perform a redirect for Horde_Routes_Utils->redirectTo() directory (string) Path to the directory that will be passed to the controllerScan callback alwaysScan (boolean) Should the controllerScan callback be called before every URL match? explicit (boolean) Should routes be connected with the implicit defaults of array('controller'=>'content', 'action'=>'index', 'id'=>null)? When set to True, these will not be added to route connections.

public
# connect( mixed $first, mixed $second = null, mixed $third = null )

Create and connect a new Route to the Mapper.

Create and connect a new Route to the Mapper.

Usage: $m = new Horde_Routes_Mapper(); $m->connect(':controller/:action/:id'); $m->connect('date/:year/:month/:day', array('controller' => "blog", 'action' => 'view'); $m->connect('archives/:page', array('controller' => 'blog', 'action' => 'by_page', ' requirements' => array('page' => '\d{1,2}'))); $m->connect('category_list', 'archives/category/:section', array('controller' => 'blog', 'action' => 'category', 'section' => 'home', 'type' => 'list')); $m->connect('home', '', array('controller' => 'blog', 'action' => 'view', 'section' => 'home'));

Parameters

$first
First argument in vargs, see usage above.
$second
Second argument in varags
$third
Third argument in varargs
public
# setCache( Horde_Cache $cache )

Set an optional Horde_Cache object for the created rules.

Set an optional Horde_Cache object for the created rules.

Parameters

$cache
Cache object
public
# createRegs( array $clist = null )

Creates the regexes for all connected routes

Creates the regexes for all connected routes

Parameters

$clist
controller list, controller_scan will be used otherwise
public
# match( string $url )

Match a URL against one of the routes contained. It will return null if no valid match is found.

Match a URL against one of the routes contained. It will return null if no valid match is found.

Usage: $resultdict = $m->match('/joe/sixpack');

Parameters

$url
URL to match
public
# routematch( string $url )

Match a URL against one of the routes contained. It will return null if no valid match is found, otherwise a result dict (array) and a route object is returned.

Match a URL against one of the routes contained. It will return null if no valid match is found, otherwise a result dict (array) and a route object is returned.

Usage: list($resultdict, $resultobj) = $m->match('/joe/sixpack');

Parameters

$url
URL to match
public null|string
# generate( array $first = null, array $second = null )

Generates the URL from a given set of keywords Returns the URL text, or null if no URL could be generated.

Generates the URL from a given set of keywords Returns the URL text, or null if no URL could be generated.

Usage: $m->generate(array('controller' => 'content', 'action' => 'view', 'id' => 10));

Parameters

$first
$routeArgs Optional explicit route list
$second
$kargs Keyword arguments (key/value pairs)

Returns

null|string
URL text or null
public
# resource( string $memberName, string $collectionName, array $kargs = array() )

Generate routes for a controller resource

Generate routes for a controller resource

The $memberName name should be the appropriate singular version of the resource given your locale and used with members of the collection.

The $collectionName name will be used to refer to the resource collection methods and should be a plural version of the $memberName argument. By default, the $memberName name will also be assumed to map to a controller you create.

The concept of a web resource maps somewhat directly to 'CRUD' operations. The overlying things to keep in mind is that mapping a resource is about handling creating, viewing, and editing that resource.

All keyword arguments ($kargs) are optional.

controller If specified in the keyword args, the controller will be the actual controller used, but the rest of the naming conventions used for the route names and URL paths are unchanged.

collection Additional action mappings used to manipulate/view the entire set of resources provided by the controller. Example:: $map->resource('message', 'messages', array('collection' => array('rss' => 'GET))); # GET /message;rss (maps to the rss action) # also adds named route "rss_message"

member Additional action mappings used to access an individual 'member' of this controllers resources. Example:: $map->resource('message', 'messages', array('member' => array('mark' => 'POST'))); # POST /message/1;mark (maps to the mark action) # also adds named route "mark_message" new Action mappings that involve dealing with a new member in the controller resources. Example:: $map->resource('message', 'messages', array('new' => array('preview' => 'POST'))); # POST /message/new;preview (maps to the preview action) # also adds a url named "preview_new_message" pathPrefix Prepends the URL path for the Route with the pathPrefix given. This is most useful for cases where you want to mix resources or relations between resources. namePrefix Perpends the route names that are generated with the namePrefix given. Combined with the pathPrefix option, it's easy to generate route names and paths that represent resources that are in relations. Example:: map.resource('message', 'messages', array('controller' => 'categories', 'pathPrefix' => '/category/:category_id', 'namePrefix' => 'category_'))); # GET /category/7/message/1 # has named route "category_message" parentResource An assoc. array containing information about the parent resource, for creating a nested resource. It should contain the $memberName and collectionName of the parent resource. This assoc. array will be available via the associated Route object which can be accessed during a request via request.environ['routes.route'] If parentResource is supplied and pathPrefix isn't, pathPrefix will be generated from parentResource as "/:_id". If parentResource is supplied and namePrefix isn't, namePrefix will be generated from parentResource as "_". Example:: $m = new Horde_Routes_Mapper(); $utils = $m->utils; $m->resource('location', 'locations', array('parentResource' => array('memberName' => 'region', 'collectionName' => 'regions')))); # pathPrefix is "regions/:region_id" # namePrefix is "region_" $utils->urlFor('region_locations', array('region_id'=>13)); # '/regions/13/locations' $utils->urlFor('region_new_location', array('region_id'=>13)); # '/regions/13/locations/new' $utils->urlFor('region_location', array('region_id'=>13, 'id'=>60)); # '/regions/13/locations/60' $utils->urlFor('region_edit_location', array('region_id'=>13, 'id'=>60)); # '/regions/13/locations/60/edit' Overriding generated pathPrefix:: $m = new Horde_Routes_Mapper(); $utils = new Horde_Routes_Utils(); $m->resource('location', 'locations', array('parentResource' => array('memberName' => 'region', 'collectionName' => 'regions'), 'pathPrefix' => 'areas/:area_id'))); # name prefix is "region_" $utils->urlFor('region_locations', array('area_id'=>51)); # '/areas/51/locations' Overriding generated namePrefix:: $m = new Horde_Routes_Mapper $m->resource('location', 'locations', array('parentResource' => array('memberName' => 'region', 'collectionName' => 'regions'), 'namePrefix' => ''))); # pathPrefix is "regions/:region_id" $utils->urlFor('locations', array('region_id'=>51)); # '/regions/51/locations'

Note: Since Horde Routes 0.2.0 and Python Routes 1.8, this method is not compatible with earlier versions inasmuch as the semicolon is no longer used to delimit custom actions. This was a change in Rails itself (http://dev.rubyonrails.org/changeset/6485) and adopting it here allows us to keep parity with Rails and ActiveResource.

Parameters

$memberName
Singular version of the resource name
$collectionName
Collection name (plural of $memberName)
$kargs
Keyword arguments (see above)
Properties summary
public array $environ

Filtered request environment with keys like SCRIPT_NAME

Filtered request environment with keys like SCRIPT_NAME

# array()
public callable $controllerScan

Callback function used to get array of controller names

Callback function used to get array of controller names

#
public string $directory

Path to controller directory passed to controllerScan function

Path to controller directory passed to controllerScan function

#
public boolean $alwaysScan

Call controllerScan callback before every route match?

Call controllerScan callback before every route match?

#
public boolean $explicit

Disable route memory and implicit defaults?

Disable route memory and implicit defaults?

#
public boolean $debug

Collect debug information during route match?

Collect debug information during route match?

# false
public boolean $subDomains

Use sub-domain support?

Use sub-domain support?

# false
public array $subDomainsIgnore

Array of sub-domains to ignore if using sub-domain support

Array of sub-domains to ignore if using sub-domain support

# array()
public boolean $appendSlash

Append trailing slash ('/') to generated routes?

Append trailing slash ('/') to generated routes?

# false
public null|string $prefix

Prefix to strip during matching and to append during generation

Prefix to strip during matching and to append during generation

# null
public array $matchList

Array of connected routes

Array of connected routes

# array()
public array $routeNames

Array of connected named routes, indexed by name

Array of connected named routes, indexed by name

# array()
public array $urlCache

Cache of URLs used in generate()

Cache of URLs used in generate()

# array()
public string $encoding

Encoding of routes URLs (not yet supported)

Encoding of routes URLs (not yet supported)

# 'utf-8'
public string $decodeErrors

What to do on decoding errors? 'ignore' or 'replace'

What to do on decoding errors? 'ignore' or 'replace'

# 'ignore'
public string $domainMatch

Partial regexp used to match domain part of the end of URLs to match

Partial regexp used to match domain part of the end of URLs to match

# '[^\.\/]+?\.[^\.\/]+'
public array $maxKeys

Array of all connected routes, indexed by the serialized array of all keys that each route could utilize.

Array of all connected routes, indexed by the serialized array of all keys that each route could utilize.

# array()
public array $minKeys

Array of all connected routes, indexed by the serialized array of the minimum keys that each route needs.

Array of all connected routes, indexed by the serialized array of the minimum keys that each route needs.

# array()
public Horde_Routes_Utils $utils

Utility functions like urlFor() and redirectTo() for this Mapper

Utility functions like urlFor() and redirectTo() for this Mapper

#
public Horde_Cache $cache

Cache

Cache

#
public integer $cacheLifetime

Cache lifetime for the same value of $this->matchList

Cache lifetime for the same value of $this->matchList

# 86400
API documentation generated by ApiGen