vog

php code generator for immutable value objects

View the Project on GitHub MarvinWank/vog

Definition file

The definitions of the objects to be generated by vog stored in a file in json format. On the root level of the value file, you have to provide the full path to your projects root with the key root_path. No / is necessary at the end

Example:

{
  "root_path": "/home/example_user/example_project/src",
  "namespace": "",
  "models/values": [
    {
      "type": "enum",
      "name": "DietStyle",
      "values": {
        "EVERYTHING": "everything",
        "VEGETARIAN": "vegetarian",
        "VEGAN": "vegan"
      }
    }
  ]
}

As you can see in the example, the value file also has an array at the top level, with the key of it being a path. In this array, an Enum with the name of “DietStyle” is given. When generated, its full path will be root_path + <key of the path array> + name + .php, so in this example

/home/example_user/example_project/src/models/values/DietStyle.php

Its namespace will be automatically generated from the path specification according to PSR, so if no or an empty namespace is provided on the root level, as in this case, it would be Models\Values.

If you set for example "namespace": "Vog\Lib" as your root_path the result would be Vog\Lib\Models\Values.

Any number of objects may be defined in each path array and any number of path arrays may be given in the value file.

Example

The following definition file will result in the following file structure:

{
  "root_path": "/home/example_user/awesome_app/src",
  "namespace": "AwesomeApp",
  "api/dtos": [
    {
      "name": "DietStyle",
      "type": "enum",
      "values": {
        "EVERYTHING": "everything",
        "VEGETARIAN": "vegetarian",
        "VEGAN": "vegan"
      }
    },
    {
      "type": "valueObject",
      "name": "Recipe",
      "values": {
        "title": "string",
        "minutes_to_prepare": "?int",
        "rating": "float",
        "diet_style": "DietStyle"
      },
      "string_value": "title"
    }
  ],
  "": [
    {
      "name": "AppConfig",
      "type": "valueObject",
      "values": {
        "AppId": "int",
        "logLevel": "?string",
        "isProd": "boolean"
      }
    }
  ]
}
.					 		# /home/example_user/awesome_app/src/
|          
├── Api 		 	 		# Namespace AwesomeApp\Api\
│   └── dtos
│	│	- DietStyle.php     # Generated by vog, namespace AwesomeApp\Api\Dtos
│   │   - Recipe.php      
│
│── vendor
│   └── bin
│       - vog.php           # vog executable
│
├── vog_config.php          # vog config must be located in same directory as vendor
├── value.json              # vog definition file

generic properties

These properties of the json-Object are either available or required for alle data types

name data type default optionality description
type string - required for all defines the type of object to be generated. valid types are ‘enum’, ‘nullableEnum’, ‘valueObject’ and ‘set’
name string - required for all defines both the php class name and file name of the value object to be generated
values object - required for all except set defines the values to be represented by the value object to be generated. Syntax and effect vary by type.
extends ?string ”” optional Optionally states the name of the class this object should extend
implements array [] optional Optionally states the name(s) of the interface(s) this object should implement
mutable bool false optional for value objects Optionally states the mutability of the object. If so, the object will have setters.
dateTimeFormat string global value optional for value objects Optionally defines an object-specific DateTime-Format