-
Notifications
You must be signed in to change notification settings - Fork 0
Console
Prime provides some utility commands, using symfony/console library. To use it, you should register commands from namespace
Prime\Console, or directly use b2pweb/bdf-prime-bundle.
Without parameter it will show caches states (enabled or disabled).
With --clear or -c option, caches will be cleared.
Creates configured databases if not exists. Only SQL database handled by a doctrine connection are created by this command. A custom admin user and password can be set for create the database.
Options:
| Name | Shortcut | Description | Default value |
|---|---|---|---|
--connection |
none | Define the connection name (optional). If not set, all connections will be used. | none |
--user |
-u |
Define admin username for create the database. | "root" |
--password |
-p |
Define admin password for create the database. | "" |
Note: Database access will not be granted to configured user.
Drop (remove) a database. Only SQL database handled by a doctrine connection are created by this command. A custom admin user and password can be set for create the database.
Options:
| Name | Shortcut | Description | Default value |
|---|---|---|---|
--connection |
none | Define the connection name (optional). If not set, all connections will be used. | none |
--user |
-u |
Define admin username for create the database. | "root" |
--password |
-p |
Define admin password for create the database. | "" |
--force |
-f |
If set, no confirmation will be asked to user. | none |
Generates the entity class from mapper configuration.
The created entity will inherit from Bdf\Prime\Entity\Model and implements Bdf\Prime\Entity\InitializableInterface.
A property will be declared for each database field, and attached relation. A getter and setter will be defined for each property,
and also an "adder" method for array properties. Property which needs an initialisation (i.e. embedded and DateTime) will be set on InitializableInterface::initialize() method.
By default, all properties will use PHP 7.4 typed property (add a typehint and also a default value to null),
and in PHP >= 8.0 promoted properties will be used instead of an array parameter at constructor.
If the entity class already exists, it will be updated (i.e. new properties and methods will be added).
A backup of the previous class can be done by using option --backup or -b, which will copy file with .bak suffix.
This command takes at parameter a directory or file path to mappers. If a directory is given, it will be iterated recursively for resolve mapper classes.
Once a mapper is found, prompts will appear for configure generation.
If the entity class already exists, the prompt "'$fileName' exists. what do you want ?" will be displayed first with choices:
- Regenerate: will replace the existing entity : do not update entity
- Update: will complete entity with new properties and methods : add new properties and methods to entity. Let unchanged existent ones.
- Cancel do not change the entity class, and skip it
After that (or if the class do not exist), ask for configuration :
-
Auto+create : recommended choice. Will use default configuration (inherit from
Modeland implementsInitializableInterface), write class, and continue to next entity generation. - Auto : Simply configure generator with default configuration, but do not write the class.
- Create : Write class file following defined configuration, and continue to next entity generation.
- Show : Show code which will be generated.
- Extends class : Define the inherited class name. Must be a fully qualified class name.
- Implements interface : Define implemented interfaces.
- Extensions : Define used traits.
-
Enable/disable get method shortcut : Disable (or re-enable) usage of short name getter methods (i.e. without
getprefix). -
Change field visibility : Switch to
privateorprotectedvisibility on field (protectedby default). - Enable/disable typed properties (PHP >= 7.4 only) : Switch usage of typed properties.
-
Enable/disable promoted properties on constructor (PHP >= 8.0 only) : Switch usage of promoted properties on constructor in replacement of single
arrayargument. - Skip : Skip generation of this class, and continue to next entity generation.
Shows a graph representation of mappers using Graphviz. Use doctrine schema visitor. Takes as parameter the path of mappers.
Options:
| Name | Shortcut | Description | Default value |
|---|---|---|---|
--output |
-o |
(required) Output file name. | none |
--fromdb |
non | If defined, load schema from database instead of mappers. | none |
Generate optimised hydrators for entities. Takes as argument the entity directory to iterate for generates hydrators.
Once generated, the loader file can be included for populate the instance of HydratorRegistry, defined into a $registry variable.
When using b2pweb/bdf-prime-bundle, file configured on prime.hydrators will be automatically used as loader.
Note: If then entity use polymorphic or custom relations, the hydrator generation will be skipped.
Options:
| Name | Shortcut | Description | Default value |
|---|---|---|---|
--loader |
-l |
(required) Output file name. Directory of this file will be use as output directory for generated hydrators. | none |
--include |
-i |
If defined, add include statements on loader file to skip autoloader. |
none |
Generates mapper classes from a database schema. Class name will be resolved from table name, and properties names from columns names.
Note: The generated class will not be set into a namespace. You must review generated code before using it.
Options:
| Name | Shortcut | Description | Default value |
|---|---|---|---|
--table |
-t |
(required) Table name to parse. | none |
--connection |
-c |
(required) Database connection to use. | none |
--output |
-o |
(required) Path to output directory. | none |
Execute arbitrary SQL query.
Adapter of the dbal:run-sql command of doctrine.
Update database schema according to mappers. Schema upgrade is generally safe, and will not cause data loose. The command takes as argument the mapper directory path. This directory will be iterated recursively.
Note: schema upgrade can detect et migrate column rename if, and only if, only one column (the renamed one) is changed and all its configuration are identically (i.e. type and flags).
But it's strongly discouraged to rename a field. Prefer duplicate the field and perform a manual migration of data on it, or simply use an alias.
Options:
| Name | Shortcut | Description | Default value |
|---|---|---|---|
--execute |
none | If defined, execute migration queries. | none |
--userDrop |
none | If defined, drop undeclared columns. | none |
--force |
none | If defined, force migration of mapper with disabled schema manager. This is strongly discouraged. | none |