CodeParser
in package
Parses the PHP code section of CMS objects.
Tags
Table of Contents
- $cache : mixed
- $dataCacheKey : string
- $filePath : string
- $object : CmsCompoundObject
- __construct() : mixed
- Creates the class instance
- parse() : array<string|int, mixed>
- Parses the CMS object's PHP code section and returns an array with the following keys: - className - filePath (path to the parsed PHP file) - offset (PHP section offset in the template file) - source ('parser', 'request-cache', or 'cache')
- source() : mixed
- Runs the object's PHP file and returns the corresponding object.
- extractClassFromFile() : string
- Extracts the class name from a cache file
- getCachedFileInfo() : int
- Returns information about a cached file
- getCachedInfo() : mixed
- Returns information about all cached files.
- getCacheFilePath() : string
- Returns path to the cached parsed file
- handleCorruptCache() : void
- In some rare cases the cache file will not contain the class name we expect. When this happens, destroy the corrupt file, flush the request cache, and repeat the cycle.
- makeDirectorySafe() : mixed
- Make directory with concurrency support
- rebuild() : mixed
- Rebuilds the current file cache.
- storeCachedInfo() : void
- Stores result data inside cache.
- validate() : mixed
- Evaluates PHP content in order to detect syntax errors.
- writeContentSafe() : mixed
- Writes content with concurrency support and cache busting This work is based on the Twig\Cache\FilesystemCache class
Properties
$cache
protected
static mixed
$cache
= []
The internal cache, keeps parsed object information during a request.
$dataCacheKey
protected
string
$dataCacheKey
= ''
Key for the parsed PHP file information cache.
$filePath
protected
string
$filePath
Contains a path to the CMS object's file being parsed.
$object
protected
CmsCompoundObject
$object
A reference to the CMS object being parsed.
Methods
__construct()
Creates the class instance
public
__construct(CmsCompoundObject $object) : mixed
Parameters
- $object : CmsCompoundObject
Return values
mixed —parse()
Parses the CMS object's PHP code section and returns an array with the following keys: - className - filePath (path to the parsed PHP file) - offset (PHP section offset in the template file) - source ('parser', 'request-cache', or 'cache')
public
parse() : array<string|int, mixed>
Return values
array<string|int, mixed> —source()
Runs the object's PHP file and returns the corresponding object.
public
source(Page $page, Layout $layout, Controller $controller) : mixed
Parameters
- $page : Page
-
Specifies the CMS page.
- $layout : Layout
-
Specifies the CMS layout.
- $controller : Controller
-
Specifies the CMS controller.
Return values
mixed —extractClassFromFile()
Extracts the class name from a cache file
protected
extractClassFromFile(mixed $path) : string
Parameters
- $path : mixed
Return values
string —getCachedFileInfo()
Returns information about a cached file
protected
getCachedFileInfo() : int
Return values
int —getCachedInfo()
Returns information about all cached files.
protected
getCachedInfo() : mixed
Return values
mixed —Returns an array representing the cached data or NULL.
getCacheFilePath()
Returns path to the cached parsed file
protected
getCacheFilePath() : string
Return values
string —handleCorruptCache()
In some rare cases the cache file will not contain the class name we expect. When this happens, destroy the corrupt file, flush the request cache, and repeat the cycle.
protected
handleCorruptCache(mixed $data) : void
Parameters
- $data : mixed
Return values
void —makeDirectorySafe()
Make directory with concurrency support
protected
makeDirectorySafe(mixed $dir) : mixed
Parameters
- $dir : mixed
Return values
mixed —rebuild()
Rebuilds the current file cache.
protected
rebuild(mixed $path) : mixed
Parameters
- $path : mixed
Return values
mixed —storeCachedInfo()
Stores result data inside cache.
protected
storeCachedInfo(array<string|int, mixed> $result) : void
Parameters
- $result : array<string|int, mixed>
Return values
void —validate()
Evaluates PHP content in order to detect syntax errors.
protected
validate(mixed $php) : mixed
The method handles PHP errors and throws exceptions.
Parameters
- $php : mixed
Return values
mixed —writeContentSafe()
Writes content with concurrency support and cache busting This work is based on the Twig\Cache\FilesystemCache class
protected
writeContentSafe(mixed $path, mixed $content) : mixed
Parameters
- $path : mixed
- $content : mixed