Skip to content

Commit

Permalink
Merge pull request #33 from Deepress/fix-symfony-bc-break
Browse files Browse the repository at this point in the history
Fix symfony bc break
  • Loading branch information
enumag authored Jul 13, 2018
2 parents c3bd5b7 + 16ea21f commit 48b4abf
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 54 deletions.
21 changes: 0 additions & 21 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,18 @@ cache:
- $HOME/.composer/cache

php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2

env:
matrix:
- NETTE=nette-2.4-dev
- NETTE=nette-2.4
- NETTE=nette-2.3

matrix:
include:
- php: 5.6
env: NETTE=nette-2.3 COMPOSER_EXTRA_ARGS="--prefer-lowest --prefer-stable"
- php: 7.0
env: NETTE=nette-2.4 COVERAGE="--coverage ./coverage.xml --coverage-src ./src" TESTER_RUNTIME="phpdbg"
exclude:
- php: 5.4
env: NETTE=nette-2.4-dev
- php: 5.4
env: NETTE=nette-2.4
- php: 5.5
env: NETTE=nette-2.4-dev
- php: 5.5
env: NETTE=nette-2.4
- php: 7.2
env: NETTE=nette-2.3
allow_failures:
- php: 7.0
env: NETTE=nette-2.4 COVERAGE="--coverage ./coverage.xml --coverage-src ./src" TESTER_RUNTIME="phpdbg"

before_install:
- travis_retry composer self-update
Expand Down
47 changes: 24 additions & 23 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,38 @@
"issues": "https://github.com/kdyby/validator/issues"
},
"require": {
"nette/di": "~2.3@dev",
"nette/utils": "~2.3@dev",
"php": "^7.1",
"nette/di": "~2.4@dev",
"nette/utils": "~2.4@dev",

"symfony/validator": ">=2.5.3",
"symfony/validator": ">=4.1.0",
"kdyby/doctrine-cache": "~2.4@dev",
"kdyby/translation": "~2.2@dev"
},
"require-dev": {
"kdyby/annotations": "~2.2@dev",
"symfony/yaml": "^2.8|^3.0",
"nette/application": "~2.3@dev",
"nette/bootstrap": "~2.3@dev",
"nette/caching": "~2.3@dev",
"nette/component-model": "~2.2@dev",
"nette/database": "~2.3@dev",
"nette/deprecated": "~2.2@dev",
"nette/di": "~2.3@dev",
"nette/finder": "~2.3@dev",
"nette/forms": "~2.3@dev",
"nette/http": "~2.3@dev",
"nette/mail": "~2.3@dev",
"nette/neon": "~2.3@dev",
"nette/php-generator": "~2.3@dev",
"nette/reflection": "~2.3@dev",
"nette/robot-loader": "~2.3@dev",
"nette/application": "~2.4@dev",
"nette/bootstrap": "~2.4@dev",
"nette/caching": "~2.4@dev",
"nette/component-model": "~2.4@dev",
"nette/database": "~2.4@dev",
"nette/deprecated": "~2.4@dev",
"nette/di": "~2.4@dev",
"nette/finder": "~2.4@dev",
"nette/forms": "~2.4@dev",
"nette/http": "~2.4@dev",
"nette/mail": "~2.4@dev",
"nette/neon": "~2.4@dev",
"nette/php-generator": "~2.4@dev",
"nette/reflection": "~2.4@dev",
"nette/robot-loader": "~2.4@dev",
"nette/safe-stream": "~2.3@dev",
"nette/security": "~2.3@dev",
"nette/tokenizer": "~2.2@dev",
"nette/utils": "~2.3@dev",
"latte/latte": "~2.3@dev",
"tracy/tracy": "~2.3@dev",
"nette/security": "~2.4@dev",
"nette/tokenizer": "~2.3@dev",
"nette/utils": "~2.4@dev",
"latte/latte": "~2.4@dev",
"tracy/tracy": "~2.4@dev",

"nette/tester": "~1.3@rc"
},
Expand Down
14 changes: 10 additions & 4 deletions src/DI/ValidatorExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Nette;
use Nette\DI\Compiler;
use Nette\Utils\Validators;

use Symfony\Component\Validator\Constraints\Email;


/**
Expand All @@ -37,7 +37,8 @@ class ValidatorExtension extends Nette\DI\CompilerExtension implements ITranslat
'cache' => 'default',
'translationDomain' => NULL,
'debug' => '%debugMode%',
'strictEmail' => FALSE,
'strictEmail' => NULL,
'emailValidationMode' => Email::VALIDATION_MODE_LOOSE,
];


Expand Down Expand Up @@ -80,12 +81,17 @@ public function loadConfiguration()
->setClass('Symfony\Component\Validator\Validator\ValidatorInterface')
->setFactory('Symfony\Component\Validator\Validator\RecursiveValidator');

Validators::assertField($config, 'strictEmail', 'boolean');
if ($config['strictEmail'] !== NULL) {
Validators::assertField($config, 'strictEmail', 'boolean');
trigger_error('`strictEmail` configuration option is deprecated, use `emailValidationMode` instead.', E_USER_DEPRECATED);;
}

Validators::assertField($config, 'emailValidationMode', 'string');

$builder->addDefinition($this->prefix('constraint.email'))
->setClass('Symfony\Component\Validator\Constraints\EmailValidator')
->setArguments([
'strict' => $config['strictEmail'],
'defaultMode' => $config['emailValidationMode'],
])
->addTag(self::TAG_CONSTRAINT_VALIDATOR);

Expand Down
10 changes: 6 additions & 4 deletions tests/KdybyTests/Validator/Extension.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use KdybyTests\ValidatorMocks\ArticleMock;
use Nette;
use Symfony;
use Tester;
use Symfony\Component\Validator\Constraints\Email;

require_once __DIR__ . '/../bootstrap.php';

Expand Down Expand Up @@ -118,9 +119,9 @@ class ExtensionTest extends Tester\TestCase
public function strictEmailDataProvider()
{
return [
[[], FALSE],
[[__DIR__ . '/config/strict-email.neon'], TRUE],
[[__DIR__ . '/config/non-strict-email.neon'], FALSE],
[[], Email::VALIDATION_MODE_LOOSE],
[[__DIR__ . '/config/strict-email.neon'], Email::VALIDATION_MODE_STRICT],
[[__DIR__ . '/config/non-strict-email.neon'], Email::VALIDATION_MODE_LOOSE],
];
}

Expand All @@ -138,7 +139,8 @@ class ExtensionTest extends Tester\TestCase
$validator = $factory->getInstance(new \Symfony\Component\Validator\Constraints\Email());
Tester\Assert::type('Symfony\Component\Validator\Constraints\EmailValidator', $validator);

$property = new \ReflectionProperty('Symfony\Component\Validator\Constraints\EmailValidator', 'isStrict');
$property = new \ReflectionProperty('Symfony\Component\Validator\Constraints\EmailValidator', 'defaultMode');

$property->setAccessible(TRUE);
Tester\Assert::same($strict, $property->getValue($validator));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/KdybyTests/Validator/config/non-strict-email.neon
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
validator:
strictEmail: false
emailValidationMode: 'loose'
2 changes: 1 addition & 1 deletion tests/KdybyTests/Validator/config/strict-email.neon
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
validator:
strictEmail: true
emailValidationMode: 'strict'

0 comments on commit 48b4abf

Please sign in to comment.