CodeParser
Parses the PHP code section of CMS objects.
class Cms\Classes\CodeParser
Properties
protected
static
$cache
:
mixed
= []
The internal cache, keeps parsed object information during a request.
protected
$dataCacheKey
:
string
= ""
Key for the parsed PHP file information cache.
protected $filePath : string
Contains a path to the CMS object's file being parsed.
protected $object : Cms\Classes\CmsCompoundObject
A reference to the CMS object being parsed.
Methods
public __construct (Cms\Classes\CmsCompoundObject $object)
Creates the class instance
Property | Type | Description |
---|---|---|
$object | Cms\Classes\CmsCompoundObject |
Cms\Classes\CmsCompoundObject
|
public parse () : array
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 source (Cms\Classes\Page $page, Cms\Classes\Layout $layout, Cms\Classes\Controller $controller) : mixed
Runs the object's PHP file and returns the corresponding object.
Property | Type | Description |
---|---|---|
$page | Cms\Classes\Page |
Specifies the CMS page. |
$layout | Cms\Classes\Layout |
Specifies the CMS layout. |
$controller | Cms\Classes\Controller |
Specifies the CMS controller. |
protected extractClassFromFile ($path) : string
Extracts the class name from a cache file
Property | Type | Description |
---|---|---|
$path | mixed |
mixed
|
protected getCacheFilePath () : string
Returns path to the cached parsed file
protected getCachedFileInfo () : int
Returns information about a cached file
protected getCachedInfo () : mixed
Returns information about all cached files.
Returns an array representing the cached data or NULL.
protected handleCorruptCache ($data) : 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.
Property | Type | Description |
---|---|---|
$data | mixed |
mixed
|
protected makeDirectorySafe ($dir)
Make directory with concurrency support
Property | Type | Description |
---|---|---|
$dir | mixed |
mixed
|
protected rebuild ($path)
Rebuilds the current file cache.
Property | Type | Description |
---|---|---|
$path | mixed |
mixed
|
protected storeCachedInfo (array $result) : void
Stores result data inside cache.
Property | Type | Description |
---|---|---|
$result | array |
array
|
protected validate ($php)
Evaluates PHP content in order to detect syntax errors.
The method handles PHP errors and throws exceptions.
Property | Type | Description |
---|---|---|
$php | mixed |
mixed
|
protected writeContentSafe ($path, $content)
Writes content with concurrency support and cache busting This work is based on the Twig\Cache\FilesystemCache class
Property | Type | Description |
---|---|---|
$path | mixed |
mixed
|
$content | mixed |
mixed
|