Documentation · Chapter 02

Read and extend
a real project.

The final exercise verifies that you can follow the architecture before writing a new feature.

FINAL WORKSHOP

Add an About page to a classic application.

  1. Create a project named architecture-lab.
  2. Inspect phpaml.json, public/, routes/, src/, and runtime/.
  3. Create an AboutController.
  4. Add GET /about to routes/WebApp.php.
  5. Return a simple HTML response, then verify it in the browser.

GUIDED SOLUTION

Build in request order.

phpaml — zsh
aml create architecture-lab
cd architecture-lab
aml make:controller About
aml serve

The command creates the controller under src/controllers. Then add the route to routes/WebApp.php and connect it to AboutController::index. The route must be loaded before the browser can reach the action.

phpaml — zsh
public function index(): Response
{
    return Response::html('<main><h1>About</h1><p>My first PHPAML page.</p></main>');
}

Open /about. A 200 response proves that entry point, router, controller, and response work together. A 404 generally means the route is not registered; a 500 means processing started and then failed.

Knowledge check

CHECK YOUR UNDERSTANDING

Why is the controller under src/ rather than public/?

Show the answer

Because the controller is internal code. Only public/index.php should be directly exposed to the Web.

CHECK YOUR UNDERSTANDING

Why is a route required?

Show the answer

It connects an HTTP method and path to the action that handles them.

SUMMARY

What to remember

  • You can follow a complete request.
  • You can distinguish public, application, and rebuildable code.
  • You can distribute model, view, and controller responsibilities.
  • You can now approach migration of an older project.