eZPublishCommunityProject(LegacyStack)  2013.6
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)
 Returns the attribute data for $attr, this is either returned from the member variables or a member function depending on whether the definition field or function attributes matched. More...
 
 attributes ()
 Returns the attributes for this object, taken from the definition fields and function attributes. More...
 
 eZPersistentObject ($row)
 Initializes the object with the $row. More...
 
 fill ($row)
 Tries to fill in the data in the object by using the object definition which is returned by the function definition() and the database row data $row. More...
 
 hasAttribute ($attr)
 Checks if $attr is part of the definition fields or function attributes. More...
 
 hasDirtyData ()
 Returns true if the data is considered dirty and needs to be stored. More...
 
 remove ($conditions=null, $extraConditions=null)
 Removes the object from the database, it will use the keys in the object definition to figure out which table row should be removed unless $conditions is defined as an array with fieldnames. More...
 
 setAttribute ($attr, $val)
 Sets the attribute $attr to the value $val. More...
 
 setHasDirtyData ($hasDirtyData)
 Sets whether the object has dirty data or not. More...
 
 store ($fieldFilters=null)
 Stores the object in the database, uses storeObject() to do the actual job and passes $fieldFilters to it. More...
 
 sync ($fieldFilters=null)
 Makes sure data is stored if the data is considered dirty. More...
 

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 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 wildcardExists ($uriString)
 Checks if $uriString exists as a wildcard. More...
 
- Static Public Member Functions inherited from eZPersistentObject
static conditionText ($conditions)
 Calls conditionTextByRow with an empty row and $conditions. More...
 
static conditionTextByRow ($conditions, $row)
 Generates an SQL sentence from the conditions $conditions and row data $row. More...
 
static count ($def, $conds=null, $field=null)
 Fetches the number of rows by using the object definition. More...
 
static definition ()
 Returns the definition for the object, the default implementation is to return an empty array. More...
 
static escapeArray ($array)
 Escapes strings in an array with the help of eZDBInterface::escapeString(). More...
 
static fetchObject ($def, $field_filters, $conds, $asObject=true, $grouping=null, $custom_fields=null)
 Fetches and returns an object based on the given parameters and returns is either as an object or as an array. More...
 
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)
 Creates an SQL query out of the different parameters and returns an array with the result. More...
 
static getShortAttributeName ($db, $def, $attrName)
 Returns the short attribute name (alias) if it's defined, given attribute name otherwise. More...
 
static handleRows ($rows, $class_name, $asObject)
 Creates PHP objects out of the database rows $rows. More...
 
static newObjectOrder ($def, $orderField, $conditions)
 Returns an order value which can be used for new items in table, for instance placement. More...
 
static removeObject ($def, $conditions=null, $extraConditions=null)
 Deletes the object from the table defined in $def with conditions $conditions and extra conditions $extraConditions. More...
 
static reorderObject ($def, $orderField, $conditions, $down=true)
 Moves a row in a database table. More...
 
static replaceFieldsWithShortNames ($db, $fieldDefs, &$fields)
 For the given array $fields treats its keys (for associative array) or values (for non-associative array) as table fields names and replaces them with short names (aliases) found in $fieldDefs. More...
 
static storeObject ($obj, $fieldFilters=null)
 Stores the data in $obj to database. More...
 
static swapRow ($table, $keys, $order_id, $rows, $id1, $id2)
 Sets row id $id2 to have the placement of row id $id1. More...
 
static updateObjectList ($parameters)
 Updates rows matching the given parameters. More...
 

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
 

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::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

Referenced by ezpKernelWeb\dispatchLoop().

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::wildcardExists (   $uriString)
static

Checks if $uriString exists as a wildcard.

Parameters
string$uriString
Returns
boolean

Referenced by eZURLAliasML\translate().

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: