Skip to content

WebFramework Documentation

Welcome to the WebFramework documentation. WebFramework is a lightweight, secure-by-default PHP microframework built on top of the Slim Framework. It provides a cohesive set of services around database management, ORM, caching, authentication, middleware, templating, translations, instrumentation, and more – giving you Laravel-like features without the bloat.

Perfect for developers who love Slim's simplicity but need full-featured components for building modern PHP applications and REST APIs.

Installation

Skeleton Application

WebFramework is installed via Composer. You can install a skeleton application to get you started:

Bash
composer create-project avoutic/web-framework-skeleton

Existing project

You can also add WebFramework to an existing project by installing it via Composer:

Bash
composer require avoutic/web-framework

Composer installs the command line tool of the framework as vendor/bin/framework. Nothing has to be copied for it.

The web entry point, public/index.php, has to be a file in the web root of your application. Add the following to your composer.json file, so it is published on every install and update:

JSON
1
2
3
4
5
6
7
8
    "scripts": {
        "post-install-cmd": [
            "framework-publish"
        ],
        "post-update-cmd": [
            "framework-publish"
        ]
    },

framework-publish copies public/index.php from the framework into your application. If that fails, it says why and makes Composer report an error, so you are not left with an old entry point without knowing. When you run Composer with --no-scripts, run vendor/bin/framework-publish yourself afterwards.

Directory Structure

Applications using WebFramework typically have the following directory structure:

  • actions: Contains files for each endpoint and related API functions.
  • config: Contains the configuration files for the application.
  • definitions: Contains the PHP-DI definitions for the application.
  • public: The location for the core index.php and external static files like images, CSS, and JavaScript.
  • migrations: Contains the database migrations for the application.
  • scripts: Contains scripts for tasks, migrations, and other automation tasks.
  • src: Contains the core application/business logic and model files.
  • templates: Contains the templates used by the actions.
  • tests: Contains the tests for the application.
  • translations: Contains the translation files for the application.

You are free to organize your project in any way you like, but the above structure is recommended. You will need to configure the PSR-4 autoloading in your composer.json file to match the directory structure. The skeleton uses the following configuration:

JSON
1
2
3
4
5
6
7
    "autoload": {
        "psr-4": {
            "App\\": "src/",
            "App\\Actions\\": "actions/",
            "App\\Routes\\": "routes/"
        }
    },

Static Analysis

The framework comes with a PHPStan extension that knows the id property of an entity is written by the repository. Without it, PHPStan reports the id of your entities as never written. Include it in the phpstan.neon of your application:

Text Only
includes:
    - vendor/avoutic/web-framework/phpstan-core.neon

If you use phpstan/extension-installer, it is included automatically and you can leave this out.

The extension recognizes an entity by its type: a class that implements WebFramework\Entity\Entity, which every class that extends EntityCore does. It does not matter in which namespace the entity lives.

Documentation Contents

This documentation is organized into several sections, each focusing on a specific aspect of WebFramework. Click on the links below to explore each section in detail:

Getting Started

  • Installation Guide: Instructions for installing WebFramework and setting up a base project.
  • Migration Guide: Guidance on migrating between different versions of WebFramework.

Core Concepts

HTTP & Routing

  • Routing: How to set up and manage routes in your WebFramework application.
  • Middleware Management: How to define and use middleware to process requests and responses.
  • Emitting Responses: How to generate responses in actions using the ResponseEmitter or via exceptions.
  • Input Validation: How to add input validation to your actions using the InputValidationService.
  • Templating: How to use the Latte templating engine to render templates.

Authentication & Security

Data & Storage

  • Database Usage: How to interact with the database, including executing queries and managing transactions.
  • Database Migrations: How to manage database schema changes using the DatabaseManager.
  • Caching: How to use caching to store and retrieve data efficiently.

Background Processing

  • Queueing: How to queue Jobs and handle them asynchronously.
  • Tasks: How to create and run tasks from the command line.

Observability

  • Instrumentation: How to instrument your application for monitoring and performance tracking.
  • Logging: How to configure log channels and route log output.
  • Sanity Checks: How to use the sanity check system to ensure your application environment is correct.

Utilities

  • Translations: How to deploy and configure multi-lingual support in your application.
  • Event Handling: How to trigger and handle Events with EventListeners.
  • Modules: Available installable modules that extend WebFramework functionality.
  • Mailing: How to send emails synchronously or asynchronously using the mail system.

Development Guide

Getting Started

To get started with WebFramework, follow the Installation Guide to set up your project. Once installed, explore the documentation to learn how to leverage the full capabilities of WebFramework in your application.

For any questions or further assistance, please refer to the documentation or reach out to the WebFramework community.

Happy coding!