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
Requires
- yiisoft/yii2: ^2.0
This package is not auto-updated.
Last update: 2024-11-09 19:33:33 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:
- Get the data from the field model
- Wrapping wrapper
- Add at the start
EXPLAIN
- Execute sql query
- 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}', ], ]; }