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

You then probably want to add something like the following to your composer.json file, to make sure the core files are installed:

JSON
    "scripts": {
        "post-install-cmd": [
            "php -r \"copy('vendor/avoutic/web-framework/public/index.php', 'public/index.php');\"",
            "php -r \"copy('vendor/avoutic/web-framework/scripts/framework.php', 'framework');\""
        ],
        "post-update-cmd": [
            "php -r \"copy('vendor/avoutic/web-framework/public/index.php', 'public/index.php');\"",
            "php -r \"copy('vendor/avoutic/web-framework/scripts/framework.php', 'framework');\""
        ]
    },

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
    "autoload": {
        "psr-4": {
            "App\\": "src/",
            "App\\Actions\\": "actions/",
            "App\\Routes\\": "routes/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "WebFramework\\PHPStan\\": "vendor/avoutic/web-framework/phpstan/"
        }
    },

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!