Gacela
2.1.0 release notes (opens in a new tab)
Colour theme

Build modular PHP applications.

Split your application into modules that talk through one door. Everything behind it stays private.

src/Checkout any module Facade Factory your services your domain Config config/*.php Provider other modules

The only door. Every other module in your application talks to this module through its Facade, and through nothing else. Change what is behind it freely: nobody outside can depend on what they cannot reach. Read about the Facade

Wires the inside. The Factory builds this module's own services and hands them their dependencies. It is where object construction lives, so your domain classes never have to know how they were made. Read about the Factory

Reaches outside. When the module needs something another module owns, the Provider resolves it. Extra-dependencies enter here and nowhere else, which keeps the coupling in one readable file. Read about the Provider

Reads the settings. The Config gives the Factory typed access to the project's configuration files, so a value can change per environment without any class inside the module learning where it came from. Read about the Config

Quickstart

A module in three files

This is the whole ceremony: a Facade in front, a Factory wiring a service behind it, and one bootstrap call at your entry point. The Facade resolves its sibling Factory automatically.

use Gacela\Framework\Gacela;
use Module\Facade;

require __DIR__ . '/vendor/autoload.php';

Gacela::bootstrap(__DIR__);

$facade = new Facade();
echo $facade->greet('Alice'); # Hi, Alice!
namespace Module;

use Gacela\Framework\AbstractFacade;

/**
 * @method Factory getFactory()
 */
final class Facade extends AbstractFacade
{
    public function greet(string $name): string
    {
        return $this->getFactory()
            ->createGreeter()
            ->greet($name);
    }
}
namespace Module;

use Gacela\Framework\AbstractFactory;
use Module\Service\Greeter;

final class Factory extends AbstractFactory
{
    public function createGreeter(): Greeter
    {
        return new Greeter();
    }
}
namespace Module\Service;

final class Greeter
{
    public function greet(string $name): string
    {
        return "Hi, $name!";
    }
}

Get started

Start your first module

composer require gacela-project/gacela:^2.1