Parses the PHP code section of CMS objects.

Protected properties

protected Cms\Classes\CmsCompoundObject $object

A reference to the CMS object being parsed.

protected string $filePath

Contains a path to the CMS object's file being parsed.

protected static mixed $cache

The internal cache, keeps parsed object information during a request.

protected string $dataCacheKey

Key for the parsed PHP file information cache.

Public methods

public void __construct(Cms\Classes\CmsCompoundObject $object)

Creates the class instance


public array 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 mixed source(Cms\Classes\Page $page, Cms\Classes\Layout $layout, Cms\Classes\Controller $controller)

Runs the object's PHP file and returns the corresponding object.


Protected methods

protected string extractClassFromFile($path)

Extracts the class name from a cache file

  • $path

protected string getCacheFilePath()

Returns path to the cached parsed file

protected integer getCachedFileInfo()

Returns information about a cached file

protected mixed getCachedInfo()

Returns information about all cached files.

protected void handleCorruptCache($data)

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.

  • $data

protected void makeDirectorySafe($dir)

Make directory with concurrency support

  • $dir

protected void rebuild(string $path)

Rebuilds the current file cache.

  • string $path - The path in which the cached file should be stored

protected void storeCachedInfo(array $result)

Stores result data inside cache.

  • array $result

protected void validate($php)

Evaluates PHP content in order to detect syntax errors. The method handles PHP errors and throws exceptions.

  • $php

protected void writeContentSafe($path, $content)

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

  • $path
  • $content