Mastodon
Skip to content

Home

Welcome to the WebFramework documentation. WebFramework is a companion framework to use on top of the Slim Framework, designed to provide a cohesive set of services around database management, ORM, caching, authentication, middleware, templating, translations, instrumentation, and more.

Installation

Skeleton Application

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

composer create-project avoutic/web-framework-skeleton

Existing project

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

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:

    "scripts": {
        "post-install-cmd": [
            "php -r \"copy('vendor/avoutic/web-framework/htdocs/index.php', 'htdocs/index.php');\"",
            "mkdir -p scripts",
            "php -r \"copy('vendor/avoutic/web-framework/scripts/db_init.php', 'scripts/db_init.php');\"",
            "php -r \"copy('vendor/avoutic/web-framework/scripts/db_update.php', 'scripts/db_update.php');\"",
            "php -r \"copy('vendor/avoutic/web-framework/scripts/db_version.php', 'scripts/db_version.php');\"",
            "php -r \"copy('vendor/avoutic/web-framework/scripts/sanity_check.php', 'scripts/sanity_check.php');\""
        ],
        "post-update-cmd": [
            "php -r \"copy('vendor/avoutic/web-framework/htdocs/index.php', 'htdocs/index.php');\"",
            "mkdir -p scripts",
            "php -r \"copy('vendor/avoutic/web-framework/scripts/db_init.php', 'scripts/db_init.php');\"",
            "php -r \"copy('vendor/avoutic/web-framework/scripts/db_update.php', 'scripts/db_update.php');\"",
            "php -r \"copy('vendor/avoutic/web-framework/scripts/db_version.php', 'scripts/db_version.php');\"",
            "php -r \"copy('vendor/avoutic/web-framework/scripts/sanity_check.php', 'scripts/sanity_check.php');\""
        ]
    },

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.
  • db_scheme: Contains the database migrations for the application.
  • definitions: Contains the PHP-DI definitions for the application.
  • htdocs: The location for the core index.php and external static files like images, CSS, and JavaScript.
  • 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:

    "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:

  • Installation Guide: Instructions for installing WebFramework and setting up a base project.
  • Migration Guide: Guidance on migrating between different versions of WebFramework.
  • Configuration Management: How to manage and access configuration settings in your application.
  • Dependency Injection: How to use and configure dependency injection in WebFramework.
  • 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.
  • Entities and Repositories: Understanding the Entity and Repository pattern in WebFramework.
  • Creating New Entities: Step-by-step guide to creating new entities and repositories.
  • Input Validation: How to add input validation to your actions using the InputValidationService.
  • 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.
  • Sanity Checks: How to use the sanity check system to ensure your application environment is correct.
  • Tasks: How to create and run tasks from the command line.
  • Templating: How to use the Latte templating engine to render templates.
  • Translations: How to deploy and configure multi-lingual support in your application.
  • Emitting Responses: How to generate responses in actions using the ResponseEmitter or via exceptions.
  • Caching: How to use caching to store and retrieve data efficiently.

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!