eZPublish  4.5
eZURLWildcard Class Reference

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

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

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. More...
 
 eZURLWildcard ($row)
 Initializes a new URL alias persistent object. More...
 
 store ($fieldFilters=null)
 Stores the eZURLWildcard persistent object. More...
 
- Public Member Functions inherited from eZPersistentObject
 attribute ($attr, $noFunction=false)
 
 attributes ()
 
 eZPersistentObject ($row)
 
 fill ($row)
 
 hasAttribute ($attr)
 
 hasDirtyData ()
 
 remove ($conditions=null, $extraConditions=null)
 
 setAttribute ($attr, $val)
 
 setHasDirtyData ($hasDirtyData)
 
 store ($fieldFilters=null)
 
 sync ($fieldFilters=null)
 

Static Public Member Functions

static cleanup ($baseURL)
 Removes a wildcard based on a source_url. More...
 
static definition ()
 
static expireCache ()
 Expires the wildcard cache. More...
 
static fetch ($id, $asObject=true)
 Fetch a wildcard by numerical ID. More...
 
static fetchBySourceURL ($url, $asObject=true)
 Fetches a wildcard by source url. More...
 
static fetchCacheFile ($filepath)
 Includes a wildcard cache file and returns its return value This method is used as a callback by eZClusterFileHandler::processFile. More...
 
static fetchList ($offset=false, $limit=false, $asObject=true)
 Fetches the list of URL wildcards. More...
 
static fetchListCount ()
 Returns the number of wildcards in the database without any filtering. More...
 
static isCacheExpired ($timestamp)
 Checks if the wildcard cache is expired. More...
 
static removeAll ()
 Removes all the wildcards. More...
 
static removeByIDs ($idList)
 Removes wildcards based on an ID list. More...
 
static translate (&$uri)
 Transforms the URI if there exists an alias for it. More...
 
- Static Public Member Functions inherited from eZPersistentObject
static conditionText ($conditions)
 
static conditionTextByRow ($conditions, $row)
 
static count ($def, $conds=null, $field=null)
 
static definition ()
 
static escapeArray ($array)
 
static fetchObject ($def, $field_filters, $conds, $asObject=true, $grouping=null, $custom_fields=null)
 
static fetchObjectList ($def, $field_filters=null, $conds=null, $sorts=null, $limit=null, $asObject=true, $grouping=false, $custom_fields=null, $custom_tables=null, $custom_conds=null)
 
static getShortAttributeName ($db, $def, $attrName)
 
static handleRows ($rows, $class_name, $asObject)
 
static newObjectOrder ($def, $orderField, $conditions)
 
static removeObject ($def, $conditions=null, $extraConditions=null)
 
static reorderObject ($def, $orderField, $conditions, $down=true)
 
static swapRow ($table, $keys, $order_id, $rows, $id1, $id2)
 
static updateObjectList ($parameters)
 

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
 
- Public Attributes inherited from eZPersistentObject
 $PersistentDataDirty
 Whether the data is dirty, ie needs to be stored, or not. More...
 

Static Protected Member Functions

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

Static Protected Attributes

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

Detailed Description

Handles URL alias wildcards in eZ Publish.

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
static eZURLWildcard::cacheInfo ( )
staticprotected

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
static eZURLWildcard::cacheInfoDirectories ( $wildcardCacheDir,
$wildcardCacheFile,
$wildcardCachePath,
$wildcardKeys 
)
staticprotected

Sets the various cache information to the parameters.

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
static eZURLWildcard::createWildcardsIndex ( )
staticprotected

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
static eZURLWildcard::definition ( )
static
static eZURLWildcard::expireCache ( )
static

Expires the wildcard cache.

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

Returns
void
static eZURLWildcard::expiryTimestamp ( )
staticprotected

Returns the expiry timestamp for wildcard cache from eZExpiryHandler.

Returns
int|bool the timestamp if set, false otherwise
eZURLWildcard::eZURLWildcard (   $row)

Initializes a new URL alias persistent object.

Parameters
array$row
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
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
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
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]
static eZURLWildcard::fetchListCount ( )
static

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

Returns
int Number of wildcards in the database
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
static eZURLWildcard::loadCacheFile (   $cacheID = 'index')
staticprotected

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
static eZURLWildcard::matchRegexpCode (   $wildcard)
staticprotected

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
static eZURLWildcard::matchReplaceCode (   $wildcard)
staticprotected

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
static eZURLWildcard::removeAll ( )
static

Removes all the wildcards.

Returns
void
static eZURLWildcard::removeByIDs (   $idList)
static

Removes wildcards based on an ID list.

Parameters
array$idListarray of numerical ID
Returns
void
eZURLWildcard::store (   $fieldFilters = null)

Stores the eZURLWildcard persistent object.

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
static eZURLWildcard::translateWithCache (   $wildcardNum,
$uri,
$wildcardInfo,
  $matchRegexp 
)
staticprotected

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
static eZURLWildcard::wildcardsIndex ( )
staticprotected

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

Member Data Documentation

eZURLWildcard::$cacheFiles = array()
staticprotected
eZURLWildcard::$wildcardsIndex = null
staticprotected
const eZURLWildcard::CACHE_SIGNATURE = 'urlalias-wildcard'
const eZURLWildcard::TYPE_DIRECT = 2
const eZURLWildcard::TYPE_FORWARD = 1
const eZURLWildcard::TYPE_NONE = 0
const eZURLWildcard::WILDCARDS_PER_CACHE_FILE = 100

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