PHPackages                             simplemvc/framework - 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. [Framework](/categories/framework)
4. /
5. simplemvc/framework

ActiveLibrary[Framework](/categories/framework)

simplemvc/framework
===================

SimpleMVC framework

0.3.0(3y ago)346554[1 PRs](https://github.com/simplemvc/framework/pulls)1MITPHPPHP ^7.4 || ^8.0

Since Jul 25Pushed 3y ago5 watchersCompare

[ Source](https://github.com/simplemvc/framework)[ Packagist](https://packagist.org/packages/simplemvc/framework)[ RSS](/packages/simplemvc-framework/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (10)Versions (6)Used By (1)

SimpleMVC
---------

[](#simplemvc)

[![Build status](https://github.com/simplemvc/framework/workflows/PHP%20test/badge.svg)](https://github.com/simplemvc/framework/actions)

**SimpleMVC** is an [MVC](https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller) framework for PHP based on the [KISS](https://en.wikipedia.org/wiki/KISS_principle) principle:

> "Keep It Simple, Stupid"

The goal of this project is to offer a simple to use and fast framework for PHP applications using [PSR](https://www.php-fig.org/psr/) standards.

SimpleMVC uses the [dependency injection](https://en.wikipedia.org/wiki/Dependency_injection) pattern to manage the dependencies between classes and the [FastRoute](https://github.com/nikic/FastRoute) library for implementing the routing system.

SimpleMVC uses the following PSR standards, from the [PHP-FIG](https://www.php-fig.org/) initiative:

- [PSR-11](https://www.php-fig.org/psr/psr-11/) for DI Container;
- [PSR-7](https://www.php-fig.org/psr/psr-7/) for HTTP message;
- [PSR-3](https://www.php-fig.org/psr/psr-3/) for logging;

This project was born as educational library for the course **PHP Programming** by [Enrico Zimuel](https://www.zimuel.it/)at [ITS ICT Piemonte](http://www.its-ictpiemonte.it/) in Italy.

Since than, the project has been evoluted and used also for building web application in production. We decided to create a more general purpose project and this was the beginning of this repository.

Introduction
------------

[](#introduction)

SimpleMVC implements the [Model–View–Controller](https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller) (MVC) architectural pattern using [Dependency injection](https://en.wikipedia.org/wiki/Dependency_injection)and [PSR](https://www.php-fig.org/psr/) standards.

A SimpleMVC application looks as follows:

```
chdir(dirname(__DIR__));
require 'vendor/autoload.php';

use DI\ContainerBuilder;
use SimpleMVC\App;
use SimpleMVC\Emitter\SapiEmitter;

$builder = new ContainerBuilder();
$builder->addDefinitions('config/container.php');
$container = $builder->build();

$app = new App($container);
$app->bootstrap(); // optional
$response = $app->dispatch(); // PSR-7 response

SapiEmitter::emit($response);
```

In this example we use a DI container with [PHP-DI](https://php-di.org/). We create a `SimpleMVC\App` object using the previous container.

The application can be configured using the `config/container.php` file. An example is as follows:

```
// config/container.php
use App\Controller;

return [
    'config' => [
        'routing' => [
            'routes' => [
                [ 'GET', '/', Controller\HomePage::class ]
            ]
        ]
    ]
];
```

The steps to manage the request are:

- `bootstrap()` (optional), here you can specify any bootstrap requirements;
- `dispatch()`, where the HTTP request is dispatched, executing the controller specified in the route.

The `dispatch()` returns a PSR-7 response. Finally, we can render the response using an emitter. In this example we used a `SapiEmitter` to render the PSR-7 response in the standard output.

The previous PHP script is basically a front controller of an MVC application (see diagram below).

[![MVC diagram](doc/mvc.png)](doc/mvc.png)

In this diagram the front controller is stored in a `public/index.php` file. The `public` folder is usually the document root of a web server.

Using a pipeline of controllers
-------------------------------

[](#using-a-pipeline-of-controllers)

If you want you can specify a pipeline of controllers to be executed for a specific route. For instance, imagine to have a route as follows:

```
// config/container.php
use App\Controller;
use SimpleMVC\Controller\BasicAuth;

return [
    'config' => [
        'routing' => [
            'routes' => [
                [ 'GET', '/admin', [BasicAuth::class, Controller\HomePage::class ]
            ]
        ],
        'authentication' => [
            'username' => 'admin',
            'password' => '1234567890'
        ]
    ]
];
```

The route `GET /admin` will execute the `BasicAuth` controller first and, if the authentication will be successfull, the `HomePage` controller after.

This is a pipeline of two controllers executed in order. The `BasicAuth` is a simple implementation of the [Basic Access Authentication](https://en.wikipedia.org/wiki/Basic_access_authentication). This controller uses the `username` and `password`configuration in the `authentication` section.

If the authentication is not success, the `BasicAuth` emits an `HaltResponse` that will stop the pipeline execution. `HaltResponse` is a special PSR-7 that informs the SimpleMVC framework to halt the execution.

Passing attributes between controllers
--------------------------------------

[](#passing-attributes-between-controllers)

If you need to pass an attribute (parameter) from a controller to another in a pipeline of execution you can use the `AttributeInterface`. For instance, imagine to pass a `foo` attribute from a controller `A` to controller `B`, using the follwing routing pipeline:

```
// config/container.php
use App\Controller;

return [
    'config' => [
        'routing' => [
            'routes' => [
                [ 'GET', '/', [Controller\A::class, Controller\B::class ]
            ]
        ]
    ]
];
```

You need to create the controller A as follows:

```
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use SimpleMVC\Controller\AttributeInterface;
use SimpleMVC\Controller\AttributeTrait;
use SimpleMVC\Controller\ControllerInterface;

class A implements ControllerInterface, AttributeInterface
{
    use AttributeTrait;

    public function execute(
        ServerRequestInterface $request,
        ResponseInterface $response
    ): ResponseInterface
    {
        $this->addRequestAttribute('foo', 'bar');
        return $response;
    }
}
```

We can use an `AttributeTrait` that implements the `AttributeInterface` with the `addRequestAttribute(string $name, $value)`. This function adds a [PSR-7](https://www.php-fig.org/psr/psr-7/)attribute into the `$request` for the next controller.

In order to get the `foo` parameter in the `B` controller you can use the PSR-7 standard function `getAttribute()` from the HTTP request, as follows:

```
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use SimpleMVC\Controller\ControllerInterface;

class B implements ControllerInterface
{
    public function execute(
        ServerRequestInterface $request,
        ResponseInterface $response
    ): ResponseInterface
    {
        $attribute = $request->getAttribute('foo');
        pritnf("Attribute is: %s", $attribute);
        return $response;
    }
}
```

Notice that you don't need to implement the `AttributeInterface` for the `B` controller since we only need to read from the `$request`.

Quickstart
----------

[](#quickstart)

You can start using the framework with the [skeleton](https://github.com/simplemvc/skeleton) application.

Copyright
---------

[](#copyright)

The author of this software is [Enrico Zimuel](https://github.com/ezimuel/) and other [contributors](https://github.com/simplemvc/framework/graphs/contributors).

This software is released under the [MIT License](/LICENSE).

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~25 days

Total

3

Last Release

1343d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/75c7c511421feb14316a01d29a7566bd4fdd97147b5a4f3faa5a065f9d0a0193?d=identicon)[ezimuel](/maintainers/ezimuel)

---

Top Contributors

[![ezimuel](https://avatars.githubusercontent.com/u/475967?v=4)](https://github.com/ezimuel "ezimuel (22 commits)")[![stefanak-michal](https://avatars.githubusercontent.com/u/5502917?v=4)](https://github.com/stefanak-michal "stefanak-michal (1 commits)")

---

Tags

psr-7frameworkSimplemvc

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/simplemvc-framework/health.svg)

```
[![Health](https://phpackages.com/badges/simplemvc-framework/health.svg)](https://phpackages.com/packages/simplemvc-framework)
```

###  Alternatives

[cakephp/cakephp

The CakePHP framework

8.8k18.5M1.6k](/packages/cakephp-cakephp)[laravel/framework

The Laravel Framework.

34.7k509.9M17.0k](/packages/laravel-framework)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[antidot-fw/framework

Anti.Framework library

183.2k5](/packages/antidot-fw-framework)[originphp/framework

The OriginPHP framework

472.6k6](/packages/originphp-framework)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
