Skip to content

Internals Controller Controller

Stefan Crkvenjakov edited this page Oct 7, 2026 · 1 revision

controller\Controller

Framework Internals · Subsystem overview · Developer guide

Source: awt_src/classes/controller/Controller.php · Snapshot 8411f4287706.

Controllers extend View and receive package context, paths and the dispatcher from their runtime or object factory. Route execution selects an action method.

Imports and dependencies

use context\Context;
use /**
 * Interface IController
 *
 * Defines the contract for controllers within the application.
 * Controllers implementing this interface are responsible for
 * handling requests and returning appropriate responses.
 */
    controller\interfaces\IController;
use /**
 * The View class is responsible for rendering templates and managing the output display.
 * This class typically handles the dynamic content replacement in templates and
 * facilitates the interaction between the controller and the user interface.
 */
    view\View;

Controller

Declaration and architectural role

abstract class Controller extends View implements IController

Source description (behavioral corrections are recorded in Known discrepancies):

Abstract class representing a controller, which implements the IController interface.

This class provides functionality for managing controller-related properties, including the controller name, the root directory path, and shared data. It also defines methods for setting paths necessary for view rendering.

Constants, enum cases, traits and properties

Declarations below preserve visibility, type, default and modifiers exactly. A typed property without an initializer remains uninitialized until its constructor or another method assigns it. Mutable fields belong to this instance unless marked static; readonly fields can be initialized once. Constructor-promoted properties are also listed below.

Member Declaration Purpose or source contract
$controllerName public string $controllerName; @var string $controllerName The name of the controller.
$rootDirPath public string $rootDirPath; @var string $rootDirPath The root directory path for the controller.
$context private ?Context $context = null; Used by setContext(), getContext().
$shared public array $shared = []; Declared extension/state field; no own method directly consumes it in this source file.

Method index

Method Signature
setContext public function setContext(Context $context): void
getContext public function getContext(): ?Context
setRootPath final public function setRootPath(string $rootDirPath): void
setViewPath final public function setViewPath(string $path): void
setName final public function setName(string $name): void

setContext

Source line 51

public function setContext(Context $context): void

Parameters

Parameter Type, modifiers and default Purpose
$context Context $context Package context object or package name according to the declared type.

State writes: $this->context.

Implementation, validation guards and interaction order
public function setContext(Context $context): void
    {
        $this->context = $context;
    }

getContext

Source line 56

public function getContext(): ?Context

Return expressions (including local callbacks): $this->context.

Implementation, validation guards and interaction order
public function getContext(): ?Context
    {
        return $this->context;
    }

setRootPath

Source line 70

final public function setRootPath(string $rootDirPath): void

Parameters

Parameter Type, modifiers and default Purpose
$rootDirPath string $rootDirPath The root directory path to set.

Sets the root directory path for the controller.

This method allows the root directory path to be set, which can be used to locate views or other resources relative to this path.

@param string $rootDirPath The root directory path to set. @return void

State writes: $this->rootDirPath.

Implementation, validation guards and interaction order
/**
     * Sets the root directory path for the controller.
     *
     * This method allows the root directory path to be set, which can be
     * used to locate views or other resources relative to this path.
     *
     * @param string $rootDirPath The root directory path to set.
     * @return void
     */
    final public function setRootPath(string $rootDirPath): void
    {
        $this->rootDirPath = $rootDirPath;
    }

setViewPath

Source line 85

final public function setViewPath(string $path): void

Parameters

Parameter Type, modifiers and default Purpose
$path string $path The relative path to the view directory.

Sets the view directory path for the controller.

This method constructs the full path to the view directory by concatenating the root directory path with the provided relative path.

@param string $path The relative path to the view directory. @return void

State writes: $this->viewDirectory.

Implementation, validation guards and interaction order
/**
     * Sets the view directory path for the controller.
     *
     * This method constructs the full path to the view directory by
     * concatenating the root directory path with the provided relative
     * path.
     *
     * @param string $path The relative path to the view directory.
     * @return void
     */
    final public function setViewPath(string $path): void
    {
        $this->viewDirectory = $this->rootDirPath . $path;
    }

setName

Source line 95

final public function setName(string $name): void

Parameters

Parameter Type, modifiers and default Purpose
$name string $name * @return void

Sets the name for controller. @param string $name @return void

State writes: $this->controllerName.

Implementation, validation guards and interaction order
/**
     * Sets the name for controller.
     * @param string $name
     * @return void
     */
    final public function setName(string $name): void
    {
        $this->controllerName = $name;
    }

Related types

Clone this wiki locally