Skip to content

Commit 74a2cad

Browse files
committedJun 28, 2018
Updated README.md
1 parent 75974be commit 74a2cad

File tree

1 file changed

+49
-5
lines changed

1 file changed

+49
-5
lines changed
 

Diff for: ‎README.md

+49-5
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
[![Maintainability](https://api.codeclimate.com/v1/badges/a53d266e0050a850e749/maintainability)](https://codeclimate.com/github/ProgMiner/php-datagen/maintainability)
88
[![Total Downloads][ico-downloads]][link-downloads]
99

10-
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.
1311

1412
## Install
1513

@@ -21,9 +19,55 @@ $ composer require progminer/php-datagen
2119

2220
## Usage
2321

24-
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):
50+
```
51+
// Field declaration
52+
[direct] <val/var> <Field name>[: <Type name>[, <Validator names>]][ <:/</>= [`[``]]<Default value>[`[``]]];
53+
```
54+
55+
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.
67+
68+
### Validators
2569

26-
// TODO
70+
*Coming soon...*
2771

2872
## Contributing
2973

0 commit comments

Comments
 (0)