Modular Framework  1.0
A light and thin PHP Framework
Loading...
Searching...
No Matches
Modular Framework

Welcome to Modular Framework.

Modular is a lightweight framework to create webservices or websites fast. It is heavily inspired by Spring Boot, so if you like Spring Boot you will also like Modular.

Why should you consider using Modular instead of Spring Boot? While one obvious reason is that you can program with PHP, there are numerous other benefits to using Modular. For instance, with Modular, you can directly upload your source code onto any web server and have it up and running without needing to compile or perform any other additional steps. As root servers can be quite expensive these days, opting for Modular can help you save money, as it can be run on any server with PHP installed. By doing a quick search online, you can easily find web hosting providers offering plans starting from as low as $2. In other words, hosting an API or website will cost you as little as $2.

Getting started

Download Modular Framework here.

Create an empty folder and put an index.php file inside of it. Inside the index.php file include the modular.phar:

<?php
include "modular.phar";

To make sure that routing is working properly create a .htaccess file in the folder as well:

Options All -Indexes -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L,QSA]

Now you can start a min. PHP 7.4 server. A folder Port should have appeared in your project directory now. Here you will find some examples how the basic structure of the framework is set up.

You can use Docker to create a suitable server. Paste docker-compose.yml and Dockerfile inside your project directory and run:

docker-compose up -d --build

If you want to skip these steps you can just clone the basic project from here.

Routing

Routing

Controller

<?php
namespace Port\Web\Controller;
class MainController extends BaseController {
}
Base controller class. Responsible for routing between different components.
Definition: BaseController.php:18

Simple Routes

// ...
class MainController extends BaseController {
/** @Get / */
public function main(): string {
return "Hello world";
}
}

Variables

// ...
class MainController extends BaseController {
// ...
/** @Get /user/{id} */
public function getUser(string $id): string {
return "User: $id";
}
}

Request Types

// ...
class MainController extends BaseController {
// ...
/** @Post /user/{id}/edit */
public function editUser(string $id): string {
return "User $id updated";
}
}

Response Entities

// ...
class MainController extends BaseController {
// ...
/** @Get /v1/user/{id} */
public function getUserWithId(string $id): string {
$user = ["name" => "Peter", "age" => 25];
return new ResponseEntity($user, HttpStatus::OK());
}
}
Represents the http status of a request.
Definition: HttpStatus.php:75
This class represents a response of a route.
Definition: ResponseEntity.php:14

Special Routes

// ...
class MainController extends BaseController {
// ...
/** @NotFound / */
public function notFound(): string {
return "Your not found page";
}
}

Customization

Customization

Environment Variables

Custom Header information

Coming soon...

Custom Themes

Coming soon...