Cms\Classes\CodeParser

Overview

CodeParser 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

dataCacheKey is the key for the parsed PHP file information cache.


Public Methods

public __construct()

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

public parse()

public parse(): array 

parse 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()

public source(
    Cms\Classes\Page $page,
    Cms\Classes\Layout $layout,
    Cms\Classes\Controller $controller
): mixed 

source runs the object's PHP file and returns the corresponding object.

Protected Methods

protected extractClassFromFile()

protected extractClassFromFile($path): string 

extractClassFromFile extracts the class name from a cache file

protected getCacheFilePath()

protected getCacheFilePath(): string 

getCacheFilePath returns path to the cached parsed file

protected getCachedFileInfo()

protected getCachedFileInfo(): integer 

getCachedFileInfo returns information about a cached file

protected getCachedInfo()

protected getCachedInfo(): mixed 

getCachedInfo returns information about all cached files.

protected handleCorruptCache()

protected handleCorruptCache($data): void 

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 makeDirectorySafe()

protected makeDirectorySafe($dir): void

makeDirectorySafe makes a directory with concurrency support

protected rebuild()

protected rebuild(string $path): void

rebuild the current file cache.

protected storeCachedInfo()

protected storeCachedInfo(array $result): void 

storeCachedInfo stores result data inside cache.

protected validate()

protected validate($php): void

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

protected writeContentSafe()

protected writeContentSafe($path, $content): void

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