Skip to content

Commit 7965ed1

Browse files
author
Oscar Otero
committed
v2
1 parent 2080091 commit 7965ed1

File tree

9 files changed

+66
-196
lines changed

9 files changed

+66
-196
lines changed

.gitattributes

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
* text=auto eol=lf
22

3-
/tests export-ignore
4-
.editorconfig export-ignore
5-
.gitattributes export-ignore
6-
.gitignore export-ignore
7-
.travis.yml export-ignore
8-
phpunit.xml export-ignore
9-
phpcs.xml export-ignore
3+
/tests export-ignore
4+
.editorconfig export-ignore
5+
.gitattributes export-ignore
6+
.gitignore export-ignore
7+
.php_cs export-ignore
8+
.travis.yml export-ignore
9+
phpcs.xml.dist export-ignore
10+
phpunit.xml.dist export-ignore

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
vendor
22
composer.lock
3-
.php_cs.cache
43
coverage
5-
.phpunit.result.cache
4+
*.cache

.php_cs

Lines changed: 8 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,10 @@
11
<?php
22

3-
$finder = PhpCsFixer\Finder::create()
4-
->files()
5-
->name('*.php')
6-
->in(__DIR__ . '/src')
7-
->in(__DIR__ . '/tests')
8-
;
9-
10-
return PhpCsFixer\Config::create()
11-
->setRules(array(
12-
'@PSR2' => true,
13-
'array_syntax' => ['syntax' => 'short'],
14-
'binary_operator_spaces' => ['align_double_arrow' => false, 'align_equals' => false],
15-
'blank_line_after_namespace' => true,
16-
'blank_line_after_opening_tag' => false,
17-
'blank_line_before_return' => false,
18-
'braces' => ['allow_single_line_closure' => false],
19-
'cast_spaces' => true,
20-
'class_definition' => ['singleLine' => false, 'singleItemSingleLine' => true, 'multiLineExtendsEachSingleLine' => true],
21-
'class_keyword_remove' => false,
22-
'combine_consecutive_unsets' => true,
23-
'concat_space' => false,
24-
'declare_equal_normalize' => ['space' => 'single'],
25-
'declare_strict_types' => false,
26-
'elseif' => true,
27-
'encoding' => true,
28-
'full_opening_tag' => true,
29-
'function_declaration' => true,
30-
'function_typehint_space' => true,
31-
'general_phpdoc_annotation_remove' => ['expectedExceptionMessageRegExp', 'expectedException', 'expectedExceptionMessage'],
32-
'hash_to_slash_comment' => true,
33-
'header_comment' => false,
34-
'heredoc_to_nowdoc' => true,
35-
'include' => true,
36-
'indentation_type' => true,
37-
'line_ending' => true,
38-
'linebreak_after_opening_tag' => true,
39-
'lowercase_cast' => true,
40-
'lowercase_constants' => true,
41-
'lowercase_keywords' => true,
42-
'mb_str_functions' => false,
43-
'method_argument_space' => true,
44-
'method_separation' => true,
45-
'native_function_casing' => true,
46-
'native_function_invocation' => false,
47-
'new_with_braces' => true,
48-
'no_blank_lines_after_class_opening' => true,
49-
'no_blank_lines_after_phpdoc' => false,
50-
'no_blank_lines_before_namespace' => false,
51-
'no_closing_tag' => true,
52-
'no_empty_comment' => true,
53-
'no_empty_phpdoc' => true,
54-
'no_empty_statement' => true,
55-
'no_extra_consecutive_blank_lines' => ['break', 'continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block'],
56-
'no_leading_import_slash' => true,
57-
'no_leading_namespace_whitespace' => true,
58-
'no_mixed_echo_print' => ['use' => 'echo'],
59-
'no_multiline_whitespace_around_double_arrow' => true,
60-
'no_multiline_whitespace_before_semicolons' => true,
61-
'no_short_bool_cast' => true,
62-
'no_short_echo_tag' => true,
63-
'no_singleline_whitespace_before_semicolons' => true,
64-
'no_spaces_after_function_name' => true,
65-
'no_spaces_around_offset' => true,
66-
'no_spaces_inside_parenthesis' => true,
67-
'no_trailing_comma_in_list_call' => true,
68-
'no_trailing_comma_in_singleline_array' => true,
69-
'no_trailing_whitespace' => true,
70-
'no_trailing_whitespace_in_comment' => true,
71-
'no_unneeded_control_parentheses' => true,
72-
'no_unused_imports' => true,
73-
'no_useless_else' => true,
74-
'no_useless_return' => true,
75-
'no_whitespace_before_comma_in_array' => true,
76-
'no_whitespace_in_blank_line' => true,
77-
'normalize_index_brace' => true,
78-
'not_operator_with_space' => false,
79-
'not_operator_with_successor_space' => false,
80-
'object_operator_without_whitespace' => true,
81-
'ordered_class_elements' => false,
82-
'ordered_imports' => true,
83-
'php_unit_fqcn_annotation' => true,
84-
'php_unit_strict' => false,
85-
'phpdoc_add_missing_param_annotation' => true,
86-
'phpdoc_align' => true,
87-
'phpdoc_inline_tag' => true,
88-
'phpdoc_no_access' => true,
89-
'phpdoc_no_alias_tag' => ['property-read' => 'property', 'property-write' => 'property', 'type' => 'var'],
90-
'phpdoc_no_empty_return' => true,
91-
'phpdoc_no_package' => true,
92-
'phpdoc_no_useless_inheritdoc' => true,
93-
'phpdoc_order' => true,
94-
'phpdoc_return_self_reference' => true,
95-
'phpdoc_scalar' => true,
96-
'phpdoc_separation' => false,
97-
'phpdoc_single_line_var_spacing' => true,
98-
'phpdoc_summary' => false,
99-
'phpdoc_to_comment' => true,
100-
'phpdoc_trim' => true,
101-
'phpdoc_types' => true,
102-
'phpdoc_var_without_name' => true,
103-
'pow_to_exponentiation' => false,
104-
'pre_increment' => true,
105-
'protected_to_private' => true,
106-
'return_type_declaration' => true,
107-
'semicolon_after_instruction' => true,
108-
'short_scalar_cast' => true,
109-
'single_blank_line_at_eof' => true,
110-
'single_blank_line_before_namespace' => false,
111-
'single_class_element_per_statement' => true,
112-
'single_import_per_statement' => true,
113-
'single_line_after_imports' => true,
114-
'single_quote' => true,
115-
'space_after_semicolon' => true,
116-
'standardize_not_equals' => true,
117-
'strict_param' => false,
118-
'switch_case_semicolon_to_colon' => true,
119-
'switch_case_space' => true,
120-
'ternary_operator_spaces' => true,
121-
'ternary_to_null_coalescing' => false,
122-
'trailing_comma_in_multiline_array' => true,
123-
'trim_array_spaces' => true,
124-
'unary_operator_spaces' => true,
125-
'visibility_required' => true,
126-
'whitespace_after_comma_in_array' => true,
127-
))
128-
->setFinder($finder)
129-
;
3+
return My\PhpCsFixerConfig::create()
4+
->setFinder(
5+
PhpCsFixer\Finder::create()
6+
->files()
7+
->name('*.php')
8+
->in(__DIR__.'/src')
9+
->in(__DIR__.'/tests')
10+
);

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ language: php
22
sudo: false
33

