Perforce Chronicle 2012.2/486814
API Documentation

Url_Route Class Reference

A route that matches/assembles url paths using custom url records. More...

List of all members.

Public Member Functions

 assemble ($data=array(), $reset=true, $encode=false)
 Attempt to return a path for the given route parameters.
 getCurrentUrl ()
 Get the last matched url record.
 getVersion ()
 Get the version of the route.
 match ($match)
 Look for a custom url.
 setMatchDeleted ($matchDeleted)
 Control whether or not route will match on deleted custom urls.

Static Public Member Functions

static getInstance (Zend_Config $config)
 Implemented out of obligation as required by the interface.

Protected Attributes

 $_currentUrl = null
 $_matchDeleted = true

Detailed Description

A route that matches/assembles url paths using custom url records.

Copyright:
2011-2012 Perforce Software. All rights reserved
License:
Please see LICENSE.txt in top-level folder of this distribution.
Version:
2012.2/486814

Member Function Documentation

Url_Route::assemble ( data = array(),
reset = true,
encode = false 
)

Attempt to return a path for the given route parameters.

If no custom url is defined for the given params ('data') throws an exception.

Parameters:
array$datathe route parameters to assemble path for.
bool$resetthis parameter has no effect - we always reset
bool$encodethis parameter has no effect - paths are always encoded
Returns:
string the assembled/matching url path.
Exceptions:
P4Cms_Record_NotFoundExceptionif no path can be found for the given params.
    {
        return Url_Model_Url::fetchByParams($data)->getPath();
    }
Url_Route::getCurrentUrl ( )

Get the last matched url record.

Returns:
Url_Model_Url|null the last matched url or null if none matched.
    {
        return $this->_currentUrl;
    }
static Url_Route::getInstance ( Zend_Config $  config) [static]

Implemented out of obligation as required by the interface.

Always returns a new instance of this route class.

Parameters:
Zend_Config$configroute configuration information (we ignore)
Returns:
Url_Route a new instance of this route class.
    {
        return new static;
    }
Url_Route::getVersion ( )

Get the version of the route.

We do this to make the rewrite router passing the whole request to our match() method.

Returns:
integer route version
    {
        return 2;
    }
Url_Route::match ( match)

Look for a custom url.

Parameters:
string | Zend_Controller_Request_Abstract$matcheither http request or the url path to lookup params for
Returns:
array|false params for the given path or false if no matching record found.
    {
        // set request and path based on the type of the $match parameter
        $request = $match instanceof Zend_Controller_Request_Abstract ? $match : null;
        $path    = $request ? $request->getPathInfo() : $match;

        try {
            // look for a custom url matching path
            // if match deleted is true, honors even deleted url records.
            $this->_currentUrl = Url_Model_Url::fetch(
                $path, array('includeDeleted' => $this->_matchDeleted)
            );

            $params = $this->_currentUrl->getParams();

            // set action from the request if present
            if ($request && $request->getParam('action')) {
                $params['action'] = $request->getParam('action');
            }

            return $params;
        } catch (P4Cms_Record_NotFoundException $e) {
            return false;
        }
    }
Url_Route::setMatchDeleted ( matchDeleted)

Control whether or not route will match on deleted custom urls.

Default behavior is to match on deleted urls (to avoid breaking links).

Parameters:
bool$matchDeletedtrue to match deleted; false to ignore.
Returns:
Url_Route provides fluent interface.
    {
        $this->_matchDeleted = (bool) $matchDeleted;

        return $this;
    }

Member Data Documentation

Url_Route::$_currentUrl = null [protected]
Url_Route::$_matchDeleted = true [protected]

The documentation for this class was generated from the following file: