eZ Publish  [4.2]
eZURLWildcard Class Reference

Handles URL alias wildcards in eZ Publish. More...

+ Inheritance diagram for eZURLWildcard:
+ Collaboration diagram for eZURLWildcard:

List of all members.

Public Member Functions

 asArray ()
 Converts the url wildcard object to an associative array with the attribute names as array keys and the values as array values.
 eZURLWildcard ($row)
 Initializes a new URL alias persistent object.
 store ($fieldFilters=null)
 Stores the eZURLWildcard persistent object.

Static Public Member Functions

static cleanup ($baseURL)
 Removes a wildcard based on a source_url.
static definition ()
static expireCache ()
 Expires the wildcard cache.
static fetch ($id, $asObject=true)
 Fetch a wildcard by numerical ID.
static fetchBySourceURL ($url, $asObject=true)
 Fetches a wildcard by source url.
static fetchCacheFile ($filepath)
 Includes a wildcard cache file and returns its return value This method is used as a callback by eZClusterFileHandler::processFile.
static fetchList ($offset=false, $limit=false, $asObject=true)
 Fetches the list of URL wildcards.
static fetchListCount ()
 Returns the number of wildcards in the database without any filtering.
static isCacheExpired ($timestamp)
 Checks if the wildcard cache is expired.
static removeAll ()
 Removes all the wildcards.
static removeByIDs ($idList)
 Removes wildcards based on an ID list.
static translate (&$uri)
 Transforms the URI if there exists an alias for it.

Public Attributes

const CACHE_SIGNATURE = 'urlalias-wildcard'
const TYPE_DIRECT = 2
const TYPE_FORWARD = 1
const TYPE_NONE = 0
const WILDCARDS_PER_CACHE_FILE = 100

Static Protected Member Functions

static cacheInfo ()
 Returns an array with information on the wildcard cache The array containst the following keys.
static cacheInfoDirectories (&$wildcardCacheDir, &$wildcardCacheFile, &$wildcardCachePath, &$wildcardKeys)
 Sets the various cache information to the parameters.
static createWildcardsIndex ()
 Create the wildcard cache.
static expiryTimestamp ()
 Returns the expiry timestamp for wildcard cache from eZExpiryHandler.
static loadCacheFile ($cacheID= 'index')
 Loads and returns the cluster handler instance for the requested cache file.
static matchRegexpCode ($wildcard)
 Transforms the source-url of a wildcard to a preg_match compatible expression Example: foo/* will be converted to #^foo/(.
static matchReplaceCode ($wildcard)
 Converts the destination-url of a wildcard to a preg_replace compatible expression.
static translateWithCache ($wildcardNum, &$uri, &$wildcardInfo, $matchRegexp)
 The callback loads appropriate cache file for wildcard $wildcardNum, extracts wildcard info and 'replace' url from cache.
static wildcardsIndex ()
 Assign function names to input variables.

Static Protected Attributes

static $cacheFiles = array()
static $wildcardsIndex = null

Detailed Description

Handles URL alias wildcards in eZ Publish.

Definition at line 41 of file ezurlwildcard.php.


Member Function Documentation

eZURLWildcard::asArray ( )

Converts the url wildcard object to an associative array with the attribute names as array keys and the values as array values.

Returns:
array

Definition at line 115 of file ezurlwildcard.php.

static eZURLWildcard::cacheInfo ( ) [static, protected]

Returns an array with information on the wildcard cache The array containst the following keys.

  • dir - The directory for the cache
  • file - The base filename for the caches
  • path - The entire path (including filename) for the cache
  • keys - Array with key values which is used to uniquely identify the cache
    Returns:
    array

Definition at line 382 of file ezurlwildcard.php.

Referenced by cacheInfoDirectories(), and loadCacheFile().

static eZURLWildcard::cacheInfoDirectories ( &$  wildcardCacheDir,
&$  wildcardCacheFile,
&$  wildcardCachePath,
&$  wildcardKeys 
) [static, protected]

Sets the various cache information to the parameters.

Definition at line 410 of file ezurlwildcard.php.

Referenced by createWildcardsIndex().

static eZURLWildcard::cleanup ( baseURL) [static]

Removes a wildcard based on a source_url.

The URL should be provided without the /* prefix: foobar will remove the wildcard with source_url = foobar/*

Parameters:
string$baseURLURL prefix matched against destination_url
Returns:
void

Definition at line 138 of file ezurlwildcard.php.

static eZURLWildcard::createWildcardsIndex ( ) [static, protected]

Create the wildcard cache.

The wildcard caches are splitted between several files: 'wildcard_<md5>_index.php': contains regexps for wildcards 'wildcard_<md5>_0.php', 'wildcard_<md5>_1.php', ... 'wildcard_<md5>_N.php': contains cached wildcards. Each file has info about eZURLWildcard::WILDCARDS_PER_CACHE_FILE wildcards.

Returns:
void

Definition at line 503 of file ezurlwildcard.php.

Referenced by wildcardsIndex().

static eZURLWildcard::definition ( ) [static]
Returns:
the definition for the object, the default implementation is to return an empty array. It's upto each inheriting class to return a proper definition array.

The definition array is an associative array consists of these keys:

  • fields - an associative array of fields which defines which database field (the key) is to fetched and how they map to object member variables (the value).
  • keys - an array of fields which is used for uniquely identifying the object in the table.
  • function_attributes - an associative array of attributes which maps to member functions, used for fetching data with functions.
  • set_functions - an associative array of attributes which maps to member functions, used for setting data with functions.
  • increment_key - the field which is incremented on table inserts.
  • class_name - the classname which is used for instantiating new objecs when fetching from the database.
  • sort - an associative array which defines the default sorting of lists, the key is the table field while the value is the sorting method which is either asc or desc.
  • name - the name of the database table

Example:

static function definition()
{
    return array( "fields" => array( "id" => "ID",
                                     "version" => "Version",
                                     "name" => "Name" ),
                  "keys" => array( "id", "version" ),
                  "function_attributes" => array( "current" => "currentVersion",
                                                  "class_name" => "className" ),
                  "increment_key" => "id",
                  "class_name" => "eZContentClass",
                  "sort" => array( "id" => "asc" ),
                  "name" => "ezcontentclass" );
}

Reimplemented from eZPersistentObject.

Definition at line 84 of file ezurlwildcard.php.

static eZURLWildcard::expireCache ( ) [static]

Expires the wildcard cache.

This causes the wildcard cache to be regenerated on the next page load.

Returns:
void

Definition at line 424 of file ezurlwildcard.php.

Referenced by cleanup(), and removeAll().

static eZURLWildcard::expiryTimestamp ( ) [static, protected]

Returns the expiry timestamp for wildcard cache from eZExpiryHandler.

Returns:
int|bool the timestamp if set, false otherwise

Definition at line 437 of file ezurlwildcard.php.

eZURLWildcard::eZURLWildcard ( row)

Initializes a new URL alias persistent object.

Parameters:
array$row

Definition at line 79 of file ezurlwildcard.php.

static eZURLWildcard::fetch ( id,
asObject = true 
) [static]

Fetch a wildcard by numerical ID.

Parameters:
int$id
bool$asObject
Returns:
eZURLWildcard null if no match was found

Definition at line 186 of file ezurlwildcard.php.

static eZURLWildcard::fetchBySourceURL ( url,
asObject = true 
) [static]

Fetches a wildcard by source url.

Parameters:
string$urlSource URL
bool$asObject
Returns:
eZURLWildcard Null if no match was found

Definition at line 200 of file ezurlwildcard.php.

static eZURLWildcard::fetchCacheFile ( filepath) [static]

Includes a wildcard cache file and returns its return value This method is used as a callback by eZClusterFileHandler::processFile.

Parameters:
string$filepath
Returns:
array

Definition at line 690 of file ezurlwildcard.php.

static eZURLWildcard::fetchList ( offset = false,
limit = false,
asObject = true 
) [static]

Fetches the list of URL wildcards.

By defaults, fetches all the wildcards

Parameters:
int$offsetOffset to limit the list from
int$limitLimit to the number of fetched items
bool$asObject
Returns:
array[eZURLWildcard]

Definition at line 215 of file ezurlwildcard.php.

Referenced by createWildcardsIndex().

static eZURLWildcard::fetchListCount ( ) [static]

Returns the number of wildcards in the database without any filtering.

Returns:
int Number of wildcards in the database

Definition at line 229 of file ezurlwildcard.php.

static eZURLWildcard::isCacheExpired ( timestamp) [static]

Checks if the wildcard cache is expired.

Parameters:
int$timestampTimestamp expiry should be checked against
Returns:
bool true if cache is expired
Deprecated:
since 4.2.0

Definition at line 459 of file ezurlwildcard.php.

static eZURLWildcard::loadCacheFile ( cacheID = 'index') [static, protected]

Loads and returns the cluster handler instance for the requested cache file.

The instance will be returned even if the file doesn't exist

Parameters:
$cacheIDCache file number. Will load the index if not provided.
Returns:
eZClusterFileHandlerInterface

Definition at line 668 of file ezurlwildcard.php.

Referenced by createWildcardsIndex(), translateWithCache(), and wildcardsIndex().

static eZURLWildcard::matchRegexpCode ( wildcard) [static, protected]

Transforms the source-url of a wildcard to a preg_match compatible expression Example: foo/* will be converted to #^foo/(.

*)$#

Parameters:
array$wildcardwildcard data with a source_url key
Returns:
string preg_match compatible string

Definition at line 559 of file ezurlwildcard.php.

Referenced by createWildcardsIndex().

static eZURLWildcard::matchReplaceCode ( wildcard) [static, protected]

Converts the destination-url of a wildcard to a preg_replace compatible expression.

Example: foobar/{1} will be converted to ...

Todo:
fix the example
Parameters:
array$wildcardWildcard array with a destination_url key
Returns:
string match/replace PHP Code
Todo:
Try to replace the eval'd code with a preg_replace expression

Definition at line 587 of file ezurlwildcard.php.

Referenced by createWildcardsIndex().

static eZURLWildcard::removeAll ( ) [static]

Removes all the wildcards.

Returns:
void

Definition at line 152 of file ezurlwildcard.php.

static eZURLWildcard::removeByIDs ( idList) [static]

Removes wildcards based on an ID list.

Parameters:
array$idListarray of numerical ID
Returns:
void

Definition at line 163 of file ezurlwildcard.php.

eZURLWildcard::store ( fieldFilters = null)

Stores the eZURLWildcard persistent object.

Reimplemented from eZPersistentObject.

Definition at line 126 of file ezurlwildcard.php.

static eZURLWildcard::translate ( &$  uri) [static]

Transforms the URI if there exists an alias for it.

Parameters:
eZURI | string$uri
Returns:
mixed The translated URI if the resource has moved, or true|false if translation was (un)successful

Definition at line 249 of file ezurlwildcard.php.

static eZURLWildcard::translateWithCache ( wildcardNum,
&$  uri,
&$  wildcardInfo,
matchRegexp 
) [static, protected]

The callback loads appropriate cache file for wildcard $wildcardNum, extracts wildcard info and 'replace' url from cache.

The wildcard number (not a wildcard id) is used here in order to load the appropriate cache file.

If it's needed to fetch wildcard from db, use eZURLWildcard::fetchList with offset = $wildcardNum and $limit = 1.

Parameters:
int$wildcardNum
eZURI | string$uri
mixed$wildcardInfo
mixed$matches
Returns:
bool
Todo:
make private, this method isn't used anywhere else

Definition at line 633 of file ezurlwildcard.php.

Referenced by translate().

static eZURLWildcard::wildcardsIndex ( ) [static, protected]

Assign function names to input variables.

Generates the wildcard cache if expired.

Parameters:
$regexpArrayCallbackfunction to get an array of regexps
Returns:
array The wildcards index, as an array of regexps

Definition at line 472 of file ezurlwildcard.php.


Member Data Documentation

eZURLWildcard::$cacheFiles = array() [static, protected]

Definition at line 67 of file ezurlwildcard.php.

eZURLWildcard::$wildcardsIndex = null [static, protected]

Definition at line 73 of file ezurlwildcard.php.

Referenced by createWildcardsIndex(), and wildcardsIndex().

const eZURLWildcard::CACHE_SIGNATURE = 'urlalias-wildcard'

Definition at line 61 of file ezurlwildcard.php.

Definition at line 55 of file ezurlwildcard.php.

Definition at line 54 of file ezurlwildcard.php.

Definition at line 53 of file ezurlwildcard.php.

Definition at line 47 of file ezurlwildcard.php.

Referenced by createWildcardsIndex().


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