Class: ModelTask
Full name: Azera\Cli\Tasks\ModelTask
CLI task for synchronising PHP model properties from the database schema (DB→PHP) and for scaffolding new model files from database tables.
Usage:
model:sync-all [
model:list [
The model:sync accepts:
- A file path: src/Models/User.php ↰
- A short class name: User (discovered via PSR-4 / --directory) ↰
- A fully-qualified name: App\Models\User
By default the task only reports changes. Pass --apply to write the updated model files to disk.
Options:
--apply Apply changes to files instead of just
reporting them
--create-missing Create new model files for tables that don't
have a corresponding model yet
--database=model:sync (optional)
--field-visibility=
Examples: model:sync-all # auto-discover App\Models model:sync-all src/Models # dry-run model:sync-all src/Models --apply # apply model:sync-all src/Models --apply --generate-accessors # with accessors model:sync-all src/Models --apply --field-visibility=protected model:sync-all src/Models --apply --no-deprecate model:sync-all src/Models --apply --create-missing --namespace=App\Models model:sync src/Models/User.php --apply # file path model:sync User --apply # short class name (PSR-4) model:sync App\Models\User --apply # fully-qualified name model:sync User --directory=src/Models --apply # with directory hint model:new User # auto-discover App\Models dir model:new User src/Models --namespace=App\Models --apply model:list # list all models + tables model:list src/Models --missing # also show uncovered tables
Public Properties
publicConsole$console·publicarray$options·
Public methods
listAction() ·
public function listAction(string $dir = ''): void
List all model files in a directory together with their mapped database table. With --missing, also list database tables that have no corresponding model file yet.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$dir |
string | '' |
Directory to scan (optional – defaults to App\Models via PSR-4) |
Return value
- Type:
void
syncAllAction() ·
public function syncAllAction(string $dir = ''): void
Scan a directory recursively, find all PHP files that extend Model, and sync each one against the database.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$dir |
string | '' |
Directory to scan (optional – defaults to App\Models via PSR-4) |
Return value
- Type:
void
syncAction() ·
public function syncAction(string $file = ''): void
Sync a single model against the database.
The argument may be a file path, a short class name, or a fully-qualified class name. Short and qualified class names are resolved to file paths via the PSR-4 autoloading map. Use --directory=
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$file |
string | '' |
File path, short class name, or fully-qualified class name (required) |
Return value
- Type:
void
newAction() ·
public function newAction(string $className = '', string $dir = ''): void
Scaffold a new model class from a database table and immediately sync its properties.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$className |
string | '' |
Short class name without namespace (e.g. User) |
$dir |
string | '' |
Target directory for the new file (optional – defaults to App\Models via PSR-4) |
Return value
- Type:
void