ancor/yii2-code-syntax

Check syntax for some programming languages

Installs: 32

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Type:yii2-extension

dev-master 2016-02-22 18:00 UTC

This package is not auto-updated.

Last update: 2024-05-11 17:01:44 UTC


README

Check code in some programming languages for syntax errors.

Currently supported languages:

Feel free to let me know what else you want added via:

Installation

The preferred way to install this extension is through composer.

Either run

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

or add

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

to the require section of your composer.json file.

Validators

Sql Syntax Validator

Validation occurs as follows:

  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.

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.

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}',
       ],
    ];
}