44
php:
5-
- 7.0
6-
- 7.1
75
- 7.2
6+
- 7.3
87

98
before_script:
109
- composer self-update

CHANGELOG.md

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,85 +2,65 @@
22

33
All notable changes to this project will be documented in this file.
44

5-
The format is based on [Keep a Changelog](http://keepachangelog.com/)
5+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8-
## [Unreleased]
9-
10-
### Fixed
11-
12-
- Use `phpstan` as a dev dependency to detect bugs
13-
8+
## [2.0.0] - 2019-11-30
149
### Added
10+
- Added argument to `redirect()` option to define a `responseFactory`
1511

16-
- Added `responseFactory` option to `__construct`
12+
### Removed
13+
- Support for PHP 7.0 and 7.1
14+
- `responseFactory` option
1715

1816
## [1.1.0] - 2018-08-04
19-
2017
### Added
21-
2218
- PSR-17 support
2319
- New option `responseFactory`
2420

2521
## [1.0.0] - 2018-01-24
26-
2722
### Added
28-
2923
- Improved testing and added code coverage reporting
3024
- Added tests for PHP 7.2
3125

3226
### Changed
33-
3427
- Upgraded to the final version of PSR-15 `psr/http-server-middleware`
3528

3629
### Fixed
37-
3830
- Updated license year
3931

4032
## [0.5.0] - 2017-11-13
41-
4233
### Changed
43-
4434
- Replaced `http-interop/http-middleware` with `http-interop/http-server-middleware`.
4535

4636
### Removed
47-
4837
- Removed support for PHP 5.x.
4938

5039
## [0.4.0] - 2017-09-21
51-
5240
### Changed
53-
5441
- Append `.dist` suffix to phpcs.xml and phpunit.xml files
5542
- Changed the configuration of phpcs and php_cs
5643
- Upgraded phpunit to the latest version and improved its config file
5744
- Updated to `http-interop/http-middleware#0.5`
5845

5946
## [0.3.0] - 2016-12-26
60-
6147
### Changed
62-
6348
- Updated tests
6449
- Updated to `http-interop/http-middleware#0.4`
6550
- Updated `friendsofphp/php-cs-fixer#2.0`
6651

6752
## [0.2.0] - 2016-11-22
68-
6953
### Changed
70-
7154
- Updated to `http-interop/http-middleware#0.3`
7255

7356
## [0.1.1] - 2016-10-01
74-
7557
### Fixed
76-
7758
- Changed `composer.json` to include the latest version of `middlewares/utils 0.*`
7859

7960
## 0.1.0 - 2016-09-30
80-
8161
First version
8262

83-
[Unreleased]: https://github.com/middlewares/trailing-slash/compare/v1.1.0...HEAD
63+
[2.0.0]: https://github.com/middlewares/trailing-slash/compare/v1.1.0...v2.0.0
8464
[1.1.0]: https://github.com/middlewares/trailing-slash/compare/v1.0.0...v1.1.0
8565
[1.0.0]: https://github.com/middlewares/trailing-slash/compare/v0.5.0...v1.0.0
8666
[0.5.0]: https://github.com/middlewares/trailing-slash/compare/v0.4.0...v0.5.0

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2018
3+
Copyright (c) 2019
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
[![Build Status][ico-travis]][link-travis]
66
[![Quality Score][ico-scrutinizer]][link-scrutinizer]
77
[![Total Downloads][ico-downloads]][link-downloads]
8-
[![SensioLabs Insight][ico-sensiolabs]][link-sensiolabs]
98

109
Middleware to normalize the trailing slash of the uri path. By default removes the slash so, for example, `/post/23/` is converted to `/post/23`. Useful if you have problems with the router.
1110

1211
## Requirements
1312

14-
* PHP >= 7.0
13+
* PHP >= 7.2
1514
* A [PSR-7 http library](https://github.com/middlewares/awesome-psr15-middlewares#psr-7-implementations)
1615
* A [PSR-15 middleware dispatcher](https://github.com/middlewares/awesome-psr15-middlewares#dispatcher)
1716

@@ -34,19 +33,37 @@ $dispatcher = new Dispatcher([
3433
$response = $dispatcher->dispatch(new ServerRequest());
3534
```
3635

37-
## Options
36+
## Usage
3837

39-
#### `__construct(booll $trailingSlash = false)`
38+
By default, this middleware removes the trailing slash of the uri path. Set `true` to the constructor's first argument to add instead remove:
4039

41-
Set `true` to add the slash instead remove so, for example, `post/23` is converted to `/post/23/`. Note that if the path contains an extension, the slash is **NOT** added. For example, `images/image.png` remains the same, instead be converted to `images/image.png/`.
40+
```php
41+
//Removes the slash, so /post/23/ is converted to /post/23
42+
$slash = new Middlewares\TrailinSlash();
43+
44+
//Force the slash, so /post/23 is converted to /post/23/
45+
$slash = new Middlewares\TrailinSlash(true);
46+
```
4247

43-
#### `redirect(true)`
48+
Of course, if the path contains an extension, the slash is **NOT** added. For example, `images/image.png` remains the same, instead be converted to `images/image.png/`.
4449

45-
Set this option to return a `301` response redirecting to the new path
50+
### redirect
4651

47-
#### `responseFactory(Psr\Http\Message\ResponseFactoryInterface $responseFactory)`
52+
If the path must be converted, this option returns a `301` response redirecting to the new path. Optionally, you can provide a `Psr\Http\Message\ResponseFactoryInterface` that will be used to create the redirect response. If it's not defined, [Middleware\Utils\Factory](https://github.com/middlewares/utils#factory) will be used to detect it automatically.
53+
54+
```php
55+
$responseFactory = new MyOwnResponseFactory();
56+
57+
//Simply removes the slash
58+
$slash = new Middlewares\TrailinSlash();
59+
60+
//Returns a redirect response to the new path
61+
$slash = (new Middlewares\TrailinSlash())->redirect();
62+
63+
//Returns a redirect response to the new path using a specific response factory
64+
$slash = (new Middlewares\TrailinSlash())->redirect($responseFactory);
65+
```
4866

49-
A PSR-17 factory to create `301` responses.
5067
---
5168

5269
Please see [CHANGELOG](CHANGELOG.md) for more information about recent changes and [CONTRIBUTING](CONTRIBUTING.md) for contributing details.
@@ -58,10 +75,8 @@ The MIT License (MIT). Please see [LICENSE](LICENSE) for more information.
5875
[ico-travis]: https://img.shields.io/travis/middlewares/trailing-slash/master.svg?style=flat-square
5976
[ico-scrutinizer]: https://img.shields.io/scrutinizer/g/middlewares/trailing-slash.svg?style=flat-square
6077
[ico-downloads]: https://img.shields.io/packagist/dt/middlewares/trailing-slash.svg?style=flat-square
61-
[ico-sensiolabs]: https://img.shields.io/sensiolabs/i/82362f27-d8e9-4808-aed0-ce2cb5e339d4.svg?style=flat-square
6278

6379
[link-packagist]: https://packagist.org/packages/middlewares/trailing-slash
6480
[link-travis]: https://travis-ci.org/middlewares/trailing-slash
6581
[link-scrutinizer]: https://scrutinizer-ci.com/g/middlewares/trailing-slash
6682
[link-downloads]: https://packagist.org/packages/middlewares/trailing-slash
67-
[link-sensiolabs]: https://insight.sensiolabs.com/projects/82362f27-d8e9-4808-aed0-ce2cb5e339d4

composer.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717
"issues": "https://github.com/middlewares/trailing-slash/issues"
1818
},
1919
"require": {
20-
"php": "^7.0",
21-
"middlewares/utils": "^2.1",
20+
"php": "^7.2",
21+
"middlewares/utils": "^3.0",
2222
"psr/http-server-middleware": "^1.0"
2323
},
2424
"require-dev": {
25-
"phpunit/phpunit": "^6.0|^7.0",
26-
"zendframework/zend-diactoros": "^1.3",
25+
"phpunit/phpunit": "^8.1",
26+
"zendframework/zend-diactoros": "^2.2",
2727
"friendsofphp/php-cs-fixer": "^2.0",
2828
"squizlabs/php_codesniffer": "^3.0",
29-
"phpstan/phpstan": "^0.9.2|^0.10.3"
29+
"oscarotero/php-cs-fixer-config": "^1.0"
3030
},
3131
"autoload": {
3232
"psr-4": {
@@ -43,8 +43,7 @@
4343
"phpunit --coverage-text",
4444
"phpcs"
4545
],
46-
"cs-fix": "php-cs-fixer fix .",
47-
"coverage": "phpunit --coverage-html=coverage",
48-
"analyse": "phpstan analyse --no-progress --level 7 src"
46+
"cs-fix": "php-cs-fixer fix",
47+
"coverage": "phpunit --coverage-html=coverage"
4948
}
5049
}

0 commit comments

Comments
 (0)