Skip to content

Latest commit

 

History

History
106 lines (77 loc) · 1.78 KB

File metadata and controls

106 lines (77 loc) · 1.78 KB

Getting Started

This short guide shows how to add Gacela to a fresh PHP project and build your first module.

1. Install

composer require gacela-project/gacela

2. Create the gacela.php bootstrap file

<?php
declare(strict_types=1);

use Gacela\Framework\Bootstrap\GacelaConfig;

return static function (GacelaConfig $config): void {
    $config->addAppConfig('config/*.php');
};

3. Add your first module

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!';
    }
}

4. Bootstrap the application

use Gacela\Framework\Gacela;

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

Gacela::bootstrap(__DIR__);

Now you can use your facade:

$hello = (new \App\Hello\Facade())->sayHello();

Next steps

See the official documentation and the example repository for more advanced usage.