Controller finds and serves requested CMS pages.

Public Properties

public array $vars

vars is a list of variables to pass to the page.

public string $assetPath

assetPath specifies the relative path to the asset directory.

public string $assetUrlPath

assetUrlPath specifies the public path to the asset directory.

Protected Properties

protected Cms\Classes\Theme $theme

theme reference to the CMS theme processed by the controller.

protected Cms\Classes\Router $router

router reference to the Router object.

protected Cms\Twig\Loader $loader

loader reference to the Twig template loader.

protected Cms\Classes\Page $page

page reference to the CMS page template being processed.

protected Cms\Classes\CodeBase $pageObj

pageObj reference to the CMS page code section object.

protected Cms\Classes\Layout $layout

layout reference to the CMS layout template used by the page.

protected Cms\Classes\CodeBase $layoutObj

layoutObj reference to the CMS layout code section object.

protected TwigEnvironment $twig

twig environment object.

protected string $pageContents

pageContents contains the rendered page contents string.

protected static self $instance

instance is a cache of this object.

protected Cms\Classes\ComponentBase $componentContext

componentContext of the active component, used internally.

protected Cms\Classes\PartialStack $partialStack

partialStack used internally.

protected Cms\Classes\PartialWatcher $partialWatcher

partialWatcher used internally.

protected bool $pageCycled

protected array $assets

Collection of assets to display in the layout.

protected array $assetBundles

Collection of combined and prioritized assets.

protected string $assetDefaults

assetDefaults is the default attributes for assets.

protected array $emitterSingleEventCollection

emitterSingleEventCollection of events to be fired once only

protected array $emitterEventCollection

emitterEventCollection of all registered events

protected array $emitterEventSorted

emitterEventSorted collection

protected int $statusCode

statusCode for the response

protected mixed $responseOverride

responseOverride for the standard controller response.

protected Symfony\Component\HttpFoundation\ResponseHeaderBag $responseHeaderBag

protected array $responseBrowserEvents

responseBrowserEvents for the AJAX framework.

Public Methods

public __construct()

public __construct(Cms\Classes\Theme $theme = null): void

__construct the controller.

public addComponent()

public addComponent(
    mixed $name,
    string $alias,
    array $properties = [],
    bool $addToLayout = false
): ComponentBase|null 

addComponent class or short name to the page or layout object, assigning it an alias with configuration as properties.

public addCss()

public addCss($name, $attributes = []): void

addCss includes a StyleSheet asset to the asset list

public addCssBundle()

public addCssBundle($name, $attributes = []): void

addCssBundle includes a CSS asset to the bundled combiner pipeline

public addJs()

public addJs($name, $attributes = []): void

addJs includes a JavaScript asset to the asset list

public addJsBundle()

public addJsBundle($name, $attributes = []): void

addJsBundle includes a JS asset to the bundled combiner pipeline

public addRss()

public addRss($name, $attributes = []): void

addRss adds an RSS link asset to the asset list. Call $this->makeAssets() in a view to output corresponding markup.

public bindEvent()

public bindEvent($event, $callback, $priority = 0): void 

bindEvent creates a new event binding

public bindEventOnce()

public bindEventOnce($event, $callback, $priority = 0): void 

bindEventOnce creates a new event binding that fires once only

public combineAssets()

public combineAssets($assets, $localPath = ''): string 

public currentPageUrl()

public currentPageUrl(
    array $parameters = [],
    bool $routePersistence = true
): null|string 

currentPageUrl looks up the current page URL with supplied parameters and route persistence.

public dispatchBrowserEvent()

public dispatchBrowserEvent($event, $data = null): void

dispatchBrowserEvent queues a browser event

public findComponentByHandler()

public findComponentByHandler(string $handler): ComponentBase|null 

findComponentByHandler searches the layout and page components by an AJAX handler and returns the component object if found.

public findComponentByName()

public findComponentByName($name $name): ComponentBase|null 

findComponentByName searches the layout and page components by an alias and returns the component object if found.

public findComponentByPartial()

public findComponentByPartial(string $partial): ComponentBase|null 

