You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PHP-DataGen is a code generation tool with a built-in parser of own Kotlin-like properties description language to create classes with strongly typed properties.
11
-
12
-
The base description of the language is in [schema.md](schema.md).
10
+
The PHP-DataGen project is a utility - code generator of PHP classes with certain properties and is aimed at simplifying the work of PHP programmers.
You can use it from your PHP code or using the CLI.
22
+
The tool has both the ability to control the generation using PHP scripts and the CLI to work with the built-in parser of its own language (hereinafter - PDGL).
23
+
24
+
### CLI
25
+
26
+
```bash
27
+
# General form
28
+
./php-datagen <command>
29
+
30
+
# File compiling
31
+
./php-datagen compile <files>...
32
+
33
+
# Project building (all files compiling)
34
+
./php-datagen build [<project dir>]
35
+
```
36
+
37
+
### PDGL
38
+
39
+
All language-supported statements are provided in the file [schema.md](schema.md) at the root of the project, but without a description of what a particular operator does. The `namespace` and `use` statements works the same as in normal PHP, but the class, fields, and their modifiers are not so simple.
40
+
41
+
Of the modifiers of the class can be identified only one non-standard for PHP the `final` modifier which also has the `final!` variation. The fact is that the result of the work of PHP-DataGen - class, which must be extended by another class to work.
42
+
43
+
The `final` modifier turns the class into a ready-to-use class by removing the prefix (the default, so far, without the possibility of modification, `Data_`) and the `abstract` modifier of the resulting PHP class. The `final!` modifier which "under the hood" is referred to as "final final" is an addition to the `final` modifier (and can not be used without it) and adds to the resulting PHP class the `final` modifier.
44
+
45
+
#### Class field
46
+
47
+
The syntax of class field very little resemblance to the syntax of PHP classes properties and even more, in my opinion, resembles the syntax of class properties Kotlin.
48
+
49
+
Let's start with what is written in the file [schema.md](schema.md):
And now in order (operators are bold, substitutions are italic):
56
+
57
+
-**direct** - modifier. If exists, allows the extending class to access properties directly (sets the `protected` access modifier instead of `private`);
58
+
-**val** or **var** is a field declaration operator. If **val** is used, the property is not editable after setting in the constructor, if **var** is editable;
59
+
-*Field name* - the name of the field, specified without the PHP-specific dollar sign (`$`);
60
+
-**:** - optional colon operator to specify the field type. If not specified, the field type is considered `mixed`;
61
+
-*Type name* - type name. It can be one of the standard PHP types (case-insensitive) or a class name. If it ends with a question sign (for example, `string?`) then the field as well can store `null` value;
62
+
-**,** - optional comma operator allows you to specify the validator name after the type (or validator) name;
63
+
-*Validator name* - name of validator (see next section);
64
+
-**<=**, **:=** or **=** - default value assignment operator. In variation **<=** assigns a value when declaring a property. In variation **:=** assigns a value when the constructor is called without checking the type and calling validators. In variation **=** assigns a value when calling a constructor with type checking and calling validators;
65
+
-**`** or **```** - see *Default value*;
66
+
-*Default value* - the default value of the field. It can be surrounded by **`** or **```** operators when contains a semicolon (`;`) (except when a variation of the default value assignment operator **<=** is used). There is no difference in the use of **`** or **```** if the default value is not contains a reverse apostrophe (```), in which case you must use the **```** operator.
0 commit comments