From 9c46e0a7eb8d1d4563a4c671db3c2ed61fecde3d Mon Sep 17 00:00:00 2001 From: phillmac Date: Fri, 4 Oct 2019 07:57:33 +1000 Subject: [PATCH 01/13] Change private methods to protected visibility --- src/RequestDataTransformer.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/RequestDataTransformer.php b/src/RequestDataTransformer.php index c74b008..4126050 100644 --- a/src/RequestDataTransformer.php +++ b/src/RequestDataTransformer.php @@ -139,7 +139,7 @@ public function transformField($name, $value) * * @return mixed */ - private function escapeHtmlCharacters($value) + protected function escapeHtmlCharacters($value) { if (is_array($value)) { return filter_var_array($value, FILTER_SANITIZE_SPECIAL_CHARS); @@ -155,7 +155,7 @@ private function escapeHtmlCharacters($value) * * @return mixed */ - private function purgeHtmlCharacters($value) + protected function purgeHtmlCharacters($value) { if (is_array($value)) { return filter_var_array($value, FILTER_SANITIZE_STRING); @@ -171,7 +171,7 @@ private function purgeHtmlCharacters($value) * * @return mixed */ - private function trim($value) + protected function trim($value) { if (is_array($value)) { return array_map('trim', $value); From 7b536067d5a1723e16d23c238fca3b6543f125d0 Mon Sep 17 00:00:00 2001 From: Louis Charette Date: Fri, 8 Nov 2019 19:25:53 -0500 Subject: [PATCH 02/13] Fix bad param when loading YAML from `RequestSchema` --- CHANGELOG.md | 4 ++++ src/RequestSchema.php | 2 +- src/ServerSideValidator.php | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e482bc7..4077bd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [4.3.1] - xxxx-xx-xx +- Fix bad param when loading YAML from `RequestSchema` + ## [4.3.0] - 2019-06-22 - Dropping support for PHP 5.6 & 7.0 - Updated dependencies @@ -44,6 +47,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a - Implement equals, not_equals, telephone, uri, and username rules +[4.3.1]: https://github.com/userfrosting/fortress/compare/4.3.0...4.3.1 [4.3.0]: https://github.com/userfrosting/fortress/compare/4.2.2...4.3.0 [4.2.2]: https://github.com/userfrosting/fortress/compare/4.2.1...4.2.2 [4.2.1]: https://github.com/userfrosting/fortress/compare/4.2.0...4.2.1 diff --git a/src/RequestSchema.php b/src/RequestSchema.php index 37c5f54..bb4ac0a 100644 --- a/src/RequestSchema.php +++ b/src/RequestSchema.php @@ -39,7 +39,7 @@ public function __construct($path = null) if (!is_null($path)) { $this->loader = new YamlFileLoader($path); - $this->items = $this->loader->load($path); + $this->items = $this->loader->load(); } } diff --git a/src/ServerSideValidator.php b/src/ServerSideValidator.php index 3878fa2..309798e 100644 --- a/src/ServerSideValidator.php +++ b/src/ServerSideValidator.php @@ -170,7 +170,7 @@ protected function validateUsername($field, $value) * Add a rule to the validator, along with a specified error message if that rule is failed by the data. * * @param string $rule The name of the validation rule. - * @param string $messageSet The message to display when validation against this rule fails. + * @param string|null $messageSet The message to display when validation against this rule fails. */ private function ruleWithMessage($rule, $messageSet) { From 495dbed42628b561f7fd0167d3d99096b920265b Mon Sep 17 00:00:00 2001 From: Louis Charette Date: Fri, 8 Nov 2019 19:27:21 -0500 Subject: [PATCH 03/13] Making StyleCI happy --- src/ServerSideValidator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ServerSideValidator.php b/src/ServerSideValidator.php index 309798e..a36f1b5 100644 --- a/src/ServerSideValidator.php +++ b/src/ServerSideValidator.php @@ -169,7 +169,7 @@ protected function validateUsername($field, $value) /** * Add a rule to the validator, along with a specified error message if that rule is failed by the data. * - * @param string $rule The name of the validation rule. + * @param string $rule The name of the validation rule. * @param string|null $messageSet The message to display when validation against this rule fails. */ private function ruleWithMessage($rule, $messageSet) From dfb2f894ebf3991535d261ff40d2810fbbb8ff18 Mon Sep 17 00:00:00 2001 From: Louis Charette Date: Sat, 9 Nov 2019 14:33:52 -0500 Subject: [PATCH 04/13] Support for future i18n version --- README.md | 7 ++++--- composer.json | 2 +- src/Adapter/ClientSideValidationAdapter.php | 12 +++++------ src/ServerSideValidator.php | 10 ++++----- src/ServerSideValidatorInterface.php | 8 +++---- tests/FormValidationAdapterTest.php | 23 +++++++++++++++++++-- tests/JqueryValidationAdapterTest.php | 23 +++++++++++++++++++-- tests/ServerSideValidatorTest.php | 23 +++++++++++++++++++-- 8 files changed, 83 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 20b96c6..4f6ef3b 100644 --- a/README.md +++ b/README.md @@ -181,11 +181,12 @@ To process an array of user input, create a `ServerSideValidator` object with th ### Translator object -Fortress requires a `MessageTranslator` (see [i18n](https://github.com/userfrosting/i18n)) object to translate message keys that may appear in rules: +Fortress requires a `Translator` (see [i18n](https://github.com/userfrosting/i18n)) object to translate message keys that may appear in rules: ``` -$localeLoader = new \UserFrosting\Support\Loader\ArrayFileLoader('locales/en_US/translations.php'); -$translator = new \UserFrosting\I18n\MessageTranslator($localeLoader->load()); +$locale = new \UserFrosting\I18n\Locale('en_US'); +$dictionary = new \UserFrosting\I18n\Dictionary($locale, $this->ci->locator); +$translator = new \UserFrosting\I18n\Translator($dictionary); ``` Then, call `validate` on the input array. `validate` will return false if any of the rules are failed. Call `errors` to get the list of generated error messages. You might want to store these error messages to a flash messaging system so they can be shown to the user. diff --git a/composer.json b/composer.json index d47c024..49225d5 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "require": { "ezyang/htmlpurifier": "^4.7.0", "php": ">=7.1", - "userfrosting/i18n": "~4.3.0", + "userfrosting/i18n": "dev-feature-rewrite", "vlucas/valitron": "^1.2.3" }, "require-dev": { diff --git a/src/Adapter/ClientSideValidationAdapter.php b/src/Adapter/ClientSideValidationAdapter.php index cb33378..4b88463 100644 --- a/src/Adapter/ClientSideValidationAdapter.php +++ b/src/Adapter/ClientSideValidationAdapter.php @@ -11,7 +11,7 @@ namespace UserFrosting\Fortress\Adapter; use UserFrosting\Fortress\RequestSchema\RequestSchemaInterface; -use UserFrosting\I18n\MessageTranslator; +use UserFrosting\I18n\Translator; /** * ClientSideValidationAdapter Class. @@ -28,7 +28,7 @@ abstract class ClientSideValidationAdapter protected $schema; /** - * @var MessageTranslator + * @var Translator */ protected $translator; @@ -36,9 +36,9 @@ abstract class ClientSideValidationAdapter * Create a new client-side validator. * * @param RequestSchemaInterface $schema A RequestSchema object, containing the validation rules. - * @param MessageTranslator $translator A MessageTranslator to be used to translate message ids found in the schema. + * @param Translator $translator A Translator to be used to translate message ids found in the schema. */ - public function __construct(RequestSchemaInterface $schema, MessageTranslator $translator) + public function __construct(RequestSchemaInterface $schema, Translator $translator) { // Set schema $this->setSchema($schema); @@ -62,9 +62,9 @@ public function setSchema(RequestSchemaInterface $schema) /** * Set the translator for this validator, as a valid MessageTranslator object. * - * @param MessageTranslator $translator A MessageTranslator to be used to translate message ids found in the schema. + * @param Translator $translator A Translator to be used to translate message ids found in the schema. */ - public function setTranslator(MessageTranslator $translator) + public function setTranslator(Translator $translator) { $this->translator = $translator; diff --git a/src/ServerSideValidator.php b/src/ServerSideValidator.php index a36f1b5..642b1cb 100644 --- a/src/ServerSideValidator.php +++ b/src/ServerSideValidator.php @@ -11,7 +11,7 @@ namespace UserFrosting\Fortress; use UserFrosting\Fortress\RequestSchema\RequestSchemaInterface; -use UserFrosting\I18n\MessageTranslator; +use UserFrosting\I18n\Translator; use Valitron\Validator; /** @@ -29,16 +29,16 @@ class ServerSideValidator extends Validator implements ServerSideValidatorInterf protected $schema; /** - * @var MessageTranslator + * @var Translator */ protected $translator; /** Create a new server-side validator. * * @param RequestSchemaInterface $schema A RequestSchemaInterface object, containing the validation rules. - * @param MessageTranslator $translator A MessageTranslator to be used to translate message ids found in the schema. + * @param Translator $translator A Translator to be used to translate message ids found in the schema. */ - public function __construct(RequestSchemaInterface $schema, MessageTranslator $translator) + public function __construct(RequestSchemaInterface $schema, Translator $translator) { // Set schema $this->setSchema($schema); @@ -62,7 +62,7 @@ public function setSchema(RequestSchemaInterface $schema) /** * {@inheritdoc} */ - public function setTranslator(MessageTranslator $translator) + public function setTranslator(Translator $translator) { $this->translator = $translator; } diff --git a/src/ServerSideValidatorInterface.php b/src/ServerSideValidatorInterface.php index f5607f8..1f9e82e 100644 --- a/src/ServerSideValidatorInterface.php +++ b/src/ServerSideValidatorInterface.php @@ -11,7 +11,7 @@ namespace UserFrosting\Fortress; use UserFrosting\Fortress\RequestSchema\RequestSchemaInterface; -use UserFrosting\I18n\MessageTranslator; +use UserFrosting\I18n\Translator; /** * ServerSideValidator Interface. @@ -30,11 +30,11 @@ interface ServerSideValidatorInterface public function setSchema(RequestSchemaInterface $schema); /** - * Set the translator for this validator, as a valid MessageTranslator object. + * Set the translator for this validator, as a valid Translator object. * - * @param MessageTranslator $translator A MessageTranslator to be used to translate message ids found in the schema. + * @param Translator $translator A Translator to be used to translate message ids found in the schema. */ - public function setTranslator(MessageTranslator $translator); + public function setTranslator(Translator $translator); /** * Validate the specified data against the schema rules. diff --git a/tests/FormValidationAdapterTest.php b/tests/FormValidationAdapterTest.php index 905fddb..2bffda9 100644 --- a/tests/FormValidationAdapterTest.php +++ b/tests/FormValidationAdapterTest.php @@ -13,7 +13,10 @@ use PHPUnit\Framework\TestCase; use UserFrosting\Fortress\Adapter\FormValidationAdapter; use UserFrosting\Fortress\RequestSchema\RequestSchemaRepository; -use UserFrosting\I18n\MessageTranslator; +use UserFrosting\I18n\Translator; +use UserFrosting\I18n\DictionaryInterface; +use UserFrosting\I18n\LocaleInterface; +use UserFrosting\Support\Repository\Repository; class FormValidationAdapterTest extends TestCase { @@ -22,7 +25,7 @@ class FormValidationAdapterTest extends TestCase public function setUp() { // Create a message translator - $this->translator = new MessageTranslator(); + $this->translator = new Translator(new DictionaryStubA()); } public function testValidateEmail() @@ -682,3 +685,19 @@ public function testDomainRulesServerOnly() $this->assertEquals($expectedResult, $result); } } + +class DictionaryStubA extends Repository implements DictionaryInterface +{ + public function __construct() + { + } + + public function getDictionary(): array + { + return []; + } + + public function getLocale(): LocaleInterface + { + } +} diff --git a/tests/JqueryValidationAdapterTest.php b/tests/JqueryValidationAdapterTest.php index f1ec874..4b8d4b8 100644 --- a/tests/JqueryValidationAdapterTest.php +++ b/tests/JqueryValidationAdapterTest.php @@ -13,7 +13,10 @@ use PHPUnit\Framework\TestCase; use UserFrosting\Fortress\Adapter\JqueryValidationAdapter; use UserFrosting\Fortress\RequestSchema\RequestSchemaRepository; -use UserFrosting\I18n\MessageTranslator; +use UserFrosting\I18n\Translator; +use UserFrosting\I18n\DictionaryInterface; +use UserFrosting\I18n\LocaleInterface; +use UserFrosting\Support\Repository\Repository; class JqueryValidationAdapterTest extends TestCase { @@ -22,7 +25,7 @@ class JqueryValidationAdapterTest extends TestCase public function setUp() { // Create a message translator - $this->translator = new MessageTranslator(); + $this->translator = new Translator(new DictionaryStubB()); } public function testValidateEmail() @@ -1171,3 +1174,19 @@ public function testValidateNoRule() ], $result); } } + +class DictionaryStubB extends Repository implements DictionaryInterface +{ + public function __construct() + { + } + + public function getDictionary(): array + { + return []; + } + + public function getLocale(): LocaleInterface + { + } +} diff --git a/tests/ServerSideValidatorTest.php b/tests/ServerSideValidatorTest.php index 15e853c..9817884 100644 --- a/tests/ServerSideValidatorTest.php +++ b/tests/ServerSideValidatorTest.php @@ -13,7 +13,10 @@ use PHPUnit\Framework\TestCase; use UserFrosting\Fortress\RequestSchema\RequestSchemaRepository; use UserFrosting\Fortress\ServerSideValidator; -use UserFrosting\I18n\MessageTranslator; +use UserFrosting\I18n\Translator; +use UserFrosting\I18n\DictionaryInterface; +use UserFrosting\I18n\LocaleInterface; +use UserFrosting\Support\Repository\Repository; class ServerSideValidatorTest extends TestCase { @@ -22,7 +25,7 @@ class ServerSideValidatorTest extends TestCase public function setUp() { // Create a message translator - $this->translator = new MessageTranslator(); + $this->translator = new Translator(new DictionaryStubC()); } public function testValidateNoValidators() @@ -893,3 +896,19 @@ public function testValidateWithNoValidatorMessage() $this->assertTrue($result); } } + +class DictionaryStubC extends Repository implements DictionaryInterface +{ + public function __construct() + { + } + + public function getDictionary(): array + { + return []; + } + + public function getLocale(): LocaleInterface + { + } +} From 9f3870027134c4e9558147a32f6e03599e6b6c38 Mon Sep 17 00:00:00 2001 From: Louis Charette Date: Sat, 9 Nov 2019 14:35:10 -0500 Subject: [PATCH 05/13] Making StyleCI happy --- tests/FormValidationAdapterTest.php | 2 +- tests/JqueryValidationAdapterTest.php | 2 +- tests/ServerSideValidatorTest.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/FormValidationAdapterTest.php b/tests/FormValidationAdapterTest.php index 2bffda9..c179219 100644 --- a/tests/FormValidationAdapterTest.php +++ b/tests/FormValidationAdapterTest.php @@ -13,9 +13,9 @@ use PHPUnit\Framework\TestCase; use UserFrosting\Fortress\Adapter\FormValidationAdapter; use UserFrosting\Fortress\RequestSchema\RequestSchemaRepository; -use UserFrosting\I18n\Translator; use UserFrosting\I18n\DictionaryInterface; use UserFrosting\I18n\LocaleInterface; +use UserFrosting\I18n\Translator; use UserFrosting\Support\Repository\Repository; class FormValidationAdapterTest extends TestCase diff --git a/tests/JqueryValidationAdapterTest.php b/tests/JqueryValidationAdapterTest.php index 4b8d4b8..237c84b 100644 --- a/tests/JqueryValidationAdapterTest.php +++ b/tests/JqueryValidationAdapterTest.php @@ -13,9 +13,9 @@ use PHPUnit\Framework\TestCase; use UserFrosting\Fortress\Adapter\JqueryValidationAdapter; use UserFrosting\Fortress\RequestSchema\RequestSchemaRepository; -use UserFrosting\I18n\Translator; use UserFrosting\I18n\DictionaryInterface; use UserFrosting\I18n\LocaleInterface; +use UserFrosting\I18n\Translator; use UserFrosting\Support\Repository\Repository; class JqueryValidationAdapterTest extends TestCase diff --git a/tests/ServerSideValidatorTest.php b/tests/ServerSideValidatorTest.php index 9817884..e4e4932 100644 --- a/tests/ServerSideValidatorTest.php +++ b/tests/ServerSideValidatorTest.php @@ -13,9 +13,9 @@ use PHPUnit\Framework\TestCase; use UserFrosting\Fortress\RequestSchema\RequestSchemaRepository; use UserFrosting\Fortress\ServerSideValidator; -use UserFrosting\I18n\Translator; use UserFrosting\I18n\DictionaryInterface; use UserFrosting\I18n\LocaleInterface; +use UserFrosting\I18n\Translator; use UserFrosting\Support\Repository\Repository; class ServerSideValidatorTest extends TestCase From 58b0243224fa73c09bbc96beae54ece5309557cf Mon Sep 17 00:00:00 2001 From: Louis Charette Date: Sat, 9 Nov 2019 19:32:24 -0500 Subject: [PATCH 06/13] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 49225d5..0d90c0d 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "require": { "ezyang/htmlpurifier": "^4.7.0", "php": ">=7.1", - "userfrosting/i18n": "dev-feature-rewrite", + "userfrosting/i18n": "dev-develop", "vlucas/valitron": "^1.2.3" }, "require-dev": { From 74886d41130f3bbe77a62f271713e25ff6c9940b Mon Sep 17 00:00:00 2001 From: Louis Charette Date: Sat, 9 Nov 2019 19:38:34 -0500 Subject: [PATCH 07/13] Update changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4077bd4..6805550 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,8 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## [4.3.1] - xxxx-xx-xx +## [4.4.0] - xxxx-xx-xx +- Added support for `UserFrosting/i18n` 4.4.0 - Fix bad param when loading YAML from `RequestSchema` ## [4.3.0] - 2019-06-22 From 23aaa40751698845125d95561a489ae3a7e2d9e6 Mon Sep 17 00:00:00 2001 From: Louis Charette Date: Sat, 9 Nov 2019 19:50:49 -0500 Subject: [PATCH 08/13] Updated changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6805550..c6f8990 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a ## [4.4.0] - xxxx-xx-xx - Added support for `UserFrosting/i18n` 4.4.0 - Fix bad param when loading YAML from `RequestSchema` +- Enables extension of the `RequestDataTransformer` class by allowing implementation of a custom `transformField` function ([#29]) ## [4.3.0] - 2019-06-22 - Dropping support for PHP 5.6 & 7.0 @@ -59,3 +60,4 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a [4.1.0]: https://github.com/userfrosting/fortress/compare/4.0.1...4.1.0 [4.0.1]: https://github.com/userfrosting/fortress/compare/4.0.0...4.0.1 [#24]: https://github.com/userfrosting/fortress/issues/24 +[#29]: https://github.com/userfrosting/fortress/pull/29 From 26d415316204ce3af17353e290393c932a057fe3 Mon Sep 17 00:00:00 2001 From: phillmac Date: Thu, 27 Feb 2020 11:30:00 +1100 Subject: [PATCH 09/13] Improve extensibility Set `ruleWithMessage()` & `generateSchemaRules()` functions to protected scope to allow calling / overriding from subclasses. --- src/ServerSideValidator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ServerSideValidator.php b/src/ServerSideValidator.php index 3878fa2..5336380 100644 --- a/src/ServerSideValidator.php +++ b/src/ServerSideValidator.php @@ -172,7 +172,7 @@ protected function validateUsername($field, $value) * @param string $rule The name of the validation rule. * @param string $messageSet The message to display when validation against this rule fails. */ - private function ruleWithMessage($rule, $messageSet) + protected function ruleWithMessage($rule, $messageSet) { // Weird way to adapt with Valitron's funky interface $params = array_merge([$rule], array_slice(func_get_args(), 2)); @@ -191,7 +191,7 @@ private function ruleWithMessage($rule, $messageSet) /** * Generate and add rules from the schema. */ - private function generateSchemaRules() + protected function generateSchemaRules() { foreach ($this->schema->all() as $fieldName => $field) { if (!isset($field['validators'])) { From 2bb5a36fab158df561afdfd4d8cae7b6f1995f60 Mon Sep 17 00:00:00 2001 From: Louis Charette Date: Wed, 26 Feb 2020 19:48:23 -0500 Subject: [PATCH 10/13] Fix issue with missing `getFlattenDictionary` method in stub --- tests/DictionaryStub.php | 35 +++++++++++++++++++++++++++ tests/FormValidationAdapterTest.php | 21 +--------------- tests/JqueryValidationAdapterTest.php | 21 +--------------- tests/ServerSideValidatorTest.php | 21 +--------------- 4 files changed, 38 insertions(+), 60 deletions(-) create mode 100644 tests/DictionaryStub.php diff --git a/tests/DictionaryStub.php b/tests/DictionaryStub.php new file mode 100644 index 0000000..4ca6bf5 --- /dev/null +++ b/tests/DictionaryStub.php @@ -0,0 +1,35 @@ +translator = new Translator(new DictionaryStubA()); + $this->translator = new Translator(new DictionaryStub()); } public function testValidateEmail() @@ -685,19 +682,3 @@ public function testDomainRulesServerOnly() $this->assertEquals($expectedResult, $result); } } - -class DictionaryStubA extends Repository implements DictionaryInterface -{ - public function __construct() - { - } - - public function getDictionary(): array - { - return []; - } - - public function getLocale(): LocaleInterface - { - } -} diff --git a/tests/JqueryValidationAdapterTest.php b/tests/JqueryValidationAdapterTest.php index 237c84b..67ce08b 100644 --- a/tests/JqueryValidationAdapterTest.php +++ b/tests/JqueryValidationAdapterTest.php @@ -13,10 +13,7 @@ use PHPUnit\Framework\TestCase; use UserFrosting\Fortress\Adapter\JqueryValidationAdapter; use UserFrosting\Fortress\RequestSchema\RequestSchemaRepository; -use UserFrosting\I18n\DictionaryInterface; -use UserFrosting\I18n\LocaleInterface; use UserFrosting\I18n\Translator; -use UserFrosting\Support\Repository\Repository; class JqueryValidationAdapterTest extends TestCase { @@ -25,7 +22,7 @@ class JqueryValidationAdapterTest extends TestCase public function setUp() { // Create a message translator - $this->translator = new Translator(new DictionaryStubB()); + $this->translator = new Translator(new DictionaryStub()); } public function testValidateEmail() @@ -1174,19 +1171,3 @@ public function testValidateNoRule() ], $result); } } - -class DictionaryStubB extends Repository implements DictionaryInterface -{ - public function __construct() - { - } - - public function getDictionary(): array - { - return []; - } - - public function getLocale(): LocaleInterface - { - } -} diff --git a/tests/ServerSideValidatorTest.php b/tests/ServerSideValidatorTest.php index e4e4932..d9369d1 100644 --- a/tests/ServerSideValidatorTest.php +++ b/tests/ServerSideValidatorTest.php @@ -13,10 +13,7 @@ use PHPUnit\Framework\TestCase; use UserFrosting\Fortress\RequestSchema\RequestSchemaRepository; use UserFrosting\Fortress\ServerSideValidator; -use UserFrosting\I18n\DictionaryInterface; -use UserFrosting\I18n\LocaleInterface; use UserFrosting\I18n\Translator; -use UserFrosting\Support\Repository\Repository; class ServerSideValidatorTest extends TestCase { @@ -25,7 +22,7 @@ class ServerSideValidatorTest extends TestCase public function setUp() { // Create a message translator - $this->translator = new Translator(new DictionaryStubC()); + $this->translator = new Translator(new DictionaryStub()); } public function testValidateNoValidators() @@ -896,19 +893,3 @@ public function testValidateWithNoValidatorMessage() $this->assertTrue($result); } } - -class DictionaryStubC extends Repository implements DictionaryInterface -{ - public function __construct() - { - } - - public function getDictionary(): array - { - return []; - } - - public function getLocale(): LocaleInterface - { - } -} From 552d5c1c1820e0138abff785caa31e068cf3d9ed Mon Sep 17 00:00:00 2001 From: Louis Charette Date: Wed, 26 Feb 2020 19:49:47 -0500 Subject: [PATCH 11/13] Fix styling --- tests/DictionaryStub.php | 2 +- tests/RequestSchemaRepositoryTest.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/DictionaryStub.php b/tests/DictionaryStub.php index 4ca6bf5..ab8a414 100644 --- a/tests/DictionaryStub.php +++ b/tests/DictionaryStub.php @@ -32,4 +32,4 @@ public function getLocale(): LocaleInterface public function getFlattenDictionary(): array { } -} \ No newline at end of file +} diff --git a/tests/RequestSchemaRepositoryTest.php b/tests/RequestSchemaRepositoryTest.php index a3c8158..aef0c97 100644 --- a/tests/RequestSchemaRepositoryTest.php +++ b/tests/RequestSchemaRepositoryTest.php @@ -97,10 +97,10 @@ public function testSetDefaultWithMissingField() // Assert $contactSchema = [ - 'foo' => [ - 'default' => 'bar', - ], - ]; + 'foo' => [ + 'default' => 'bar', + ], + ]; $this->assertArraySubset($contactSchema, $result); } From bdeac1e074ff447ae913a11d8fe5343b6d17da47 Mon Sep 17 00:00:00 2001 From: Louis Charette Date: Wed, 26 Feb 2020 20:11:26 -0500 Subject: [PATCH 12/13] Changed private method into protected ones to improve extensibility. Ref #30 --- CHANGELOG.md | 2 ++ src/Adapter/FormValidationAdapter.php | 2 +- src/Adapter/JqueryValidationAdapter.php | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6f8990..597f4ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a - Added support for `UserFrosting/i18n` 4.4.0 - Fix bad param when loading YAML from `RequestSchema` - Enables extension of the `RequestDataTransformer` class by allowing implementation of a custom `transformField` function ([#29]) +- Changed private method into protected ones to improve extensibility ([#30]) ## [4.3.0] - 2019-06-22 - Dropping support for PHP 5.6 & 7.0 @@ -61,3 +62,4 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a [4.0.1]: https://github.com/userfrosting/fortress/compare/4.0.0...4.0.1 [#24]: https://github.com/userfrosting/fortress/issues/24 [#29]: https://github.com/userfrosting/fortress/pull/29 +[#30]: https://github.com/userfrosting/fortress/pull/30 diff --git a/src/Adapter/FormValidationAdapter.php b/src/Adapter/FormValidationAdapter.php index 6350624..0eaad8c 100644 --- a/src/Adapter/FormValidationAdapter.php +++ b/src/Adapter/FormValidationAdapter.php @@ -174,7 +174,7 @@ public function formValidationRulesHtml5() * @param string $validatorName * @param string[] $validator */ - private function transformValidator($fieldName, $validatorName, array $validator) + protected function transformValidator($fieldName, $validatorName, array $validator) { $params = []; // Message diff --git a/src/Adapter/JqueryValidationAdapter.php b/src/Adapter/JqueryValidationAdapter.php index a123bf8..c788f7b 100644 --- a/src/Adapter/JqueryValidationAdapter.php +++ b/src/Adapter/JqueryValidationAdapter.php @@ -90,7 +90,7 @@ public function rules($format = 'json', $stringEncode = false, $arrayPrefix = '' * @param string $validatorName * @param string[] $validator */ - private function transformValidator($fieldName, $validatorName, array $validator) + protected function transformValidator($fieldName, $validatorName, array $validator) { $transformedValidatorJson = []; switch ($validatorName) { From 6f6e41fdddb78da2c35c9b2a8e85c264287122c4 Mon Sep 17 00:00:00 2001 From: Louis Charette Date: Tue, 17 Mar 2020 21:00:04 -0400 Subject: [PATCH 13/13] Update changelog & dependencies --- CHANGELOG.md | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 597f4ab..8e9244b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## [4.4.0] - xxxx-xx-xx +## [4.4.0] - 2020-03-17 - Added support for `UserFrosting/i18n` 4.4.0 - Fix bad param when loading YAML from `RequestSchema` - Enables extension of the `RequestDataTransformer` class by allowing implementation of a custom `transformField` function ([#29]) diff --git a/composer.json b/composer.json index 0d90c0d..425ad42 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "require": { "ezyang/htmlpurifier": "^4.7.0", "php": ">=7.1", - "userfrosting/i18n": "dev-develop", + "userfrosting/i18n": "~4.4.0", "vlucas/valitron": "^1.2.3" }, "require-dev": {