-
Notifications
You must be signed in to change notification settings - Fork 2
Console Commands
This command generates Transfer Objects based on the configuration file in YML format.
$ ./vendor/bin/transfer-generate [-c|--configuration CONFIGURATION]
With the verbosity option -v
command shows generated transfer object names.
The Transfer Object Generator command requires a path to a YML configuration file.
Below is a configuration file example:
generator:
transferNamespace: "Picamator\\TransferObject\\Generated"
transferPath: "${PROJECT_ROOT}/transfer-object/src/TransferObject/Generated"
definitionPath: "${PROJECT_ROOT}/transfer-object/config/definition"
Where ${PROJECT_ROOT}
replaced automatically with project root path.
The project root path is resolved as:
- use environment variable
PROJECT_ROOT
- when the environment variable is not set use the current working directory getcwd().
In order to use schema please add on the top of the configuratiton file the following:
# $schema: https://raw.githubusercontent.com/picamator/transfer-object/main/schema/config.schema.json
Key Name | Description |
---|---|
generator |
The root configuration element. |
transferNamespace |
The namespace for the generated Transfer Objects (TOs). |
transferPath |
The path where the generated TOs will be saved. |
definitionPath |
The path where the TO definitions are located. |
-
generator
: This is the root element of the configuration file. It groups all configuration options related to the Transfer Object Generator. -
transferNamespace
: Specifies the namespace under which the generated Transfer Objects will be organized. This should follow the PHP namespace convention. -
transferPath
: Defines the file system path where the generated Transfer Object classes will be stored. -
definitionPath
: Indicates the directory path where the Transfer Object definition files are located. These definition files are used by the generator to create the corresponding Transfer Objects.
This command generates Transfer Objects from definition files specified by multiple configuration files listed in a TXT file.
$ ./vendor/bin/transfer-generate-bulk [-b|--bulk BULK]
The bulk option requires the path to the TXT files, each line of which contains the path to an individual Transfer Object configuration.
config/generator.config.yml
examples/config/advanced-transfer-generator/generator.config.yml
examples/config/definition-generator/generator.config.yml
examples/config/transfer-generator/generator.config.yml
The bulk file can be generated by the shell command:
$ find . -type f -name "*.config.yml" > ./var/config/config.list.txt
Where "*.config.yml"
is a configuration file pattern.
This command generates Transfer Object definition files based on a JSON file as a blueprint.
$ ./vendor/bin/definition-generate
The defintion generator command builds definition files based on JSON file. The JSON file is e.g. API response or payload. The command includes following input questions to initiate generator.
Input Question | Description |
---|---|
Definition directory path |
Relative, from the project directory, a path where the generated definition file should be saved. |
Transfer Object class name |
What is the root Transfer Object name. |
JSON local path or url |
Relative, from the project directory, the path to the JSON file or url. |