Simple checker for check expression on correct brackets
- PHP 7.0 or above
- Command line interface
- If you do not have Composer yet, download it and follow the instructions on http://getcomposer.org/ website or simply run the following command:
curl -s https://getcomposer.org/installer | php
- Clone https://github.com/pusachev/brackets-checker.git repository with
git clone https://github.com/pusachev/brackets-checker.git
- Install project dependencies with Composer. If the installation process is too slow, you can use the "--prefer-dist" option. Run composer installation:
php composer.phar install --prefer-dist
For use console command and check expression like "(12 + 5) * 2" please run
php bin/console magekeeper:brackects-checker:check "(12 + 5) * 2"
If by any chance you are not already including the autoload generated by composer, do not forget to add:
require __DIR__ . '/vendor/autoload.php';
Validator example
use MageKeeper\BracketsChecker\Validator\BracketsValidator;
$expression = '(100 - 20) / 2';
/** @var MageKeeper\BracketsChecker\Validator\BracketsValidatorInterface $validator */
$validator = new BracketsValidator();
if($validator->validate($expression)) {
//do something if valid
} else {
//do something if invalid
}
If you need added custom brackets like "#", please usage next method:
/** @var MageKeeper\BracketsChecker\Validator\CustomBracketsInterface $validator */
$validator->addBrackets('#', '#')
For run unit tests please run this command:
php bin/phpunit