Giter Site home page Giter Site logo

progminer / php-datagen Goto Github PK

View Code? Open in Web Editor NEW
6.0 5.0 0.0 346 KB

Code generator for making data classes on PHP

Home Page: https://packagist.org/packages/progminer/php-datagen

License: MIT License

PHP 90.49% Lex 2.40% Yacc 7.11%
php code-generator data-class php-tools

php-datagen's Introduction

php-datagen

DEVELOP OF THIS PROJECT IS CURRENTLY STOPPED

Latest Version on Packagist Software License Build Status Codacy Badge Maintainability Total Downloads

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.

The article about this project is available on Russian language at https://habr.com/post/415861/.

Install

Via Composer

$ composer require progminer/php-datagen

Usage

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).

CLI

# General form
./php-datagen <command>

# File compiling
./php-datagen compile <files>...

# Project building (all files compiling)
./php-datagen build [<project dir>]

PDGL

All language-supported statements are provided in the file 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.

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.

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.

Class field

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.

Let's start with what is written in the file schema.md:

// Field declaration
[direct] <val/var> <Field name>[: <Type name>[, <Validator names>]][ <:/</>= [`[``]]<Default value>[`[``]]];

And now in order (operators are bold, substitutions are italic):

  • direct - modifier. If exists, allows the extending class to access properties directly (sets the protected access modifier instead of private);
  • 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;
  • Field name - the name of the field, specified without the PHP-specific dollar sign ($);
  • : - optional colon operator to specify the field type. If not specified, the field type is considered mixed;
  • 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;
  • , - optional comma operator allows you to specify the validator name after the type (or validator) name;
  • Validator name - name of validator (see next section);
  • <=, := 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;
  • ` or ``` - see Default value;
  • 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.

Validators

Coming soon...

Examples

PDGL PHP
app/Type.pdata app/Data_Type.php
app/Model/FieldModel.pdata app/Model/FieldModel.php
tests/Test.pdata tests/Data_Test.php

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

php-datagen's People

Contributors

progminer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.