findComponentByPartial searches the layout and page components by a partial file and returns the component object if found.

public fireEvent()

public fireEvent(
    string $event,
    array $params = [],
    boolean $halt = false
): array 

fireEvent and call the listeners

public fireSystemEvent()

public fireSystemEvent(
    string $event,
    array $params = [],
    boolean $halt = true
): mixed 

fireSystemEvent fires a combination of local and global events. The first segment is removed from the event name locally and the local object is passed as the first argument to the event globally. Halting is also enabled by default.

For example:

$this->fireSystemEvent('backend.list.myEvent', ['my value']);

Is equivalent to:

$this->fireEvent('list.myEvent', ['myvalue'], true);

Event::fire('backend.list.myEvent', [$this, 'myvalue'], true);

public fireViewEvent()

public fireViewEvent(string $event, array $params = []): string 

fireViewEvent is a special event function used for extending within view files, allowing HTML to be injected multiple times.

For example:

<?= $this->fireViewEvent('backend.auth.extendSigninView') ?>

public flushAssets()

public flushAssets(): void 

flushAssets disables the use, and subsequent broadcast, of assets. This is useful to call during an AJAX request to speed things up. This method works by specifically targeting the hasAssetsDefined method.

public getAjaxHandler()

public getAjaxHandler(): string 

getAjaxHandler returns the AJAX handler for the current request, if available.

public getAssetPath()

public getAssetPath($fileName, $assetPath = null): void

public getAssetPaths()

public getAssetPaths(): array 

getAssetPaths returns an array of all registered asset paths.

public getBrowserEvents()

public getBrowserEvents(): array 

getBrowserEvents returns the queued browser events

public static getController()

public static getController(): self|null 

getController returns an existing instance of the controller. If the controller doesn't exists, returns null.

public getLayout()

public getLayout(): Cms\Classes\Layout 

getLayout returns the CMS layout object being processed by the controller. The object is not available on the early stages of the controller initialization.

public getLayoutObject()

public getLayoutObject(): Cms\Classes\CodeBase 

getLayoutObject is intended to be called from the page, returns the layout code base object.

public getLoader()

public getLoader(): Cms\Twig\Loader 

getLoader returns the Twig loader.

public getPage()

public getPage(): Cms\Classes\Page 

getPage returns the CMS page object being processed by the controller. The object is not available on the early stages of the controller initialization.

public getPageObject()

public getPageObject(): Cms\Classes\CodeBase 

getPageObject is intended to be called from the layout, returns the page code base object.

public getPartialObject()

public getPartialObject(): Cms\Classes\CodeBase 

getPartialObject returns the active partial object from the current context

public getResponseHeaders()

public getResponseHeaders(

): Symfony\Component\HttpFoundation\ResponseHeaderBag|null 

getResponseHeaders as a response header bag

public getRouter()

public getRouter(): Cms\Classes\Router 

getRouter returns the routing object.

public getStatusCode()

public getStatusCode(): int 

getStatusCode returns the status code for the current web response.

public getTheme()

public getTheme(): Cms\Classes\Theme 

getTheme returns the current CMS theme.

public getTwig()

public getTwig(): TwigEnvironment 

getTwig returns the Twig environment.

public hasAssetsDefined()

public hasAssetsDefined(): bool 

hasAssetsDefined returns true if assets any have been added

public loadContentObject()

public loadContentObject($name): Content|false 

loadContentObject loads content for rendering.

public loadPartialObject()

public loadPartialObject($name): Partial|false 

loadPartialObject loads a partial for rendering.

public makeAssets()

public makeAssets(string $type = null): string 

makeAssets outputs <link> and <script> tags to load assets previously added with addJs and addCss method calls

public makeResponse()

public makeResponse(mixed $contents): mixed 

makeResponse prepares a response that considers overrides and custom responses.

public pageCycle()

public pageCycle(): void

pageCycle invokes the current page cycle without rendering the page, used by AJAX handler that may rely on the logic inside the action.

public pageUrl()

public pageUrl(
    string|null $name = null,
    array $parameters = [],
    bool $routePersistence = true
): string 

