├── .editorconfig ├── .rmt.yml ├── .styleci.yml ├── CHANGELOG ├── CONTRIBUTING.md ├── Command └── CacheClearCommand.php ├── DependencyInjection ├── Compiler │ ├── OperatorsPass.php │ └── TargetsPass.php ├── Configuration.php └── KPhoenRulerZExtension.php ├── KPhoenRulerZBundle.php ├── LICENSE ├── Makefile ├── Resources └── config │ ├── debug.yml │ ├── forms.yml │ ├── rulerz.yml │ ├── targets │ ├── doctrine.yml │ ├── doctrine_dbal.yml │ ├── elasticsearch.yml │ ├── eloquent.yml │ ├── native.yml │ ├── pomm.yml │ └── solarium.yml │ └── validators.yml └── composer.json /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = LF 6 | indent_style = space 7 | indent_size = 4 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | -------------------------------------------------------------------------------- /.rmt.yml: -------------------------------------------------------------------------------- 1 | _default: 2 | 3 | # VCS CONFIG 4 | vcs: git 5 | 6 | # PREREQUISITES 7 | # Actions executed before any questions get asked to the user. 8 | # Custom action can be added by provided a relative path the the php script. Example: 9 | # - relative/path/to/your-own-sript.php 10 | prerequisites: 11 | working-copy-check: ~ 12 | display-last-changes: ~ 13 | tests-check: 14 | command: ./vendor/bin/phpunit 15 | 16 | # GENERAL CONFIG 17 | # Apply to all branches except the one from the 'branch-specific' section 18 | # Like prerequisites, you can add your own script. Example: 19 | # - relative/path/to/your-own-sript.php 20 | version-generator: simple # Simple versionning 21 | version-persister: 22 | vcs-tag: # Release with VCS tag 23 | tag-prefix: "{branch-name}_" # Prefix any tag with the VCS branch name 24 | post-release-actions: 25 | vcs-publish: # Publish the release to the VCS 26 | ask-confirmation: true 27 | 28 | # BRANCH SPECIFIC CONFIG 29 | # On master, we override the general config 30 | master: 31 | version-generator: semantic # More complex versionning (semantic) 32 | version-persister: 33 | vcs-tag: 34 | tag-prefix: '' # No more prefix for tags 35 | pre-release-actions: 36 | changelog-update: # Update a CHANGELOG file before the release 37 | format: semantic 38 | dump-commits: true 39 | vcs-commit: ~ # Commit the CHANGELOG 40 | -------------------------------------------------------------------------------- /.styleci.yml: -------------------------------------------------------------------------------- 1 | preset: symfony 2 | 3 | disabled: 4 | - phpdoc_annotation_without_dot 5 | - no_blank_lines_between_imports 6 | - phpdoc_align 7 | - phpdoc_no_empty_return 8 | - phpdoc_summary 9 | -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | 2 | VERSION 0 CHANGE OPERATORS DEFINITION, ACCORDING TO COMPILATION TARGETS REFINEMENTS DONE IN RULERZ 3 | =================================================================================================== 4 | 5 | Version 0.15 - Add support for SF 4 and require PHP >= 7.1 6 | 17/09/2018 11:02 0.15.0 initial release 7 | 85ca063 Remove useless config element from phpunit.xml.dist 8 | 8336db1 Fix version constraint on mikey179/vfsStream 9 | 012ddc7 Add a few declare() and typehints 10 | 0eeedf5 Explicitely declare the cache clear command 11 | b033819 Drop symfony 2.8 support and require PHP >= 7.1 12 | 2746094 Merge pull request #18 from marclenderink/sf4-compatibility 13 | 74bf6e9 Modified dependencies to allow SF4 components 14 | 15 | Version 0.14 - Use the bridge 16 | 22/10/2017 16:37 0.14.1 Restore support for doctrine_dbal 17 | 5802ec2 Add a "release" target in the makefile 18 | a5ac6cc Merge pull request #16 from dzikismigol/patch-1 19 | f628f2a Add OOB support for doctrine_dbal target 20 | 25/09/2017 20:58 0.14.0 initial release 21 | 675a43d Merge pull request #15 from K-Phoen/bridge 22 | de15037 Simplify some tests 23 | f71bb04 Update tests setup 24 | 2e225dd Require kphoen/rulerz-bridge ^1.0 25 | 6034486 Fix a little style violation 26 | 88957e8 Removed unused 'use' statements 27 | 78f84c7 Write quotes around parameters in the readme 28 | 50ff396 Update travis config 29 | 3bc007c Require at least symfony 2.8 30 | 697c3e9 Use the validator components from the bridge 31 | 17cd987 Automatically enable the form extension 32 | 6077920 Also require rulerz-bridge 33 | 34 | Version 0.13 - Change operators definition, according to compilation targets refinements done in RulerZ 35 | 23/09/2017 15:58 0.13.2 Fix debug configuration parsing 36 | 6d419b2 Fix tests 37 | 70551d6 Do not test against hhvm anymore 38 | 3e626ef Fix default value definition for the debug configuration option 39 | 12eab8b Merge pull request #13 from iainmckay/bug/reference-to-compilation-target 40 | 74a0d7f Fixed reference to compilation_target 41 | 21/02/2017 11:04 0.13.1 Fix elastica target service definition 42 | b34f719 Merge pull request #12 from nextima/master 43 | 925bad3 Update elastica.yml 44 | 05/02/2017 16:55 0.13.0 initial release 45 | 71aa493 Simplify operator definition 46 | ec1652c Rename rulerz.compilation_target tag to rulerz.target 47 | 4183ef2 Add editorconfig 48 | a40f373 Rename executors to targets 49 | dfd598c Add RMT config 50 | 12d1452 Merge pull request #11 from K-Phoen/analysis-z3Wjbp 51 | 5b76b6b Apply fixes from StyleCI 52 | d513936 Test against PHP 7.0 in priority 53 | c15e672 Add styleci config 54 | 7cf1835 Use the right parser in tests 55 | 3cfc720 Require rulerz >= 0.19.3 56 | 9d4f88e Merge pull request #8 from jdeniau/master 57 | 28c0135 setOperator => defineOperator 58 | 3d07954 Start to update the bundle for the future rulerz release -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing 2 | ============ 3 | 4 | First of all, **thank you** for contributing, **you are awesome**! 5 | 6 | Here are a few rules to follow in order to ease code reviews, and discussions before 7 | maintainers accept and merge your work. 8 | 9 | You MUST follow the [PSR-1](http://www.php-fig.org/psr/1/) and 10 | [PSR-2](http://www.php-fig.org/psr/2/). If you don't know about any of them, you 11 | should really read the recommendations. Can't wait? Use the [PHP-CS-Fixer 12 | tool](http://cs.sensiolabs.org/). 13 | 14 | You MUST run the test suite. 15 | 16 | You MUST write (or update) unit tests. 17 | 18 | You SHOULD write documentation. 19 | 20 | Please, write [commit messages that make 21 | sense](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html), 22 | and [rebase your branch](http://git-scm.com/book/en/Git-Branching-Rebasing) 23 | before submitting your Pull Request. 24 | 25 | One may ask you to [squash your 26 | commits](http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html) 27 | too. This is used to "clean" your Pull Request before merging it (we don't want 28 | commits such as `fix tests`, `fix 2`, `fix 3`, etc.). 29 | 30 | Thank you! 31 | 32 | ## Running the test suite 33 | 34 | Ensure that the required vendors are installed by running `composer install`. 35 | 36 | Run the tests with the `./vendor/bin/phpunit` command. 37 | -------------------------------------------------------------------------------- /Command/CacheClearCommand.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | class CacheClearCommand extends ContainerAwareCommand 17 | { 18 | /** 19 | * {@inheritdoc} 20 | */ 21 | protected function configure() 22 | { 23 | $this 24 | ->setName('rulerz:cache:clear') 25 | ->setDescription("Clear RulerZ's cache") 26 | ; 27 | } 28 | 29 | /** 30 | * {@inheritdoc} 31 | */ 32 | protected function execute(InputInterface $input, OutputInterface $output) 33 | { 34 | $cacheDir = $this->getContainer()->getParameter('rulerz.cache_directory'); 35 | $filesystem = $this->getContainer()->get('filesystem'); 36 | 37 | if (!is_writable($cacheDir)) { 38 | throw new \RuntimeException(sprintf('Unable to write in the "%s" directory', $cacheDir)); 39 | } 40 | 41 | if ($filesystem->exists($cacheDir)) { 42 | $filesystem->remove($cacheDir); 43 | $filesystem->mkdir($cacheDir); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /DependencyInjection/Compiler/OperatorsPass.php: -------------------------------------------------------------------------------- 1 | findTaggedServiceIds('rulerz.operator') as $id => $attributesSet) { 16 | foreach ($attributesSet as $attributes) { 17 | if ($container->hasDefinition($target = 'rulerz.target.'.$attributes['target'])) { 18 | $targetDefinition = $container->getDefinition($target); 19 | } elseif ($container->hasDefinition($attributes['target'])) { 20 | $targetDefinition = $container->getDefinition($attributes['target']); 21 | } else { 22 | throw new \LogicException('Unable to find service definition for compilation target: '.$attributes['target']); 23 | } 24 | 25 | if (!empty($attributes['inline']) && $attributes['inline']) { 26 | $targetDefinition->addMethodCall('defineInlineOperator', [ 27 | $attributes['operator'], new Reference($id), 28 | ]); 29 | } else { 30 | $targetDefinition->addMethodCall('defineOperator', [ 31 | $attributes['operator'], new Reference($id), 32 | ]); 33 | } 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /DependencyInjection/Compiler/TargetsPass.php: -------------------------------------------------------------------------------- 1 | getDefinition('rulerz'); 16 | 17 | foreach ($container->findTaggedServiceIds('rulerz.target') as $id => $attributes) { 18 | $targetDefinition = $container->getDefinition($id); 19 | 20 | if (!class_exists($targetDefinition->getClass())) { 21 | throw new \RuntimeException(sprintf('Class not found for target "%s". Did you require the target\'s library?', $id)); 22 | } 23 | 24 | $engineDefinition->addMethodCall('registerCompilationTarget', [new Reference($id)]); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /DependencyInjection/Configuration.php: -------------------------------------------------------------------------------- 1 | debug = $debug; 18 | } 19 | 20 | public function getConfigTreeBuilder() 21 | { 22 | $treeBuilder = new TreeBuilder(); 23 | $rootNode = $treeBuilder->root('rulerz'); 24 | 25 | $this->addCacheConfig($rootNode); 26 | $this->addDebugConfig($rootNode); 27 | $this->addTargetsConfig($rootNode); 28 | 29 | return $treeBuilder; 30 | } 31 | 32 | private function addCacheConfig(ArrayNodeDefinition $rootNode): ArrayNodeDefinition 33 | { 34 | $rootNode 35 | ->children() 36 | ->scalarNode('cache')->defaultValue('%kernel.cache_dir%/rulerz')->end() 37 | ->end(); 38 | 39 | return $rootNode; 40 | } 41 | 42 | private function addDebugConfig(ArrayNodeDefinition $rootNode): ArrayNodeDefinition 43 | { 44 | $rootNode 45 | ->children() 46 | ->booleanNode('debug')->defaultValue($this->debug)->end() 47 | ->end(); 48 | 49 | return $rootNode; 50 | } 51 | 52 | private function addTargetsConfig(ArrayNodeDefinition $rootNode): ArrayNodeDefinition 53 | { 54 | $targetsNode = $rootNode 55 | ->children() 56 | ->arrayNode('targets') 57 | ->addDefaultsIfNotSet() 58 | ->children(); 59 | 60 | foreach (KPhoenRulerZExtension::SUPPORTED_TARGETS as $target => $defaultState) { 61 | $targetsNode = $targetsNode->booleanNode($target)->defaultValue($defaultState)->end(); 62 | } 63 | 64 | $targetsNode 65 | ->end() 66 | ->end() 67 | ->end(); 68 | 69 | return $rootNode; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /DependencyInjection/KPhoenRulerZExtension.php: -------------------------------------------------------------------------------- 1 | true, // enabled by default 16 | 'doctrine' => false, 17 | 'doctrine_dbal' => false, 18 | 'eloquent' => false, 19 | 'pomm' => false, 20 | 'solarium' => false, 21 | 'elasticsearch' => false, 22 | ]; 23 | 24 | public function load(array $configs, ContainerBuilder $container) 25 | { 26 | $config = $this->processConfiguration($this->getConfiguration($configs, $container), $configs); 27 | 28 | $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); 29 | $loader->load('rulerz.yml'); 30 | $loader->load('forms.yml'); 31 | $loader->load('validators.yml'); 32 | 33 | if ($config['debug']) { 34 | $loader->load('debug.yml'); 35 | } 36 | 37 | $this->configureCache($container, $config); 38 | $this->configureTargets($loader, $config); 39 | } 40 | 41 | private function configureCache(ContainerBuilder $container, array $config): void 42 | { 43 | $directory = $container->getParameterBag()->resolveValue($config['cache']); 44 | $container->setParameter('rulerz.cache_directory', $directory); 45 | 46 | if (!file_exists($directory) && !@mkdir($directory, 0777, true)) { 47 | throw new \RuntimeException(sprintf('Could not create cache directory "%s".', $directory)); 48 | } 49 | } 50 | 51 | private function configureTargets(YamlFileLoader $loader, array $config): void 52 | { 53 | foreach (array_keys(self::SUPPORTED_TARGETS) as $target) { 54 | if ($config['targets'][$target]) { 55 | $loader->load(sprintf('targets/%s.yml', $target)); 56 | } 57 | } 58 | } 59 | 60 | public function getConfiguration(array $config, ContainerBuilder $container): Configuration 61 | { 62 | return new Configuration($container->getParameter('kernel.debug')); 63 | } 64 | 65 | /** 66 | * {@inheritdoc} 67 | */ 68 | public function getAlias(): string 69 | { 70 | return 'rulerz'; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /KPhoenRulerZBundle.php: -------------------------------------------------------------------------------- 1 | addCompilerPass(new Compiler\TargetsPass()); 19 | $container->addCompilerPass(new Compiler\OperatorsPass()); 20 | } 21 | 22 | /** 23 | * {@inheritdoc} 24 | */ 25 | public function getContainerExtension() 26 | { 27 | return new DependencyInjection\KPhoenRulerZExtension(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Kévin Gomez 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | tests: 2 | ./vendor/bin/phpunit 3 | 4 | release: 5 | ./vendor/bin/RMT release 6 | -------------------------------------------------------------------------------- /Resources/config/debug.yml: -------------------------------------------------------------------------------- 1 | services: 2 | rulerz.evaluator: 3 | alias: rulerz.evaluator.eval 4 | 5 | rulerz.evaluator.eval: 6 | class: RulerZ\Compiler\EvalEvaluator 7 | public: false 8 | -------------------------------------------------------------------------------- /Resources/config/forms.yml: -------------------------------------------------------------------------------- 1 | services: 2 | rulerz.form.type_extension: 3 | class: Symfony\Bridge\RulerZ\Form\SpecTypeExtension 4 | tags: 5 | - { name: form.type_extension, extended_type: Symfony\Component\Form\Extension\Core\Type\FormType } 6 | 7 | -------------------------------------------------------------------------------- /Resources/config/rulerz.yml: -------------------------------------------------------------------------------- 1 | services: 2 | rulerz: 3 | class: RulerZ\RulerZ 4 | arguments: [ "@rulerz.compiler" ] 5 | 6 | rulerz.compiler: 7 | class: RulerZ\Compiler\Compiler 8 | arguments: [ "@rulerz.evaluator" ] 9 | public: false 10 | 11 | rulerz.evaluator: 12 | alias: rulerz.evaluator.file 13 | public: false 14 | 15 | rulerz.evaluator.file: 16 | class: RulerZ\Compiler\FileEvaluator 17 | public: false 18 | arguments: [ "%rulerz.cache_directory%" ] 19 | 20 | rulerz.parser: 21 | class: RulerZ\Parser\Parser 22 | public: false 23 | 24 | rulerz.command.cache_clear: 25 | class: KPhoen\RulerZBundle\Command\CacheClearCommand 26 | public: true 27 | tags: 28 | - {name: console.command } 29 | -------------------------------------------------------------------------------- /Resources/config/targets/doctrine.yml: -------------------------------------------------------------------------------- 1 | services: 2 | rulerz.target.doctrine: 3 | class: RulerZ\DoctrineORM\Target\DoctrineORM 4 | public: false 5 | tags: 6 | - { name: rulerz.target } 7 | -------------------------------------------------------------------------------- /Resources/config/targets/doctrine_dbal.yml: -------------------------------------------------------------------------------- 1 | services: 2 | rulerz.target.doctrine_dbal: 3 | class: RulerZ\DoctrineDBAL\Target\DoctrineDBAL 4 | public: false 5 | tags: 6 | - { name: rulerz.target } 7 | -------------------------------------------------------------------------------- /Resources/config/targets/elasticsearch.yml: -------------------------------------------------------------------------------- 1 | services: 2 | rulerz.target.elasticsearch: 3 | class: RulerZ\Elasticsearch\Target\Elasticsearch 4 | public: false 5 | tags: 6 | - { name: rulerz.target } 7 | -------------------------------------------------------------------------------- /Resources/config/targets/eloquent.yml: -------------------------------------------------------------------------------- 1 | services: 2 | rulerz.target.eloquent: 3 | class: RulerZ\Eloquent\Target\Eloquent 4 | public: false 5 | tags: 6 | - { name: rulerz.target } 7 | -------------------------------------------------------------------------------- /Resources/config/targets/native.yml: -------------------------------------------------------------------------------- 1 | services: 2 | rulerz.target.native: 3 | class: RulerZ\Target\Native\Native 4 | public: false 5 | tags: 6 | - { name: rulerz.target } 7 | -------------------------------------------------------------------------------- /Resources/config/targets/pomm.yml: -------------------------------------------------------------------------------- 1 | services: 2 | rulerz.target.pomm: 3 | class: RulerZ\Pomm\Target\Pomm 4 | public: false 5 | tags: 6 | - { name: rulerz.target } 7 | -------------------------------------------------------------------------------- /Resources/config/targets/solarium.yml: -------------------------------------------------------------------------------- 1 | services: 2 | rulerz.target.solarium: 3 | class: RulerZ\Solarium\Target\Solarium 4 | public: false 5 | tags: 6 | - { name: rulerz.target } 7 | -------------------------------------------------------------------------------- /Resources/config/validators.yml: -------------------------------------------------------------------------------- 1 | services: 2 | rulerz.validator.unique.rule_validator: 3 | class: Symfony\Bridge\RulerZ\Validator\Constraints\RuleValidator 4 | arguments: [ "@rulerz.parser" ] 5 | tags: 6 | - { name: validator.constraint_validator, alias: rulerz_rule_validator } 7 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "kphoen/rulerz-bundle", 3 | "type": "symfony-bundle", 4 | "license": "MIT", 5 | "homepage": "https://github.com/K-Phoen/RulerZBundle", 6 | "description": "Symfony2 Bundle for RulerZ", 7 | "keywords": ["specification", "doctrine", "ruler", "rulerz"], 8 | "authors": [ 9 | { 10 | "name": "Kévin Gomez", 11 | "email": "contact@kevingomez.fr" 12 | } 13 | ], 14 | "autoload": { 15 | "psr-4": { "KPhoen\\RulerZBundle\\": "" }, 16 | "exclude-from-classmap": [ 17 | "/Tests/" 18 | ] 19 | }, 20 | "require": { 21 | "php": ">=7.1", 22 | "kphoen/rulerz": "^1.0", 23 | "kphoen/rulerz-bridge": "^1.0", 24 | "symfony/framework-bundle": "^3.0|^4.0" 25 | }, 26 | "require-dev": { 27 | "phpunit/phpunit": "^7.1", 28 | "symfony/phpunit-bridge": "^3.0|^4.0", 29 | "mikey179/vfsStream": "^1.6", 30 | "matthiasnoback/symfony-dependency-injection-test": "^3.0", 31 | "liip/rmt": "^1.2" 32 | } 33 | } 34 | --------------------------------------------------------------------------------