Repository navigation
Internals View View
Framework Internals · Subsystem overview · Developer guide
Source: awt_src/classes/view/View.php · Snapshot 8411f4287706.
A View stores the template name and bundle, initially includes the view file, then compiles the Blade template on render(). Controllers inherit this behavior.
use DOMDocument;
use Exception;
use render\events\RenderReadyEvent;
use render\Render;
use render\TemplateEngine\BladeOne;
use Throwable;class View extends RenderDeclarations 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 |
|---|---|---|
| $viewDirectory | protected string $viewDirectory; |
@var string The directory where view files are stored. |
| $viewName | public string $viewName; |
@var string The name of the view to be rendered. |
| $csrfTokens | private ?\router\interface\ICsrfTokenManager $csrfTokens = null; |
Used by setCsrfTokenManager(), render(). |
| $page | private DOMDocument $page; |
@var DOMDocument The DOM representation of the rendered view page. |
| Method | Signature |
|---|---|
| setCsrfTokenManager | public function setCsrfTokenManager(\router\interface\ICsrfTokenManager $tokens): self |
| view | public function view(array $data = []): View |
| getViewContent | protected function getViewContent(): string |
| render | public function render(): string |
public function setCsrfTokenManager(\router\interface\ICsrfTokenManager $tokens): self| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$tokens |
\router\interface\ICsrfTokenManager $tokens |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
State writes: $this->csrfTokens.
Return expressions (including local callbacks): $this.
Implementation, validation guards and interaction order
public function setCsrfTokenManager(\router\interface\ICsrfTokenManager $tokens): self
{
$this->csrfTokens = $tokens;
return $this;
}public function view(array $data = []): View| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$data |
array $data = [] |
The data to be passed to the view. |
Renders the view with the provided data.
This method prepares the view by bundling the data, creating the document, and loading the view content from the specified view file.
@param array $data The data to be passed to the view. @return View The current instance for method chaining.
State writes: $this->bundle.
Return expressions (including local callbacks): $this.
Implementation, validation guards and interaction order
/**
* Renders the view with the provided data.
*
* This method prepares the view by bundling the data, creating the document,
* and loading the view content from the specified view file.
*
* @param array $data The data to be passed to the view.
* @return View The current instance for method chaining.
*/
public function view(array $data = []): View
{
$this->bundle = $data;
$this->createBundleObjects();
$this->createDocument($this->getViewContent());
return $this;
}protected function getViewContent(): stringLoads the content of the view file and returns it as a string.
This method uses output buffering to capture the contents of the included view file and return it as a string.
@return string The content of the view file.
Return expressions (including local callbacks): ob_get_clean().
External effects include include.
Implementation, validation guards and interaction order
/**
* Loads the content of the view file and returns it as a string.
*
* This method uses output buffering to capture the contents of the included
* view file and return it as a string.
*
* @return string The content of the view file.
*/
protected function getViewContent(): string
{
ob_start();
include $this->viewDirectory . $this->viewName . '.awt.php';
return ob_get_clean();
}public function render(): stringRenders the HTML document, processes templates, and dispatches a render-ready event. It applies template parsing for loops, conditions, assets, and variables before returning the final HTML string.
@throws Exception If any issues occur during rendering or template loading. @return string The final rendered HTML content as a string.
Return expressions (including local callbacks): $this->dom->saveHTML(); "".
Failure handling catches Throwable.
Implementation, validation guards and interaction order
/**
* Renders the HTML document, processes templates, and dispatches a render-ready event.
* It applies template parsing for loops, conditions, assets, and variables before returning the final HTML string.
*
* @throws Exception If any issues occur during rendering or template loading.
* @return string The final rendered HTML content as a string.
*/
public function render(): string
{
$this->loadTemplate();
$this->createBundleObjects();
try {
$parser = new BladeOne($this->viewDirectory, COMPILED, BladeOne::MODE_AUTO,
csrfTokens: $this->csrfTokens ?? new \router\security\Csrf());
// Also populate the property used by already-compiled @csrf templates.
$parser->getCsrfToken();
$parser->setFileExtension(".awt.php");
$parser->addAssetDict(0, $this->localAssetPath);
$parser->setPackageName($this->packageName);
$parser->with($this->bundle);
$compiled = $parser->run($this->viewName);
$this->dom->loadHTML($compiled);
$ready = new RenderReadyEvent();
$ready->renderer = $this;
$this->eventDispatcher->dispatch($ready);
return $this->dom->saveHTML();
} catch (Throwable $e) {
if(DEBUG)
$e->getTraceAsString();
echo "An error has occurred while rendering: " . $e->getMessage();
}
return "";
}AWT Framework Wiki · Home · Installation Guide · Developer Guide · Framework Internals
Philosophy · Architecture · Known discrepancies · Verification
Installation Guide
Developer Guide
- Learning sequence
- First package
- Package structure
- Lifecycle
- Runtimes
- Events and objects
- Routing and controllers
- Views and resources
- Database and models
- Storage and caching
- Configuration and CLI
- Responses and errors
- Extension points
Framework Internals
- Architecture
- Bootstrap
- Packages
- Runtime
- Events and context
- Objects
- HTTP routing and controllers
- Rendering
- Blade integration
- Database
- Models
- Storage and caching
- Settings
- CLI
- Identity and sessions
- Responses
- Errors
- Complete source inventory
Documentation notes