Repository navigation
Developer Guide First Package
Developer Guide · Next: Package structure
Internals: Packages, Runtime, HTTP, Rendering, ObjectFactory.
Build DemoSite, a package with a /hello page. The example follows the installed local package's separate controller and router runtimes. It requires an installed MySQL-backed framework and ZipArchive. Create these files under awt_packages/DemoSite/:
DemoSite/
manifest.json
main.php
components/PageControllers.php
components/PageRoutes.php
controllers/WelcomeController.php
views/index.awt.php
awt_packages/DemoSite/manifest.json:
{
"name": "DemoSite",
"version": "1.0.0",
"minimum_awt_version": "27.0.0",
"maximum_awt_version": null,
"author": "Example Developer",
"type": 1,
"system_package": 0,
"description": "A small welcome application",
"dependencies": []
}Type 1 is an executable package. system_package: 0 makes it an ordinary package that needs enabling after installation. Names without spaces keep URL and filesystem paths predictable.
awt_packages/DemoSite/main.php:
<?php
namespace DemoSite;
use runtime\api\RuntimeLinkerAPI;
final class Main extends RuntimeLinkerAPI
{
public function main(): void
{
$this->createLink('controllers', '/components/PageControllers.php');
$this->createLink('routes', '/components/PageRoutes.php');
}
}The linker runs its own lifecycle and then runs linked files in insertion order. Controllers must be registered before routes retrieve them. Namespace every package's classes; declaring global Main in multiple packages would cause a PHP class collision.
awt_packages/DemoSite/components/PageControllers.php:
<?php
namespace DemoSite\components;
use controller\Controller;
use object\ObjectFactory;
use runtime\api\RuntimeControllerAPI;
final class PageControllers extends RuntimeControllerAPI
{
public function main(): void
{
$factory = (new ObjectFactory())
->setType(Controller::class)
->setClassPath($this->runtimePath . '/controllers/WelcomeController.php')
->setProperties([
'controllerName' => 'WelcomeController',
'localAssetPath' => '/awt_packages/DemoSite/views/assets',
'eventDispatcher' => $this->eventDispatcher,
])
->setMethodCalls(['setRootPath', 'setViewPath'])
->setMethodArgs([
'setRootPath' => [$this->runtimePath],
'setViewPath' => ['/views/'],
]);
$this->addController($factory, 'welcome');
}
}The factory delays controller creation until its route executes. getController() later adds packageName and Context. The dispatcher and rendering paths are configured here because the view API needs them.
awt_packages/DemoSite/components/PageRoutes.php:
<?php
namespace DemoSite\components;
use router\Router;
use runtime\api\RuntimeRouterAPI;
final class PageRoutes extends RuntimeRouterAPI
{
public function main(): void
{
$controllers = $this->getPassable(PageControllers::class);
if (!$controllers instanceof PageControllers) {
throw new \LogicException('Controller runtime must run first.');
}
$this->addRouter(
(new Router('/hello', 'index', $controllers->getController('welcome')))
->setName('demo.hello')
);
}
}One-argument getPassable() looks within this package and uses the actual fully qualified runtime class name as the key. The arbitrary name given to createLink() is not the passable key. A Router defaults to GET; HEAD can use its GET fallback.
awt_packages/DemoSite/controllers/WelcomeController.php:
<?php
namespace DemoSite\controllers;
use controller\Controller;
use view\View;
final class WelcomeController extends Controller
{
public function index(array|string $params): View
{
return $this->view(['title' => 'Welcome to DemoSite']);
}
}The action accepts captured route parameters. Returning $this->view() supplies the data bundle and lets the bootstrap render the final response. The router selects viewName = 'index' before calling the action.
awt_packages/DemoSite/views/index.awt.php:
<!doctype html>
<html lang="en">
<head><meta charset="utf-8"><title>{{ $title }}</title></head>
<body><h1>{{ $title }}</h1><p>Your package is running.</p></body>
</html>Files alone do not register the package in the database. Archive them with manifest.json and main.php at the ZIP root, or inside one containing directory.
Linux Bash, repository root (the subshell changes to the package directory):
(cd awt_packages/DemoSite && zip -r /tmp/DemoSite.zip .)
php awtzip is an external archive utility, not an AWT command. The Windows command follows Microsoft's Compress-Archive reference. Install your distribution's zip package if needed; the recursive command follows Ubuntu's zip manual. Windows PowerShell, repository root:
Compress-Archive -Path awt_packages\DemoSite\* -DestinationPath "$env:TEMP\DemoSite.zip" -Force
php awtAt the AWT prompt use the actual absolute archive path:
pm install /tmp/DemoSite.zip
pm list
pm enable 2
On Windows substitute the path printed by $env:TEMP. Replace 2 with the assigned package ID. End the CLI session and start a fresh request/process. Open /hello on the configured development server: expect “Welcome to DemoSite.” Run routes in a fresh php awt session to inspect demo.hello.
The framework's package installer moves files and registers metadata; it does not start the newly installed runtime within that command. Keep the package source/archive under your own version control before updates. See Lifecycle before making a destructive update or removal.
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