2017 © Pedro Peláez
 

yii2-extension yii2-code-syntax

Check syntax for some programming languages

image

ancor/yii2-code-syntax

Check syntax for some programming languages

  • Monday, February 22, 2016
  • by ancor.dev
  • Repository
  • 1 Watchers
  • 0 Stars
  • 21 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Code Syntax validators for Yii 2

Check code in some programming languages for syntax errors., (*1)

Currently supported languages: - php - sql - json, (*2)

Feel free to let me know what else you want added via:, (*3)

Installation

The preferred way to install this extension is through composer., (*4)

Either run, (*5)

$ php composer.phar require ancor/yii2-code-syntax

or add, (*6)

"ancor/yii2-code-syntax": "dev-master"

to the require section of your composer.json file., (*7)

Validators

Sql Syntax Validator

Validation occurs as follows:, (*8)

  1. Get the data from the field model
  2. Wrapping wrapper
  3. Add at the start EXPLAIN
  4. Execute sql query
  5. If the returned error, add this errors to validation message
Basic usage
use ancor\codeSyntax\SqlSyntaxValidator;
public function rules()
{
    return [
        [['sqlCodeField'], SqlSyntaxValidator::className()],
    ];
}
Advanced usage with options
use ancor\codeSyntax\SqlSyntaxValidator;
public function rules()
{
    return [
        [
            ['sqlCodeField'],
            SqlSyntaxValidator::className(),
            // 'wrapper' => '...{{part}}...',
            // 'makeSql' => function($validator, $partSql) { ... }
            'message' => 'Field {attribute} is invalid',
        ],
    ];
}

Php Syntax Validator

Warning: this validator use php cli. And if php has been not added to $PATH, validator will not work., (*9)

Basic usage
use ancor\codeSyntax\PhpSyntaxValidator;

public function rules()
{
    return [
       [['phpCodeField'], PhpSyntaxValidator::className()],
    ];
}
Advanced usage with options
use ancor\codeSyntax\PhpSyntaxValidator;

public function rules()
{
    return [
       [
           ['phpCodeField'],
           PhpSyntaxValidator::className(),
           'isWrapPhp' => true,
           'message' => 'Field {attribute} is invalid',
       ],
    ];
}

Json Syntax Validator

Warning: this validator use json_decode() php function. And depends on php-json extension., (*10)

Basic usage
use ancor\codeSyntax\JsonSyntaxValidator;

public function rules()
{
    return [
       [['jsonCodeField'], JsonSyntaxValidator::className()],
    ];
}
Advanced usage with options
use ancor\codeSyntax\JsonSyntaxValidator;

public function rules()
{
    return [
       [
           ['jsonCodeField'],
           JsonSyntaxValidator::className(),
           'message' => 'Field {attribute} has invalid json. Code: {errCode}, Msg: {errMsg}',
       ],
    ];
}

The Versions

22/02 2016

dev-master

9999999-dev

Check syntax for some programming languages

  Sources   Download

GPLv3

The Requires

 

by Anton Korniychuk