kernel/classes/ezurlwildcard.php
File containing the eZURLWildcard class.
- Copyright
- Copyright (C) 1999-2011 eZ Systems AS. All rights reserved.
- License
-
eZ Business Use License Agreement Version 2.0
- Package
- kernel
- Version
- 4.6.0
Package: kernelFile containing the eZURLWildcard class.
- Parent(s)
- \eZPersistentObject
- Copyright
- Copyright (C) 1999-2011 eZ Systems AS. All rights reserved.
- License
-
eZ Business Use License Agreement Version 2.0
- Version
- 4.6.0
Constants


int
WILDCARDS_PER_CACHE_FILE
= 100
Max number of wildcard entries per cache file
Properties



\array(eZClusterFileHandlerInterface)
$cacheFiles= 'array()'
staticCluster file handler instances of cache files
Default valuearray()
Details
- Type
- \array(eZClusterFileHandlerInterface)



array
$wildcardsIndex= 'null'
staticWildcards index local cache
Default valuenull
Details
- Type
- array
Methods



cacheInfoDirectories(
$wildcardCacheDir, $wildcardCacheFile, $wildcardCachePath, $wildcardKeys
)
:
void
staticSets the various cache information to the parameters.
Parameters
Name |
Type |
Description |
$wildcardCacheDir |
|
|
$wildcardCacheFile |
|
|
$wildcardCachePath |
|
|
$wildcardKeys |
|
|
Details
- Private
-



cleanup(
string $baseURL
)
:
void
staticRemoves 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
Name |
Type |
Description |
$baseURL |
string |
URL prefix matched against destination_url |



createWildcardsIndex(
)
:
void
staticCreate the wildcard cache
The wildcard caches are splitted between several files:
'wildcard__index.php': contains regexps for wildcards
'wildcard__0.php',
'wildcard__1.php',
...
'wildcard__N.php': contains cached wildcards.
Each file has info about eZURLWildcard::WILDCARDS_PER_CACHE_FILE wildcards.



eZURLWildcard(
array $row
)
:
void
Initializes a new URL alias persistent object
Parameters
Name |
Type |
Description |
$row |
array |
|



expiryTimestamp(
)
:
int | bool
staticReturns the expiry timestamp for wildcard cache from eZExpiryHandler
Returns
Type |
Description |
int | bool |
the timestamp if set, false otherwise |



fetch(
int $id, bool $asObject
=
true
)
:
\eZURLWildcard
staticFetch a wildcard by numerical ID
Parameters
Name |
Type |
Description |
$id |
int |
|
$asObject |
bool |
|
Returns



fetchBySourceURL(
string $url, bool $asObject
=
true
)
:
\eZURLWildcard
staticFetches a wildcard by source url
Parameters
Name |
Type |
Description |
$url |
string |
Source URL |
$asObject |
bool |
|
Returns



fetchCacheFile(
string $filepath
)
:
array
staticIncludes a wildcard cache file and returns its return value
This method is used as a callback by eZClusterFileHandler::processFile
Parameters
Name |
Type |
Description |
$filepath |
string |
|
Returns



fetchList(
int $offset
=
false, int $limit
=
false, bool $asObject
=
true
)
:
\array[eZURLWildcard]
staticFetches the list of URL wildcards. By defaults, fetches all the wildcards
Parameters
Name |
Type |
Description |
$offset |
int |
Offset to limit the list from |
$limit |
int |
Limit to the number of fetched items |
$asObject |
bool |
|
Returns
Type |
Description |
\array[eZURLWildcard] |
|



fetchListCount(
)
:
int
staticReturns the number of wildcards in the database without any filtering
Returns
Type |
Description |
int |
Number of wildcards in the database |



isCacheExpired(
int $timestamp
)
:
bool
staticChecks if the wildcard cache is expired
Parameters
Name |
Type |
Description |
$timestamp |
int |
Timestamp expiry should be checked against |
Returns
Type |
Description |
bool |
true if cache is expired |
Details
- Deprecated
- since 4.2.0



loadCacheFile(
\$cacheID $cacheID
=
'index'
)
:
\eZClusterFileHandlerInterface
staticLoads and returns the cluster handler instance for the requested cache file.
The instance will be returned even if the file doesn't exist
Parameters
Name |
Type |
Description |
$cacheID |
\$cacheID |
Cache file number. Will load the index if not provided. |
Returns



matchRegexpCode(
array $wildcard
)
:
string
staticTransforms the source-url of a wildcard to a preg_match compatible expression
Example: foo/* will be converted to #^foo/(.*)$#
Parameters
Name |
Type |
Description |
$wildcard |
array |
wildcard data with a source_url key |
Returns
Type |
Description |
string |
preg_match compatible string |



matchReplaceCode(
array $wildcard
)
:
string
staticConverts the destination-url of a wildcard to a preg_replace compatible
expression.
Example: foobar/{1} will be converted to ...
Parameters
Name |
Type |
Description |
$wildcard |
array |
Wildcard array with a destination_url key |
Returns
Type |
Description |
string |
match/replace PHP Code |
Details
- Todo
- fix the example
- Todo
- Try to replace the eval'd code with a preg_replace expression



removeByIDs(
array $idList
)
:
void
staticRemoves wildcards based on an ID list
Parameters
Name |
Type |
Description |
$idList |
array |
array of numerical ID |



store(
$fieldFilters
=
null
)
:
void
Stores the eZURLWildcard persistent object
Parameters
Name |
Type |
Description |
$fieldFilters |
|
|



translate(
\eZURI | string $uri
)
:
mixed
staticTransforms the URI if there exists an alias for it.
Parameters
Name |
Type |
Description |
$uri |
\eZURI | string |
|
Returns
Type |
Description |
mixed |
The translated URI if the resource has moved, or true|false if translation was (un)successful |



translateWithCache(
int $wildcardNum, \eZURI | string $uri, mixed $wildcardInfo, $matchRegexp
)
:
bool
staticThe 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
Name |
Type |
Description |
$wildcardNum |
int |
|
$uri |
\eZURI | string |
|
$wildcardInfo |
mixed |
|
$matchRegexp |
|
|
Returns
Details
- Todo
- make private, this method isn't used anywhere else



wildcardsIndex(
)
:
array
staticAssign function names to input variables. Generates the wildcard cache if
expired.
Returns
Type |
Description |
array |
The wildcards index, as an array of regexps |