Cms\Classes\CodeParser

Source: ~/modules/cms/classes/CodeParser.php

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

Parameters

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.

Parameters

Protected methods

protected string extractClassFromFile($path)

Extracts the class name from a cache file

Parameters
  • $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.

Parameters
  • $data

protected void makeDirectorySafe($dir)

Make directory with concurrency support

Parameters
  • $dir

protected void rebuild(string $path)

Rebuilds the current file cache.

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

protected void storeCachedInfo(array $result)

Stores result data inside cache.

Parameters
  • array $result

protected void validate($php)

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

Parameters
  • $php

protected void writeContentSafe($path, $content)

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

Parameters
  • $path
  • $content