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 initinit 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:
-
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\Apiunder"App\\": "src/"is). The other proposals follow the answer: its folder is the psr-4 folder of the longest prefix, for examplesrc/Api. -
The flavor:
mvcoradr. For each flavor,initcounts the default folders of that flavor (item 4) that the project has. It proposes the flavor with the most. A tie givesmvc. A project withsrc/Controllers,src/Providersandthemes/vokurogetsmvc.--flavoranswers the question. -
The front controller:
<namespace>\AppFrontwhenAppFront.phpis in the folder of the namespace. Answernonefor no front controller. -
A folder for each path of the flavor (the
pathskey ofcrest.php; see Configuration). The MVC paths arecommand,controller,form,model,module,providerandviews. The ADR paths areaction,command,middleware,provider,repositoryandresponder. 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-actionsgivesApp\my-actions, which PHP cannot use.initremoves a leading./.viewsholds 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. Thusinitrefuses an absolute folder, an empty part (//),.and... The proposal isthemes/default. When that folder does not exist andthemes/has one folder only,initproposes that folder (themes/vokuroin vokuro). The answernoneis a project with no views:initwrites'views' => false(see The MVC project). -
The runtime (see The runtime). The proposal is docker when the project has
compose.yaml,compose.yml,docker-compose.yamlordocker-compose.yml. For docker,initalso asks for the service. The proposal isapp, or the first service. -
The database:
none,mariadb,mysql,pgsqlorsqlite. The proposal isnone.--databaseanswers the question. For another answer,initadds the database after it writescrest.php, asmake:databasedoes (see Adding a database). When theproviderfolder already hasDbProvider.php,initstops before it writes a file, unless--force.initdoes not start the front controller to look for adbservice: 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.