Skip to content
This repository has been archived by the owner on Apr 28, 2024. It is now read-only.

Commit

Permalink
Release 4.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lcharette authored Mar 18, 2020
2 parents 148df3a + 6f6e41f commit 944b48a
Show file tree
Hide file tree
Showing 15 changed files with 84 additions and 39 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ 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] - 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])
- Changed private method into protected ones to improve extensibility ([#30])

## [4.3.0] - 2019-06-22
- Dropping support for PHP 5.6 & 7.0
- Updated dependencies
Expand Down Expand Up @@ -44,6 +50,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
Expand All @@ -54,3 +61,5 @@ 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
[#30]: https://github.com/userfrosting/fortress/pull/30
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"require": {
"ezyang/htmlpurifier": "^4.7.0",
"php": ">=7.1",
"userfrosting/i18n": "~4.3.0",
"userfrosting/i18n": "~4.4.0",
"vlucas/valitron": "^1.2.3"
},
"require-dev": {
Expand Down
12 changes: 6 additions & 6 deletions src/Adapter/ClientSideValidationAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace UserFrosting\Fortress\Adapter;

use UserFrosting\Fortress\RequestSchema\RequestSchemaInterface;
use UserFrosting\I18n\MessageTranslator;
use UserFrosting\I18n\Translator;

/**
* ClientSideValidationAdapter Class.
Expand All @@ -28,17 +28,17 @@ abstract class ClientSideValidationAdapter
protected $schema;

/**
* @var MessageTranslator
* @var Translator
*/
protected $translator;

/**
* 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);
Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/FormValidationAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/JqueryValidationAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/RequestDataTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/RequestSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
18 changes: 9 additions & 9 deletions src/ServerSideValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace UserFrosting\Fortress;

use UserFrosting\Fortress\RequestSchema\RequestSchemaInterface;
use UserFrosting\I18n\MessageTranslator;
use UserFrosting\I18n\Translator;
use Valitron\Validator;

/**
Expand All @@ -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);
Expand All @@ -62,7 +62,7 @@ public function setSchema(RequestSchemaInterface $schema)
/**
* {@inheritdoc}
*/
public function setTranslator(MessageTranslator $translator)
public function setTranslator(Translator $translator)
{
$this->translator = $translator;
}
Expand Down Expand Up @@ -169,10 +169,10 @@ 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 $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)
protected function ruleWithMessage($rule, $messageSet)
{
// Weird way to adapt with Valitron's funky interface
$params = array_merge([$rule], array_slice(func_get_args(), 2));
Expand All @@ -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'])) {
Expand Down
8 changes: 4 additions & 4 deletions src/ServerSideValidatorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace UserFrosting\Fortress;

use UserFrosting\Fortress\RequestSchema\RequestSchemaInterface;
use UserFrosting\I18n\MessageTranslator;
use UserFrosting\I18n\Translator;

/**
* ServerSideValidator Interface.
Expand All @@ -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.
Expand Down
35 changes: 35 additions & 0 deletions tests/DictionaryStub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/*
* UserFrosting Fortress (http://www.userfrosting.com)
*
* @link https://github.com/userfrosting/fortress
* @copyright Copyright (c) 2013-2019 Alexander Weissman
* @license https://github.com/userfrosting/fortress/blob/master/LICENSE.md (MIT License)
*/

namespace UserFrosting\Fortress\Tests;

use UserFrosting\I18n\DictionaryInterface;
use UserFrosting\I18n\LocaleInterface;
use UserFrosting\Support\Repository\Repository;

class DictionaryStub extends Repository implements DictionaryInterface
{
public function __construct()
{
}

public function getDictionary(): array
{
return [];
}

public function getLocale(): LocaleInterface
{
}

public function getFlattenDictionary(): array
{
}
}
4 changes: 2 additions & 2 deletions tests/FormValidationAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use PHPUnit\Framework\TestCase;
use UserFrosting\Fortress\Adapter\FormValidationAdapter;
use UserFrosting\Fortress\RequestSchema\RequestSchemaRepository;
use UserFrosting\I18n\MessageTranslator;
use UserFrosting\I18n\Translator;

class FormValidationAdapterTest extends TestCase
{
Expand All @@ -22,7 +22,7 @@ class FormValidationAdapterTest extends TestCase
public function setUp()
{
// Create a message translator
$this->translator = new MessageTranslator();
$this->translator = new Translator(new DictionaryStub());
}

public function testValidateEmail()
Expand Down
4 changes: 2 additions & 2 deletions tests/JqueryValidationAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use PHPUnit\Framework\TestCase;
use UserFrosting\Fortress\Adapter\JqueryValidationAdapter;
use UserFrosting\Fortress\RequestSchema\RequestSchemaRepository;
use UserFrosting\I18n\MessageTranslator;
use UserFrosting\I18n\Translator;

class JqueryValidationAdapterTest extends TestCase
{
Expand All @@ -22,7 +22,7 @@ class JqueryValidationAdapterTest extends TestCase
public function setUp()
{
// Create a message translator
$this->translator = new MessageTranslator();
$this->translator = new Translator(new DictionaryStub());
}

public function testValidateEmail()
Expand Down
8 changes: 4 additions & 4 deletions tests/RequestSchemaRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ public function testSetDefaultWithMissingField()

// Assert
$contactSchema = [
'foo' => [
'default' => 'bar',
],
];
'foo' => [
'default' => 'bar',
],
];
$this->assertArraySubset($contactSchema, $result);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/ServerSideValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use PHPUnit\Framework\TestCase;
use UserFrosting\Fortress\RequestSchema\RequestSchemaRepository;
use UserFrosting\Fortress\ServerSideValidator;
use UserFrosting\I18n\MessageTranslator;
use UserFrosting\I18n\Translator;

class ServerSideValidatorTest extends TestCase
{
Expand All @@ -22,7 +22,7 @@ class ServerSideValidatorTest extends TestCase
public function setUp()
{
// Create a message translator
$this->translator = new MessageTranslator();
$this->translator = new Translator(new DictionaryStub());
}

public function testValidateNoValidators()
Expand Down

0 comments on commit 944b48a

Please sign in to comment.