pageUrl looks up the URL for a supplied page name and returns it relative to the website root, including route parameters. Parameters can be persisted from the current page parameters.

public param()

public param(string $name, string $default = null): string 

param returns a routing parameter.

public static render()

public static render(
    string $pageFile,
    array $parameters = [],
    Cms\Classes\Theme $theme = null
): void

render a page in its entirety, including component initialization. AJAX will be disabled for this process.

public renderComponent()

public renderComponent($name $name, array $parameters = []): string 

renderComponent renders a component's default content, preserves the previous component context.

public renderContent()

public renderContent(
    string $name,
    array $parameters = [],
    $throwException = true
): mixed 

renderContent renders a requested content file. The framework uses this method internally.

public renderPage()

public renderPage(): void

renderPage renders a requested page. The framework uses this method internally.

public renderPartial()

public renderPartial(
    string $name,
    array $parameters = [],
    bool $throwException = true
): mixed 

renderPartial renders a requested partial. The framework uses this method internally.

public run()

public run(string|null $url = '/'): mixed 

run finds and serves the requested page URL. If the page cannot be found, returns the page with the URL /404. If the /404 page doesn't exist, returns the system 404 page. If the parameter is null, the current URL used. If it is not provided then '/' is used. Returns the response to the provided URL.

public runAjaxHandlerAsResponse()

public runAjaxHandlerAsResponse($handler): void

runAjaxHandlerResponse is used by the ajaxHandler Twig function.

public runPage()

public runPage(Cms\Classes\Page $page, array $options = []): string 

runPage runs a page directly from its object and supplied parameters.

public setComponentContext()

public setComponentContext($component = null): void

setComponentContext manually, used by Components when calling renderPartial.

public setResponse()

public setResponse(mixed $response): void 

setResponse for the current page request cycle, this value takes priority over the standard response prepared by the controller.

public setResponseCookie()

public setResponseCookie(
    Symfony\Component\HttpFoundation\Cookie|mixed $cookie
): void 

setResponseCookie adds a cookie to the response.

public setResponseHeader()

public setResponseHeader(
    string $key,
    array|string $values,
    bool $replace = true
): void 

setResponseHeader value

public setStatusCode()

public setStatusCode(int $code): void 

Sets the status code for the current web response.

public themeUrl()

public themeUrl($url = null): string 

themeUrl converts supplied URL to a theme URL relative to the website root, if the URL provided is an array then the files will be combined

public unbindEvent()

public unbindEvent($event = null): void 

unbindEvent destroys an event binding

Protected Methods

protected addPartialComponent()

protected addPartialComponent(
    $properties = []
): void

addPartialComponent adds a component to a partial object, used internally by the public renderPartial method

protected combineBundledAssets()

protected combineBundledAssets($type): array 

combineBundledAssets spins over every bundle definition and combines them to an asset

protected emitterEventSortEvents()

protected emitterEventSortEvents($eventName, $combined = []): array 

emitterEventSortEvents sorts the listeners for a given event by priority

protected execAjaxHandlers()

protected execAjaxHandlers(): mixed 

execAjaxHandlers executes the page, layout, component and plugin AJAX handlers.

protected execPageCycle()

protected execPageCycle(): void

execPageCycle executes the page life cycle. Creates an object from the PHP sections of the page and it's layout, then executes their life cycle functions.

protected execPostbackHandler()

protected execPostbackHandler(): void

execPostbackHandler is used internally to execute a postback version of an AJAX handler. This process fails without any exceptions to keep the page cycle going.

protected getAjaxHandlerPartialList()

protected getAjaxHandlerPartialList(): array 

protected getAjaxPartialName()

protected getAjaxPartialName(): void

getAjaxPartialName returns a partial name or true

protected getAssetEntryBuildPath()

protected getAssetEntryBuildPath(array $asset): string 

Internal helper, attaches a build code to an asset path

protected getAssetScheme()

protected getAssetScheme($asset): string 

getAssetScheme is an internal helper to get the asset scheme.

protected getLocalPath()

protected getLocalPath($relativePath): string 

getLocalPath converts a relative path to a local path

