Skip to content

Adding Crest to an Existing Project

Add Crest to a project that exists: crest init writes the project file, crest.php.

For an existing project, crest init writes crest.php (see The project file). If the project does not require Crest yet, add it as a dev dependency first. The composer require command needs the version dev-master (see Installation). The commands are the same in both flavors:

composer require --dev phalcon/crest:dev-master
crest init

init writes crest.php in the nearest folder with a composer.json. The psr-4 map is the autoload.psr-4 part of composer.json: it gives a folder to each namespace prefix, for example "App\\": "src/". The generators (the make:* commands) get their namespaces from this map. Thus init needs a psr-4 entry in composer.json. Without one, init stops and tells you to add one, for example "App\\": "app/", and to run composer dump-autoload.

init asks these questions, in this order. For each question, it proposes a value that it finds in the project:

  1. The namespace. The proposal is the namespace of the first psr-4 entry whose folder exists. The answer must be in the psr-4 map (App\Api under "App\\": "src/" is). The other proposals follow the answer: its folder is the psr-4 folder of the longest prefix, for example src/Api.

  2. The flavor: mvc or adr. For each flavor, init counts the default folders of that flavor (item 4) that the project has. It proposes the flavor with the most. A tie gives mvc. A project with src/Controllers, src/Providers and themes/vokuro gets mvc. --flavor answers the question.

  3. The front controller: <namespace>\AppFront when AppFront.php is in the folder of the namespace. Answer none for no front controller.

  4. A folder for each path of the flavor (the paths key of crest.php; see Configuration). The MVC paths are command, controller, form, model, module, provider and views. The ADR paths are action, command, middleware, provider, repository and responder. The question says if the folder exists. A class folder is in the folder of the namespace. An answer must be a relative folder in a psr-4 folder. Its folder names must give a usable namespace: src/my-actions gives App\my-actions, which PHP cannot use. init removes a leading ./.

    views holds no classes. It is a relative folder in the project, with no psr-4 check. Each part of the answer must be a folder name. Thus init refuses an absolute folder, an empty part (//), . and ... The proposal is themes/default. When that folder does not exist and themes/ has one folder only, init proposes that folder (themes/vokuro in vokuro). The answer none is a project with no views: init writes 'views' => false (see The MVC project).

  5. The runtime (see The runtime). The proposal is docker when the project has compose.yaml, compose.yml, docker-compose.yaml or docker-compose.yml. For docker, init also asks for the service. The proposal is app, or the first service.

  6. The database: none, mariadb, mysql, pgsql or sqlite. The proposal is none. --database answers the question. For another answer, init adds the database after it writes crest.php, as make:database does (see Adding a database). When the provider folder already has DbProvider.php, init stops before it writes a file, unless --force. init does not start the front controller to look for a db service: it runs before the project has its autoloader.

Press Enter to accept a proposal. --no-interaction accepts all the proposals (see Global options). --force overwrites an existing crest.php. If the project does not require Crest, init prints the composer require line. Add :dev-master to that line (see Installation).

For an MVC project, init also writes the models key of crest.php (see Configuration). It writes 'camelCase' => false, so the models of the project keep their property names. It also writes 'getSet' => false, so the properties of the models stay public. See Names and Getters and setters.

init asks no question for the view engine. When the views folder, or a folder in it, has a .volt file, init writes 'templateEngine' => 'volt' (see Volt). Else it writes no key, which is phtml.

Navigation

Type to search…

↑↓ navigate↵ selectEsc close