Search by

webservco / application-default

ariademur

A PHP component/library. Default application implementation, with factories for web and command line applications.

Package info

github.com/webservco/application-default

Homepage

pkg:composer/webservco/application-default

Statistics

Installs: 90

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v2.3.0 2026-10-11 16:34 UTC

This package is auto-updated.

Last update: 2026-10-11 16:45:40 UTC


README

A PHP component/library. Please see webservco/sandbox for an example project using these types of components.

Default application implementation, with factories for web and command line applications.

  • Requires: ALLOWED_HOSTS in the configuration (server application only)
  • Related: webservco/application (interfaces), webservco/application-runner (HTTP runner), webservco/dependency-container (provides the logger and configuration)

Installation

composer require webservco/application-default

Usage

Server application

Example of what public/index.php does in the webservco/sandbox project, after it has created the dependency container and loaded the configuration.

use WebServCo\Application\Factory\ApplicationRunnerFactory;
use WebServCo\Application\Factory\DefaultServerApplicationFactory;
use WebServCo\Error\Factory\DefaultErrorHandlingServiceFactory;
use WebServCo\Http\Factory\Message\Request\Server\ServerRequestFromServerDataFactory;

$applicationFactory = new DefaultServerApplicationFactory(
    // \WebServCo\Application\Contract\ApplicationRunnerFactoryInterface
    new ApplicationRunnerFactory($requestHandlerFactory),
    // \WebServCo\Error\Contract\ErrorHandlingServiceFactoryInterface
    new DefaultErrorHandlingServiceFactory(),
    // \WebServCo\DependencyContainer\Contract\ServiceContainerInterface
    $applicationDependencyContainer->getServiceContainer(),
    // \WebServCo\Http\Contract\Message\Request\Server\ServerRequestFromServerDataFactoryInterface
    new ServerRequestFromServerDataFactory(),
);

// \WebServCo\Application\Contract\ApplicationInterface
$application = $applicationFactory->createDefaultServerApplication($lapTimer);
$application->bootstrap();
$application->run();

Command application

use WebServCo\Application\Factory\DefaultCommandApplicationFactory;
use WebServCo\Error\Factory\DefaultErrorHandlingServiceFactory;

$applicationFactory = new DefaultCommandApplicationFactory(
    new DefaultErrorHandlingServiceFactory(),
    $applicationDependencyContainer->getServiceContainer(),
);

// $command: \WebServCo\Command\Contract\CommandRunnerInterface
$application = $applicationFactory->createCommandApplication($lapTimer, $command);
$application->bootstrap();
$application->run();

Contracts

Interface Implementation Purpose
Contract\ApplicationInterface (webservco/application) Service\DefaultApplication Sets up error handling, runs the runner and logs timing at shutdown.
Factory\DefaultServerApplicationFactory Builds the server request from PHP globals and creates the application.
Factory\DefaultCommandApplicationFactory Creates the application around a command.

Namespaces are relative to WebServCo\Application\.

Configuration

The server factory only accepts requests whose SERVER_NAME is in this list.

[Application]

ALLOWED_HOSTS[] = example.ddev.site
ALLOWED_HOSTS[] = localhost

Notes

bootstrap() installs the error handler (with the default factory, any PHP error becomes an ErrorException), registers shutdown() as a shutdown function, and then throws for errors that happened before the script started, such as a POST body over post_max_size. Install the exception handler before calling it.

shutdown() restores the previous error handler and writes the lap timer statistics as JSON to the application log channel at debug level.

createDefaultServerApplication() reads $_COOKIE, $_POST, $_GET, $_SERVER and $_FILES. Tests can pass their own data to createServerApplication() instead.

Development

# Start project.
ddev start
# Install dependencies.
ddev c u
# Run all validations.
ddev c c
# Run unit tests.
ddev c test:dox

License

MIT