PHPackages                             simple-php-web/simple-php-web - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. simple-php-web/simple-php-web

ActiveProject

simple-php-web/simple-php-web
=============================

simple php framework

1.0.2(1y ago)414AGPL-3.0-or-laterPHP

Since Sep 21Pushed 1y ago1 watchersCompare

[ Source](https://github.com/ayela-emmanuel/SimplePHP)[ Packagist](https://packagist.org/packages/simple-php-web/simple-php-web)[ RSS](/packages/simple-php-web-simple-php-web/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (3)Used By (0)

### Simple PHP Framework Documentation

[](#simple-php-framework-documentation)

---

### **Table of Contents**

[](#table-of-contents)

1. [Introduction](#introduction)
2. [Installation](#installation)
3. [Core Components](#core-components)
    - [Routing](#routing)
    - [HTTP Context](#http-context)
    - [Middleware](#middleware)
4. [Features](#features)
    - [Routing](#routing-feature)
    - [Request Handling](#request-handling)
    - [File Upload](#file-upload)
    - [Response Handling](#response-handling)
    - [Middleware Support](#middleware-support)
    - [CORS Middleware](#cors-middleware)
    - [Auto Documentation(API Explorer)](#auto-doc)
5. [Configuration](#configuration)
6. [Debugging](#debugging)
7. [DataTransformer](#data-transformer)
8. [Example Usage](#example-usage)

---

### **1. Introduction**

[](#1-introduction-)

The simplePHP framework provides essential tools to create modern web applications. It includes routing, request and response handling, middleware support, and features for handling file uploads with validation. The framework is designed with flexibility in mind, and uses PHP 8’s attributes for route-specific middleware and annotations for lower versions of PHP.

---

### **2. Installation**

[](#2-installation-)

#### **Requirements**:

[](#requirements)

- PHP 7.4+ (PHP 8+ recommended for attributes support)

#### **Installation Steps**:

[](#installation-steps)

1. Clone the repository or use composer to create project via: ```
    composer create-project simple-php-web/simple-php-web

    ```
2. Run `composer install` to set up dependencies.
3. Configure the `public/index.php` file as your entry point for your application.

```

```

---

### **3. Core Components**

[](#3-core-components-)

The framework is composed of several core components:

- **Routing**: Defines how incoming HTTP requests are matched to controller actions.
- **HTTP Context**: Handles the request and response objects to encapsulate HTTP data.
- **Middleware**: Allows you to intercept requests and responses for additional processing.

---

### **4. Features**

[](#4-features-)

#### **4.1. Routing**

[](#41-routing-)

The framework includes a simple routing mechanism that maps URLs to controller actions. It supports defining routes using PHP attributes (in PHP 8+) and annotations (for PHP 7.4+).

**Features**:

- **Route Attributes**: Easily define routes in your controllers.
- **Route-Specific Middleware**: Apply middleware to specific routes using attributes or annotations.
- **Support for Route Groups**: You can define common prefixes or middleware for multiple routes.

**Example**:
Recommended Folder Structure for Src

```
src/
│
├── Controllers/
│   ├── API/
│   │   ├── BaseApiController.php
│   │   ├── UserController.php
│   │   └── ProductController.php
│   │   └── # Other API controllers files
│   ├── WEB/
│   │   ├── BaseWebController.php
│   │   ├── HomeController.php
│   │   ├── AuthController.php
│   │   └── # Other Other Web controllers
│
├── Middleware/
│   ├── AuthMiddleware.php
│   └── # Other Middleware files
│
├── Models/
│   ├── Data/
│   │   └── UserLoginModel.php
│   ├── Database/
│   │   └── AppUser.php
│
├── Templates/
│   ├── Layouts/
│   │   ├── BaseLayout.latte
│   │   └── # Other layout templates
│   ├── HomePage.latte
│   └── # Other page templates
│
└── # Other core directories and files as needed
```

*it is recommended to follow psr-4 standard for namespaces*

```
namespace App\Controllers\WEB;
class FooController
{
    #[Route('/users', 'GET')]
    public function listUsers(Request $request, Response $response) {
        // Logic to list users
    }

}
```

For older versions of PHP, use annotation-based comments to define routes:

```
namespace App\Controllers\WEB;
class FooController
{
    /**
     * @Route("/users", methods={"GET"})
     */
    public function listUsers(Request $request, Response $response) {
        // Logic to list users
    }
}
```

after creating your controller you register them in `index.php`:

```
