The make command
make creates component skeletons from templates: controllers, services,
repositories, entities, middleware, jobs, commands. Each flag adds one type; the
flags combine to generate several files at once.
What make is and why
make is a template-driven code generator.
The problem. Every new component is the same scaffolding: a namespace, a stereotype, a base class, a method stub. Writing it by hand is drudgery and a source of typos.
The solution. State the name and the type as a flag — make takes the template,
substitutes the namespace and the class name, puts the file in the right folder under
a PSR-4 root and hooks it into the autoloader. That is what this page is about.
Syntax
call make <dot.notation.Name> -[flags] [--mvc]The first argument is a path in dot notation ending with a class name. The flags pick
which types to generate. The type’s suffix (Controller, Service…) is added by
the generator itself:
php call make -c .User # → UserController (not .UserController!)
php call make -s .User # → UserService
php call make -r .User # → UserRepositoryDot notation → path
Dots in the name become folders; the root is the matching PSR-4 prefix:
| Input | Where it lands |
|---|---|
.User |
The application’s first PSR-4 root (with a smart folder search) |
api.user.Profile |
<root>/Api/User/ProfileController.php |
acme.app.http.User |
The longest matching PSR-4 prefix |
If the path is empty (.Name), make puts the file into the first existing subfolder
(Controllers/, then Controller/, otherwise alongside by namespace). The --mvc
option forces a category folder to be added.
Flags
One flag, one component. Each appends its own suffix to the name so that the class
name reads by itself: make -c .User gives UserController.
HTTP
| Flag | Component | Suffix |
|---|---|---|
-c |
Controller | Controller |
-m |
Middleware | Middleware |
Data
| Flag | Component | Suffix |
|---|---|---|
-e |
Entity | — |
-d |
DTO | Dto |
Business layer
| Flag | Component | Suffix |
|---|---|---|
-s |
Service | Service |
-r |
Repository | Repository |
-t |
Store | Store |
Background components
| Flag | Component | Suffix |
|---|---|---|
-P |
Process | Process |
-N |
Daemon | Daemon |
Configuration and console
| Flag | Component | Suffix |
|---|---|---|
-D |
Database configuration | DbConfig |
-R |
Redis configuration | RedisConfig |
-n |
A command of your own | — |
Combining flags
Several flags on one name generate a set of related files at once:
php call make -csre .User # Controller + Service + Repository + Entity
php call make -csre .Order --mvc # the same, but into Controllers/ Services/ ...The --mvc option
It wraps the path in a category folder chosen by component type: Controllers/,
Services/, Middlewares/, Repositories/, Entities/, Dto/, Processes/,
Commands/, and Utils/ for everything else.
Without the option the file goes where you named it, and into a directory with the customary name if one already exists.
Examples
php call make -c api.user.Profile # → Api/User/ProfileController.php
php call make -P .Import # a process in Processes/, if the directory exists
php call make -n .MySync # a console command of your own (Cmd)
php call make -cs .User .Order .Item # several names at onceExisting files are never overwritten
make never clobbers a file — an existing one is marked [EXISTS] rather than
[CREATED]. Your code is safe.
Next
- Console — overview — the anatomy of a command
- script — running your own commands (
-n) - Controllers — what the
-cflag generates