protected getMultipleThemeAssetPaths()

protected getMultipleThemeAssetPaths($paths): array 

getMultipleThemeAssetPaths checks combiner paths in the theme and rewrites them to parent assets, if necessary

protected getThemeAssetRelativePath()

protected getThemeAssetRelativePath($relativePath = null): string 


protected getThemeAssetUrl()

protected getThemeAssetUrl($relativePath = null): string 

getThemeAssetUrl returns the public directory for theme assets

protected initComponents()

protected initComponents(): void 

initComponents initializes the components for the layout and page.

protected initCustomObjects()

protected initCustomObjects(): void 

initCustomObjects initializes the custom layout and page objects.

protected initTwigEnvironment()

protected initTwigEnvironment(): void 

initTwigEnvironment initializes the Twig environment and loader. Registers the \Cms\Twig\Extension object with Twig.

protected makeDynamicAttributeReplacement()

protected makeDynamicAttributeReplacement(
    $parameters = []
): array|null 

makeDynamicAttributeReplacement will look inside attribute values to replace any Twig-like variables with the values inside the parameters.

{{ post.title }}

protected makeRouterPropertyReplacement()

protected makeRouterPropertyReplacement(
    $routerParameters = []
): array|null 

makeRouterPropertyReplacement will look inside property values to replace any Twig-like variables with values from the route parameters.

{{ :post }}

protected makeXsrfCookie()

protected makeXsrfCookie(): Symfony\Component\HttpFoundation\Cookie 

makeXsrfCookie adds anti-CSRF cookie. Adds a cookie with a token for CSRF checks to the response.

protected parseAllEnvironmentVars()

protected parseAllEnvironmentVars(): void

parseAllEnvironmentVars parses vars for all relevant objects.

protected parseEnvironmentVarsOnComponent()

protected parseEnvironmentVarsOnComponent(
    $vars = [],
    $properties = null,
    $propPrefix = ''
): void

parseEnvironmentVarsOnComponent where property values should be defined as {{ param }}.

protected parseEnvironmentVarsOnTemplate()

protected parseEnvironmentVarsOnTemplate(
    $vars = [],
    $attributes = null,
    $attrPrefix = ''
): void

parseEnvironmentVarsOnTemplate where property values should be defined as {{ param }}.

protected parseRouteParamsOnComponent()

protected parseRouteParamsOnComponent(
    $params = [],
    $properties = null,
    $propPrefix = ''
): void

parseRouteParamsOnComponent where property values should be defined as {{ :param }}.

protected postProcessResult()

protected postProcessResult(
    Cms\Classes\Page $page,
    string $url,
    string $content
): string 

Post-processes page HTML code before it's sent to the client. Note for pre-processing see cms.template.processTwigContent event.

protected processAssetAttributes()

protected processAssetAttributes($attributes): void

protected removeDuplicateAssets()

protected removeDuplicateAssets(): void

removeDuplicateAssets removes duplicate and global assets from the entire collection

protected renderAssetAttributes()

protected renderAssetAttributes($type, $asset): string 

renderAssetAttributes takes an asset definition and returns the necessary HTML output

protected renderLayoutContents()

protected renderLayoutContents(): void

protected renderPageContents()

protected renderPageContents(): void

renderPageContents with exception masking

protected runAjaxHandler()

protected runAjaxHandler($handler): void

runAjaxHandler tries to find and run an AJAX handler in the page, layout, components and plugins. The method stops as soon as the handler is found. It will return the response from the handler, or true if the handler was found. Returns false otherwise.

protected runPageCapture()

protected runPageCapture($page, $ajaxPartial): void

runPageCapture captures partial output and runs AJAX handlers in partials if they are seen

protected verifyCsrfToken()

protected verifyCsrfToken(): bool 

verifyCsrfToken checks if the request requires verification first (not GET, HEAD, OPTIONS) and then the request data / headers for a valid CSRF token. Returns false if a valid token is not found. Override this method to disable the check.

protected verifyForceSecure()

protected verifyForceSecure(): bool 

verifyForceSecure checks if the back-end should force a secure protocol (HTTPS) enabled by config.