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

Parameters
Property Description
$object
Cms\Classes\CmsCompoundObject
Returns
mixed

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')
Returns
array

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.

Parameters
Property Description
$page

Specifies the CMS page.

$layout

Specifies the CMS layout.

$controller

Specifies the CMS controller.

Returns
mixed

protected extractClassFromFile ($path) : string

Extracts the class name from a cache file

Parameters
Property Description
$path
mixed
Returns
string

protected getCacheFilePath () : string

Returns path to the cached parsed file

Returns
string

protected getCachedFileInfo () : int

Returns information about a cached file

Returns
int

protected getCachedInfo () : mixed

Returns information about all cached files.

Returns
mixed

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.

Parameters
Property Description
$data
mixed
Returns
void

protected makeDirectorySafe ($dir)

Make directory with concurrency support

Parameters
Property Description
$dir
mixed
Returns
mixed

protected rebuild ($path)

Rebuilds the current file cache.

Parameters
Property Description
$path
mixed
Returns
mixed

protected storeCachedInfo (array $result) : void

Stores result data inside cache.

Parameters
Property Description
$result
array
Returns
void

protected validate ($php)

Evaluates PHP content in order to detect syntax errors.

The method handles PHP errors and throws exceptions.

Parameters
Property Description
$php
mixed
Returns
mixed

protected writeContentSafe ($path, $content)

Writes content with concurrency support and cache busting This work is based on the Twig\Cache\FilesystemCache class

Parameters
Property Description
$path
mixed
$content
mixed
Returns
mixed
Copyright © 2024 Winter CMS