This short guide shows how to add Gacela to a fresh PHP project and build your first module.
composer require gacela-project/gacela<?php
declare(strict_types=1);
use Gacela\Framework\Bootstrap\GacelaConfig;
return static function (GacelaConfig $config): void {
$config->addAppConfig('config/*.php');
};src/
└── Hello
├── Facade.php
├── Factory.php
└── Greeter.php
src/Hello/Facade.php
<?php
declare(strict_types=1);
namespace App\Hello;
use Gacela\Framework\AbstractFacade;
final class Facade extends AbstractFacade
{
public function sayHello(): string
{
return $this->getFactory()->createGreeter()->greet();
}
}src/Hello/Factory.php
<?php
declare(strict_types=1);
namespace App\Hello;
use Gacela\Framework\AbstractFactory;
final class Factory extends AbstractFactory
{
public function createGreeter(): Greeter
{
return $this->singleton(Greeter::class, fn () => new Greeter());
}
}Using
singleton()the factory keeps instances in memory.
src/Hello/Greeter.php
<?php
declare(strict_types=1);
namespace App\Hello;
final class Greeter
{
public function greet(): string
{
return 'Hello Gacela!';
}
}use Gacela\Framework\Gacela;
require __DIR__ . '/vendor/autoload.php';
Gacela::bootstrap(__DIR__);Now you can use your facade:
$hello = (new \App\Hello\Facade())->sayHello();See the official documentation and the example repository for more advanced usage.