Four commands read objects that exist only after the application registers them. container:list reads the services and lists them, and event:list reads the listeners of the events manager and lists them. make:model and make:scaffold (see Generating scaffolds) read the db service (see The database). Thus these commands start your front controller: they boot the project. Name the front controller in the bootstrap key of crest.php:
MVC
return [
'bootstrap' => App\AppFront::class,
];ADR
return [
'bootstrap' => App\Front\ApiFront::class,
];Crest constructs the class with the project root. The constructor can take the root if the class needs it. The class must declare boot(). There is no class to extend and no interface to implement: boot() is the whole contract. In the MVC example, boot() returns a FactoryDefault (a Phalcon\Di\DiInterface). In the ADR example, boot() returns a Phalcon\Container\Container. Each one is a DI container (see The MVC project):
MVC
use Phalcon\Di\DiInterface;
use Phalcon\Di\FactoryDefault;
final class AppFront
{
public function __construct(private readonly string $projectRoot)
{
}
public function boot(): DiInterface
{
$container = new FactoryDefault();
// register your providers, with the db service
return $container;
}
}ADR
use Phalcon\Container\Container;
final class ApiFront
{
public function __construct(private readonly string $root)
{
}
public function boot(): Container
{
$container = new Container();
// register your services
return $container;
}
}boot() must return an object. Each command has its own conditions for that object:
| Command | Flavor | Requires the returned object to |
|---|---|---|
container:list |
ADR | implement Phalcon\Contracts\Container\Service\Collection and Phalcon\Contracts\Container\Service\Enumerable |
event:list |
ADR | implement Collection, and hold a registered Phalcon\Events\Manager |
make:model, make:scaffold |
MVC | implement Phalcon\Di\DiInterface, and hold a db service that is a Phalcon\Db\Adapter\AdapterInterface |
Phalcon\Container\Container implements both contracts of the container:list row. Thus boot() can return a Phalcon\Container\Container for container:list.
For event:list, “registered” means a definition or an instance that exists. A manager that the container can only autowire does not count. In that case, Crest stops with an error that says that the bootstrap registers no manager. It does not show zero listeners from a new instance that it made itself.
All the other commands, for example the other generators, about, config:show and route:list, do not start your front controller. Thus they also work on a project that does not run. make:database starts it when it can, to look for a db service, and also works on a project that does not run (see Adding a database).