This section explains the parts of Crest that the rest of this page uses: The project file, The global Crest and the project Crest, The runtime, The launcher and Stubs.
The project file
Each project has a crest.php at its root. This is the project file. crest new writes it. For an existing project, crest init writes it (see Adding Crest to an existing project). The file holds the settings of the project, for example:
- the flavor
- the root namespace
- the front controller (the class that starts the application)
- the folders that Crest writes into
- the runtime (see The runtime)
The bootstrap key names the front controller (see Commands that boot the project). Configuration shows each key.
Crest finds the project by its crest.php: the file that --config names, or the nearest crest.php in or above the working directory or --directory (see Global options). Without crest.php, Crest stops. This error is the same in both flavors:
crest: no crest.php found; run 'crest init'The global Crest and the project Crest
The commands that work on the project, for example make:controller, make:action and route:list, need the autoloader and the Phalcon of the project. A project from crest new requires phalcon/crest as a dev dependency. Thus after crest install (see The launcher) or composer install, it has its own Crest in vendor/bin/crest. A global Crest passes the project commands to this Crest, with the same arguments, and returns its exit status. This is the hand-off.
make:controller creates an MVC controller (see Generating controllers). make:action creates an ADR action for a route (see Generating actions). route:list shows each route that the application answers (see Command reference). For example, a global Crest passes this command to vendor/bin/crest:
MVC
crest make:controller HelloADR
crest make:action GET /helloThe about command shows the environment and version report (see Command reference). In a project, run crest with the global Crest:
MVC
crest # list the available commands
crest about # show the environment and version report
crest make:controller CompanyADR
crest # list the available commands
crest about # show the environment and version report
crest make:action GET /company/allWithout a global Crest, run the Crest of the project: vendor/bin/crest in the project, or ./crest on a host with docker and no PHP (see The launcher). In this text, the container is the docker compose service app, a container that docker compose runs (see The runtime). In the container, there is no global Crest, so run vendor/bin/crest there:
MVC
docker compose exec app vendor/bin/crest make:controller HelloADR
docker compose exec app vendor/bin/crest make:action GET /hellonew, init, up, down, install and --version (see Global options) always run in the crest that you type, with no hand-off. down stops the containers (see The launcher). new, up, down and install run before the project has a vendor/. Thus run them with a Crest outside the vendor/ of the project, for example the global Crest (see Installation) or the launcher ./crest (see The launcher).
bin-dir is a setting of composer (see Configuration). If the project has no <bin-dir>/crest (by default vendor/bin/crest), Crest stops, as it does without crest.php. The messages are the same in both flavors:
crest: /path/to/my-app has no vendor/bin/crest; run 'crest install' or 'composer install' first
crest: /path/to/my-app does not require phalcon/crest; run 'composer require --dev phalcon/crest'The second message is for a project that does not require Crest. Add :dev-master to the composer require command of this message (see Installation).
The runtime
The runtime key of crest.php says where the project commands run:
- With
['type' => 'host'], a global Crest runs the project’svendor/bin/crestwith the PHP of the host. - With
['type' => 'docker', 'service' => 'app'](whatcrest newwrites), a global Crest runsdocker compose exec app vendor/bin/crest ...in the project root.appis the service: a container that the compose file of the project names.
Use docker when Phalcon is only in the container. For example, a v5 project then works on a host without ext-phalcon. The containers must be up (crest up).
The docker runtime has two conditions. The compose file that crest new writes, docker-compose.yml, meets both:
- The service must mount the project folder (share it with the container), with
vendor/in it: Crest looks forvendor/bin/creston the host first. - The
working_dirof the service, the folder where its commands start, must be the project root:vendor/bin/crestruns there.
crest install runs composer in a docker compose service, with each runtime. With the docker runtime, composer runs in the service of the runtime. With the host runtime, composer runs in the service of the runtime key, else in app.
crest serve is the exception: it always runs on the host, because PHP’s built-in server must listen there. With docker, crest up serves the project.
The launcher
./crest is a launcher script that crest new writes into the project. It needs docker only: PHP on the host is not necessary.
./crest up, ./crest down and ./crest install run docker compose on the host: they start the containers, stop them, and install the dependencies. With a global Crest, crest up and crest install do the same. Crest runs up, down and install with docker compose in the folder of the crest.php that it finds (see The project file).
All other commands of ./crest run vendor/bin/crest in the service of the project (app, or the --service of new; see Creating a project):
MVC
./crest make:controller HelloADR
./crest make:action GET /helloBefore ./crest install, they stop with crest: run './crest install' first. Without a terminal (CI, a pipe), the launcher adds -T, which tells docker compose exec not to ask for a terminal. On Windows, run ./crest in WSL2.
The .env file of the project holds settings that docker compose reads, for example APP_PORT and the user and group IDs (UID and GID). The files that the container writes belong to the user of these IDs. With rootless docker (docker that runs without root), set UID=0 and GID=0 in .env: rootless docker maps root in the container to your user.
The Crest commands of the launcher get CREST_HOST_ROOT, the host folder of the project. Thus Crest shows host paths, not the paths in the container. The hand-off of a global Crest does the same.
The launcher runs vendor/bin/crest. If you change vendor-dir or bin-dir in composer.json (see Configuration), change the crest= line at the top of ./crest.
Stubs
Crest generates files from stubs. A stub is a template in the Crest package, with placeholders such as {{ flavor }}: Crest fills in each placeholder with a value of the project. To change a stub, publish a copy with crest stub:publish, and edit the copy. Crest then uses your copy. crest new writes a project from the project-* stubs, for example the project-config stub for crest.php. Custom stubs and Project stubs tell where each copy goes. For the project-config stub, see also Commands after new.
Some generators also write a base: a class that Crest owns and writes again, for example CrestControllerBase, which your controllers extend. Generated bases tells when Crest writes a base again.