Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Application

An application is a software program designed to perform specific tasks for end users. PHP applications can take many forms: web applications served over HTTP, command-line tools, background daemons, REST APIs, batch-processing scripts, etc.

PHP applications are typically structured around a framework or architecture pattern, like MVC, ADR, hexagonal architecture, etc. and a dependency-injection container. The entry point is usually a single index.php for web apps, or a CLI script invoked via the shell.

PHP applications excel at connecting to various sources of information, to collect, process and store data.

<?php

    declare(strict_types=1);
    
    // Bootstrap the application
    require __DIR__ . '/vendor/autoload.php';
    
    // Route incoming HTTP request
    $uri    = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH);
    $method = $_SERVER['REQUEST_METHOD'] ?? 'GET';
    
    $router = new Router();
    $router->get('/',      [HomeController::class,  'index']);
    $router->get('/about', [AboutController::class, 'index']);
    
    $response = $router->dispatch($method, $uri);
    $response->send();

?>

Documentation

See Also