class CacheSegmentParser (View source)

A parser which extracts cache segments by searching for start and end markers in the given content.

Properties

protected string $randomCacheMarker
protected int $randomCacheMarkerLength
protected string $output
protected string $outerSegmentContent
protected array $cacheSegments
protected int $uncachedPartCount
protected string $content

Methods

__construct(string $content, string $randomCacheMarker = '')

Parses the given content and extracts segments by searching for start end end markers. Those segments can later be retrieved via getCacheSegments() and stored in a cache.

array
parseSegment(int $currentPosition)

Parses a segment at current position diving down into nested segments.

array
extractContentAndSubSegments(int $currentPosition, array $segmentData)

No description

array
reduceSegmentDataToCacheRelevantInformation(array $segmentData)

Make sure that we keep only necessary information for caching and strip all internal segment data.

string
extractContent(int $fromPosition, int $toPosition = null)

No description

int
calculateCurrentPosition(int $position)

Calculates a position assuming that the given position is a token followed by the random cache marker

int|bool
calculateNextTokenPosition(int $currentPosition, string $token)

Find the next position of the given token (one of the ContentCache::CACHESEGMENT*_TOKEN constants) in the parsed content.

string
getOutput()

Returns the fully intact content as originally given to extractRenderedSegments() but without the markers. This content is suitable for being used as output for the user.

array
getCacheSegments()

Returns an array with extracted content segments, including the type (if they can be cached or not) and tags to be used for their entries when the segments are stored in a persistent cache.

int
getUncachedPartCount()

No description

string
getOuterSegmentContent()

No description

Details

__construct(string $content, string $randomCacheMarker = '')

Parses the given content and extracts segments by searching for start end end markers. Those segments can later be retrieved via getCacheSegments() and stored in a cache.

This method also prepares a cleaned up output which can be retrieved later. See getOutput() for more information.

Parameters

string $content
string $randomCacheMarker

Exceptions

Exception

protected array parseSegment(int $currentPosition)

Parses a segment at current position diving down into nested segments.

The returned segmentData array has the following keys:

  • identifier -> The identifier of this entry for cached segments (or the eval expression for everything else)
  • type -> The type of segment (one of the ContentCache::SEGMENTTYPE* constants)
  • context -> eventual context information saved for a cached segment (optional)
  • metadata -> cache entry metadata like tags
  • content -> the content of this segment including embed code for sub segments
  • cleanContent -> the raw content without any cache references for this segment and all sub segments
  • embed -> the placeholder content for this segment to be used in "content" of parent segments

Parameters

int $currentPosition

Return Value

array

Exceptions

Exception

protected array extractContentAndSubSegments(int $currentPosition, array $segmentData)

No description

Parameters

int $currentPosition
array $segmentData

Return Value

array

protected array reduceSegmentDataToCacheRelevantInformation(array $segmentData)

Make sure that we keep only necessary information for caching and strip all internal segment data.

Parameters

array $segmentData

Return Value

array

protected string extractContent(int $fromPosition, int $toPosition = null)

No description

Parameters

int $fromPosition
int $toPosition

Return Value

string

protected int calculateCurrentPosition(int $position)

Calculates a position assuming that the given position is a token followed by the random cache marker

Parameters

int $position

Return Value

int

protected int|bool calculateNextTokenPosition(int $currentPosition, string $token)

Find the next position of the given token (one of the ContentCache::CACHESEGMENT*_TOKEN constants) in the parsed content.

Parameters

int $currentPosition

The position to start searching from

string $token

the token to search for (will internally be appeneded by the randomCacheMarker)

Return Value

int|bool

Position of the token or false if the token was not found

string getOutput()

Returns the fully intact content as originally given to extractRenderedSegments() but without the markers. This content is suitable for being used as output for the user.

Return Value

string

array getCacheSegments()

Returns an array with extracted content segments, including the type (if they can be cached or not) and tags to be used for their entries when the segments are stored in a persistent cache.

Return Value

array

int getUncachedPartCount()

No description

Return Value

int

string getOuterSegmentContent()

No description

Return Value

string