PHPackages                             ffperera/cubo - 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. ffperera/cubo

ActiveLibrary[Framework](/categories/framework)

ffperera/cubo
=============

"Lightweight PHP framework for web apps"

v1.2.2(1y ago)08MITPHPPHP &gt;=8.1

Since Apr 17Pushed 1y ago1 watchersCompare

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

READMEChangelog (5)Dependencies (4)Versions (6)Used By (0)

Cubo
====

[](#cubo)

Cubo is a lightweight PHP framework designed for building web applications with simplicity and flexibility.

It provides a minimalist but solid foundation for the development process, with zero hidden magic features, and avoiding overengineered techniques, while ensuring a clean and modular architecture.

**NOTE**: While Cubo can certainly be used in real-world production projects, there are more established frameworks with strong community support like [Symfony](https://symfony.com/) and [Laravel](https://laravel.com/). We recommend considering these alternatives for enterprise-level applications requiring extensive ecosystem support.

Features
--------

[](#features)

- **Lightweight and Fast**: Minimal overhead for optimal performance.
- **Modular Design**: Easily extendable and customizable.
- **Queue of Actions**: Queue-based workflow where requests are processed through sequential actions (*controller-like* components).
- **PSR-4 Autoloading**: Follows modern PHP standards for autoloading.
- **View Rendering**: Built-in support for rendering views and layouts.
- **HTTP Response Handling**: Simplifies response management.

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- Composer

Installation
------------

[](#installation)

Install using Composer:

```
composer install ffperera/cubo
```

Usage
-----

[](#usage)

Think of Cubo as a tool designed to manage request routing and the tasks and services linked to those routes.

As we'll explore later, Cubo operates through executing sequences of tasks, encapsulated as `Action` objects.

A Cubo-based project can be organized in countless ways. The framework is intentionally project-structure agnostic. You’re free to adopt whatever project layout best suits your needs, and you can use external components, packages, or services as required.

However, it’s important to note that Cubo’s core philosophy centers on building ultra-lightweight applications.

### Project structure

[](#project-structure)

A typical project using Cubo looks like this:

```
├── dev
│   └── scss
├── root
│   └── assets
│   │   └── pub
│   │       └── css
│   └── index.php
├── src
│   ├── config
│   │   └── routing.php
│   ├── Api
│   │
│   ├── Adm
│   │   ├── Global
│   │   │   └── Actions
│   │   ├── Home
│   │   │   └── Actions
│   │   ├── Login
│   │   │   └── Actions
│   │   ├── Menu
│   │   │   └── Actions
│   │   ├── PDO
│   │   │   └── Actions
│   │   ├── User
│   │   │    ├── Actions
│   │   │    ├── Model
│   │   │    └── Repository
│   │   └── layout
│   └── Pub
│       ├── Global
│       │   └── Actions
│       ├── Home
│       │   └── Actions
│       ├── Menu
│       │   └── Actions
│       ├── User
│       │   └── Actions (Register, Login ...)
│       └── layout
│
└── tests

```

### Entry point

[](#entry-point)

The app entry point is **/root/index.php**

This file is located in the **public** directory (root folder) of the HTTP server.

Public resources and assets like images and CSS files should be placed in the **/root** directory.

All other folders reside outside the root directory and cannot be accessed directly from external sources.

### Sections

[](#sections)

Each section can maintain its own:

- Layout templates
- Actions
- Data layers
- ...and other components

These sections can be converted into independent services (eg. micro services) with minimal refactoring.

### Action queues

[](#action-queues)

An `Action` is a class that performs specific tasks.

Developers can:

- Define action sequences (e.g., using a routing file) to handle requests
- Implement controller-like actions that manage request-specific operations
- Create middleware actions that execute before primary actions
- Utilize actions for dependency injection

There are three action queues:

- *pre*: Handles setup tasks, dependency injections, and middleware
- *main*: *Controller-like* actions tied to specific routes
- *pos*: Manages cleanup operations

Action queues are dynamic ones.

- Add new actions *mid-execution*, we can insert new Actions in the queue from the actual Action.
- Remove existing actions dynamically
- Implement error recovery flows

Example: If a request fails, abort the current action and insert a fallback action to handle the failure.

### Action

[](#action)

Example of one `Action` class.

```
class PostList extends Action
{
  public function __construct(private IPostRepository $repo) {}

  public function run(Controller $controller): void
  {

    // initialize the repository with the PDO connection
    try {
        $this->repo->init(['PDO' => $controller->get('PDO')]);
    }
    catch (\Exception $e) {
        // TODO: handle the exception
    }

    // fetch posts from the repository
    $posts = $this->repo->getPosts();

    $view = $controller->getView();

    $view->set('posts', $posts);

    $view->set('title', 'POSTS');
    $view->set('post-list-intro', 'This is the list of posts');

    $view->setLayout('/Pub/layout/main.php');
    $view->setTemplate('main', '/Pub/layout/post_list.php');

    $view->set('metatitle', 'List of Posts');
    $view->set('metadesc', 'Published posts');
    $view->set('canonical', '/blog/');

  }

}
```

### Main controller

[](#main-controller)

The `Controller` object acts as Cubo's orchestration center. It is like the **kernel** component of other frameworks.

It handles:

- Request routing management
- Action queues
- Dependency injection (e.g., services)
- Access to core Cubo components (`Request`, `View`, `Render`, `Response`)

Once configured, your application primarily operates through the `Controller::run()` method call.

```
$controller = new Controller($routes, $logger, $debug=true);

try {
    $view = $controller->run();

    if ($view) {
        $render = new Render($view, $srcDir);
        $render->send();
    }

} catch (Exception $e) {
    // Handle exceptions and errors
    echo 'Error: ' . $e->getMessage();
}
```

### Routing

[](#routing)

The routing file contains an array defining:

- All possible entry points for each section
- Associated actions for pre and post queues

Example:

```
    'app' => [
        'home' => [
            'action' => new App\Pub\Home\Actions\App(new App\Pub\Post\Repository\PostRepositoryPDO()),
            'path' =>   '/',
            'method' => 'GET',
        ],
        'blog' => [
            'action' => new App\Pub\Post\Actions\PostList(new App\Pub\Post\Repository\PostRepositoryPDO()),
            'path' =>   '/blog/',
            'method' => 'GET',
        ],
        'user-add' => [
            'action' => new App\Pub\User\Actions\UserRegisterForm(),
            'path' =>   '/register/',
            'method' => 'GET',
        ],
        'user-add-sav' => [
            'action' => new App\Pub\User\Actions\UserRegister(new App\Adm\User\Repository\UserRepositoryPDO()),
            'path' =>   '/register/',
            'method' => 'POST',
        ],
        'login' => [
            'action' => new App\Pub\User\Actions\UserLoginForm(),
            'path' =>   '/login/',
            'method' => 'GET',
        ],
        'login-in' => [
            'action' => new App\Pub\User\Actions\UserLogin(new App\Adm\User\Repository\UserRepositoryPDO()),
            'path' =>   '/login/',
            'method' => 'POST',
        ],
        'logout' => [
            'action' => new App\Pub\User\Actions\UserLogout(),
            'path' =>   '/logout/',
            'method' => 'GET',
        ],
        'PRE' => [
                    new App\Pub\Global\Actions\Session(new \FFPerera\Lib\Session(1800)),
                    new App\Adm\PDO\Actions\PDOConnection(),  // inject the PDO connection
                    new App\Pub\Menu\Actions\Menu()  // dynamic menu
                 ],
        'POS' => [],
    ],
```

### Rendering Views

[](#rendering-views)

The **Render** class is responsible for rendering views and layouts.

We can render directly to the client or render to a `Response` object depending on our needs.

Here's an example of how to use it:

```
// inside the Action::run() method
$view = $controller->getView();
$view->setLayout('layout.php');
$view->setTemplate('content', 'content.php');

// inside the Action or in the main entry point
if ($view && $view instanceof \FFPerera\Cubo\View) {
    $render = new Render($view, $srcDir);
    $render->send();
}
```

Render can use PHP templates:

```

  block('menu'); } ?>

  block('content'); } ?>

    This is the footer

```

In the `View` object, you can configure a single layout (e.g., an HTML skeleton) and include multiple templates and variables as needed.

Templates can be invoked from the layout or other templates using the `Render::block()` method.

Data injected into the `View` by `Actions` can be accessed using the `View::get()` method.

Additionally, you can create a custom `Render` subclass to integrate third-party template engines seamlessly.

In this [demo](https://github.com/ffperera/cubo-demo) project, we use the [Latte](https://latte.nette.org/en/) template engine and PHP templates working together.

### HTTP Responses

[](#http-responses)

The **Response** class allows you to manage HTTP headers, status codes, and redirections.

```
$response = new Response('{"key": "value"}', $options =[
        'headers' => [
            'Content-Type' => 'application/json; charset=UTF-8',
        ],
        'statusCode' => 200,
        'statusText' => 'OK',
        'protocolVersion' => '1.1',
]);

$response = $response->withHeader('X-Custom-Header', 'CustomValue');

$response->send();
```

Contributing
------------

[](#contributing)

Contributions are welcome!

Please fork the repository, create a feature branch, and submit a pull request.

License
-------

[](#license)

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance48

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~4 days

Total

5

Last Release

380d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4c66ebdaedb3502d249ba79cb306755bdc77cb5d1b3ea13040ed88c3ad690e5a?d=identicon)[ffperera](/maintainers/ffperera)

---

Top Contributors

[![ffperera](https://avatars.githubusercontent.com/u/6794915?v=4)](https://github.com/ffperera "ffperera (37 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ffperera-cubo/health.svg)

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

###  Alternatives

[symfony/symfony

The Symfony PHP framework

31.3k86.3M2.2k](/packages/symfony-symfony)[cakephp/cakephp

The CakePHP framework

8.8k18.5M1.6k](/packages/cakephp-cakephp)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[laravel/nightwatch

The official Laravel Nightwatch package.

3526.1M13](/packages/laravel-nightwatch)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

81733.7k](/packages/flow-php-flow)

PHPackages © 2026

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