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

Commit

Permalink
4.2.2 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
lcharette committed Mar 29, 2019
2 parents 4e0d947 + 8ce0a02 commit f0e4de4
Show file tree
Hide file tree
Showing 21 changed files with 2,124 additions and 1,083 deletions.
4 changes: 1 addition & 3 deletions .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,11 @@ $rules = [

'header_comment' => [
'header' => $header,
'separate' => 'bottom',
'comment_type' => 'PHPDoc',
]
];

$finder = PhpCsFixer\Finder::create()
->in(__DIR__ . '/src');
->in([__DIR__ . '/src', __DIR__ . '/tests']);

return PhpCsFixer\Config::create()
->setRules($rules)
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ 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.2.2] - 2019-03-28
- Fix error if custom validator doesn't provides a message.
- Removed broken and deprecated `RequestSchema::loadSchema` method.
- 100% Test coverage ([#24])

## [4.2.1] - 2019-01-13
- Fix issue with ResourceLocator

Expand Down Expand Up @@ -34,10 +39,12 @@ 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.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
[4.2.0]: https://github.com/userfrosting/fortress/compare/4.1.2...4.2.0
[4.1.3]: https://github.com/userfrosting/fortress/compare/4.1.2...4.1.3
[4.1.2]: https://github.com/userfrosting/fortress/compare/v4.1.1...4.1.2
[4.1.1]: https://github.com/userfrosting/fortress/compare/4.1.0...v4.1.1
[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
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,29 @@

[![Latest Version](https://img.shields.io/github/release/userfrosting/fortress.svg)](https://github.com/userfrosting/fortress/releases)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE.md)
[![Build Status](https://travis-ci.org/userfrosting/fortress.svg?branch=master)](https://travis-ci.org/userfrosting/fortress)
[![codecov](https://codecov.io/gh/userfrosting/fortress/branch/master/graph/badge.svg)](https://codecov.io/gh/userfrosting/fortress)
[![Join the chat at https://chat.userfrosting.com/channel/support](https://demo.rocket.chat/images/join-chat.svg)](https://chat.userfrosting.com/channel/support)
[![Donate](https://img.shields.io/badge/Open%20Collective-Donate-blue.svg)](https://opencollective.com/userfrosting#backer)

| Branch | Build | Coverage | Style |
| ------ |:-----:|:--------:|:-----:|
| [master][Fortress] | [![][fortress-master-build]][fortress-travis] | [![][fortress-master-codecov]][fortress-codecov] | [![][fortress-style-master]][fortress-style] |
| [develop][fortress-develop] | [![][fortress-develop-build]][fortress-travis] | [![][fortress-develop-codecov]][fortress-codecov] | [![][fortress-style-develop]][fortress-style] |

<!-- Links -->
[Fortress]: https://github.com/userfrosting/fortress
[fortress-develop]: https://github.com/userfrosting/fortress/tree/develop
[fortress-version]: https://img.shields.io/github/release/userfrosting/fortress.svg
[fortress-master-build]: https://travis-ci.org/userfrosting/fortress.svg?branch=master
[fortress-master-codecov]: https://codecov.io/gh/userfrosting/fortress/branch/master/graph/badge.svg
[fortress-develop-build]: https://travis-ci.org/userfrosting/fortress.svg?branch=develop
[fortress-develop-codecov]: https://codecov.io/gh/userfrosting/fortress/branch/develop/graph/badge.svg
[fortress-releases]: https://github.com/userfrosting/fortress/releases
[fortress-travis]: https://travis-ci.org/userfrosting/fortress
[fortress-codecov]: https://codecov.io/gh/userfrosting/fortress
[fortress-style-master]: https://github.styleci.io/repos/30551954/shield?branch=master&style=flat
[fortress-style-develop]: https://github.styleci.io/repos/30551954/shield?branch=develop&style=flat
[fortress-style]: https://github.styleci.io/repos/30551954

If you simply want to show that you like this project, or want to remember it for later, you should **star**, not **fork**, this repository. Forking is only for when you are ready to create your own copy of the code to work on.

### By [Alex Weissman](https://alexanderweissman.com)
Expand Down Expand Up @@ -85,7 +103,7 @@ message:
{
"require": {
"php": ">=5.6.0",
"userfrosting/fortress": "^4.1.0"
"userfrosting/fortress": "^4.2.0"
}
}
```
Expand Down
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,10 @@
"psr-4": {
"UserFrosting\\Fortress\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"UserFrosting\\Fortress\\Tests\\": "tests"
}
}
}
13 changes: 8 additions & 5 deletions src/Adapter/ClientSideValidationAdapter.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
/**

/*
* UserFrosting Fortress (http://www.userfrosting.com)
*
* @link https://github.com/userfrosting/fortress
Expand All @@ -13,7 +14,7 @@
use UserFrosting\I18n\MessageTranslator;

/**
* ClientSideValidationAdapter Class
* ClientSideValidationAdapter Class.
*
* Loads validation rules from a schema and generates client-side rules compatible with a particular client-side (usually Javascript) plugin.
*
Expand Down Expand Up @@ -74,9 +75,11 @@ public function setTranslator(MessageTranslator $translator)
* Generate and return the validation rules for this specific validation adapter.
*
* This method returns a collection of rules, in the format required by the specified plugin.
* @param string $format The format in which to return the rules. For example, "json" or "html5".
* @param bool $stringEncode In the case of JSON rules, specify whether or not to encode the result as a serialized JSON string.
* @return mixed The validation rule collection.
*
* @param string $format The format in which to return the rules. For example, "json" or "html5".
* @param bool $stringEncode In the case of JSON rules, specify whether or not to encode the result as a serialized JSON string.
*
* @return mixed The validation rule collection.
*/
abstract public function rules($format = 'json', $stringEncode = true);
}
18 changes: 9 additions & 9 deletions src/Adapter/FormValidationAdapter.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
/**

/*
* UserFrosting Fortress (http://www.userfrosting.com)
*
* @link https://github.com/userfrosting/fortress
Expand All @@ -10,7 +11,7 @@
namespace UserFrosting\Fortress\Adapter;

/**
* FormValidationAdapter Class
* FormValidationAdapter Class.
*
* Loads validation rules from a schema and generates client-side rules compatible with the [FormValidation](http://formvalidation.io) JS plugin.
*
Expand All @@ -34,14 +35,15 @@ public function rules($format = 'json', $stringEncode = true)
* Generate FormValidation compatible rules from the specified RequestSchema, as a JSON document.
* See [this](http://formvalidation.io/getting-started/#calling-plugin) as an example of what this function will generate.
*
* @param bool $encode Specify whether to return a PHP array, or a JSON-encoded string.
* @param bool $encode Specify whether to return a PHP array, or a JSON-encoded string.
*
* @return string|array Returns either the array of rules, or a JSON-encoded representation of that array.
*/
public function formValidationRulesJson($encode = true)
{
$clientRules = [];
$implicitRules = [];
foreach ($this->schema->getSchema() as $fieldName => $field) {
foreach ($this->schema->all() as $fieldName => $field) {
$clientRules[$fieldName] = [];
$clientRules[$fieldName]['validators'] = [];

Expand Down Expand Up @@ -70,7 +72,7 @@ public function formValidationRulesHtml5()
{
$clientRules = [];
$implicitRules = [];
foreach ($this->schema->getSchema() as $fieldName => $field) {
foreach ($this->schema->all() as $fieldName => $field) {
$fieldRules = '';
$validators = $field['validators'];

Expand Down Expand Up @@ -243,13 +245,13 @@ private function transformValidator($fieldName, $validatorName, array $validator
break;
case 'member_of':
if (isset($validator['values'])) {
$params['regexp'] = '^' . implode('|', $validator['values']) . '$';
$params['regexp'] = '^'.implode('|', $validator['values']).'$';
}
$transformedValidatorJson['regexp'] = $params;
break;
case 'not_member_of':
if (isset($validator['values'])) {
$params['regexp'] = '^(?!' . implode('|', $validator['values']) . '$).*$';
$params['regexp'] = '^(?!'.implode('|', $validator['values']).'$).*$';
}
$transformedValidatorJson['regexp'] = $params;
break;
Expand All @@ -273,8 +275,6 @@ public function html5Attributes($validator, $prefix)
$msg = '';
if (isset($validator['message'])) {
$msg = $validator['message'];
} else {
return $attr;
}
$attr .= "$prefix-message=\"$msg\" ";
}
Expand Down
18 changes: 11 additions & 7 deletions src/Adapter/JqueryValidationAdapter.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
/**

/*
* UserFrosting Fortress (http://www.userfrosting.com)
*
* @link https://github.com/userfrosting/fortress
Expand All @@ -10,7 +11,7 @@
namespace UserFrosting\Fortress\Adapter;

/**
* JqueryValidationAdapter Class
* JqueryValidationAdapter Class.
*
* Loads validation rules from a schema and generates client-side rules compatible with the [jQuery Validation](http://http://jqueryvalidation.org) JS plugin.
*
Expand All @@ -22,7 +23,10 @@ class JqueryValidationAdapter extends ClientSideValidationAdapter
* Generate jQuery Validation compatible rules from the specified RequestSchema, as a JSON document.
* See [this](https://github.com/jzaefferer/jquery-validation/blob/master/demo/bootstrap/index.html#L168-L209) as an example of what this function will generate.
*
* @param bool $stringEncode Specify whether to return a PHP array, or a JSON-encoded string.
* @param string $format (Default: json)
* @param bool $stringEncode Specify whether to return a PHP array, or a JSON-encoded string. (default: false)
* @param string $arrayPrefix (Default: '')
*
* @return string|array Returns either the array of rules, or a JSON-encoded representation of that array.
*/
public function rules($format = 'json', $stringEncode = false, $arrayPrefix = '')
Expand All @@ -35,7 +39,7 @@ public function rules($format = 'json', $stringEncode = false, $arrayPrefix = ''
foreach ($this->schema->all() as $fieldNameO => $field) {
$fieldNameOnly = $fieldNameO;
if ($arrayPrefix != '') {
$fieldName = $arrayPrefix . '[' . $fieldNameO . ']';
$fieldName = $arrayPrefix.'['.$fieldNameO.']';
} else {
$fieldName = $fieldNameO;
}
Expand Down Expand Up @@ -69,7 +73,7 @@ public function rules($format = 'json', $stringEncode = false, $arrayPrefix = ''
}
$result = [
'rules' => $clientRules,
'messages' => $clientMessages
'messages' => $clientMessages,
];

if ($stringEncode) {
Expand Down Expand Up @@ -106,7 +110,7 @@ private function transformValidator($fieldName, $validatorName, array $validator
if (isset($validator['min']) && isset($validator['max'])) {
$transformedValidatorJson['rangelength'] = [
$validator['min'],
$validator['max']
$validator['max'],
];
} elseif (isset($validator['min'])) {
$transformedValidatorJson['minlength'] = $validator['min'];
Expand Down Expand Up @@ -152,7 +156,7 @@ private function transformValidator($fieldName, $validatorName, array $validator
if (isset($validator['min']) && isset($validator['max'])) {
$transformedValidatorJson['range'] = [
$validator['min'],
$validator['max']
$validator['max'],
];
} elseif (isset($validator['min'])) {
$transformedValidatorJson['min'] = $validator['min'];
Expand Down
17 changes: 11 additions & 6 deletions src/RequestDataTransformer.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
/**

/*
* UserFrosting Fortress (http://www.userfrosting.com)
*
* @link https://github.com/userfrosting/fortress
Expand All @@ -13,7 +14,7 @@
use UserFrosting\Support\Exception\BadRequestException;

/**
* RequestDataTransformer Class
* RequestDataTransformer Class.
*
* Perform a series of transformations on a set of data fields, as specified by a RequestSchemaInterface.
*
Expand All @@ -27,7 +28,7 @@ class RequestDataTransformer implements RequestDataTransformerInterface
protected $schema;

/**
* @var HTMLPurifier
* @var \HTMLPurifier
*/
protected $purifier;

Expand Down Expand Up @@ -77,6 +78,7 @@ public function transform(array $data, $onUnexpectedVar = 'skip')
break;
case 'error':
$e = new BadRequestException("The field '$name' is not a valid input field.");

throw $e;
break;
case 'skip':
Expand Down Expand Up @@ -133,7 +135,8 @@ public function transformField($name, $value)
/**
* Autodetect if a field is an array or scalar, and filter appropriately.
*
* @param mixed $value
* @param mixed $value
*
* @return mixed
*/
private function escapeHtmlCharacters($value)
Expand All @@ -148,7 +151,8 @@ private function escapeHtmlCharacters($value)
/**
* Autodetect if a field is an array or scalar, and filter appropriately.
*
* @param mixed $value
* @param mixed $value
*
* @return mixed
*/
private function purgeHtmlCharacters($value)
Expand All @@ -163,7 +167,8 @@ private function purgeHtmlCharacters($value)
/**
* Autodetect if a field is an array or scalar, and filter appropriately.
*
* @param mixed $value
* @param mixed $value
*
* @return mixed
*/
private function trim($value)
Expand Down
23 changes: 13 additions & 10 deletions src/RequestDataTransformerInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
/**

/*
* UserFrosting Fortress (http://www.userfrosting.com)
*
* @link https://github.com/userfrosting/fortress
Expand All @@ -12,7 +13,7 @@
use UserFrosting\Fortress\RequestSchema\RequestSchemaInterface;

/**
* RequestDataTransformer Interface
* RequestDataTransformer Interface.
*
* Perform a series of transformations on a set of data fields, as specified by a RequestSchemaInterface.
*
Expand All @@ -33,20 +34,22 @@ public function setSchema(RequestSchemaInterface $schema);
* Example transformations: escape/purge/purify HTML entities
* Also, set any default values for unspecified fields.
*
* @param array $data The array of data to be transformed.
* @param string $onUnexpectedVar[optional] Determines what to do when a field is encountered that is not in the schema. Set to one of:
* "allow": Treat the field as any other, allowing the value through.
* "error": Raise an exception.
* "skip" (default): Quietly ignore the field. It will not be part of the transformed data array.
* @return array The array of transformed data, mapping field names => values.
* @param array $data The array of data to be transformed.
* @param string $onUnexpectedVar[optional] Determines what to do when a field is encountered that is not in the schema. Set to one of:
* "allow": Treat the field as any other, allowing the value through.
* "error": Raise an exception.
* "skip" (default): Quietly ignore the field. It will not be part of the transformed data array.
*
* @return array The array of transformed data, mapping field names => values.
*/
public function transform(array $data, $onUnexpectedVar);

/**
* Transform a raw field value.
*
* @param string $name The name of the field to transform, as specified in the schema.
* @param string $value The value to be transformed.
* @param string $name The name of the field to transform, as specified in the schema.
* @param string $value The value to be transformed.
*
* @return string The transformed value.
*/
public function transformField($name, $value);
Expand Down
Loading

0 comments on commit f0e4de4

Please sign in to comment.