Skip to content

Commit 2ee59e9

Browse files
committed
Merge branch 'migrate-laminas'
* migrate-laminas: rename to mezzio for config cs kahlan config migrate to laminas
2 parents 79cd77f + 9179bfd commit 2ee59e9

15 files changed

+93
-85
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ CONTRIBUTING
33
To contribute, you can send pull requests with :
44

55
- Typo fix.
6-
- Use [Zend Coding Standard](https://github.com/zendframework/zend-coding-standard).
6+
- Use [Laminas Coding Standard](https://github.com/laminas/laminas-coding-standard).
77
- patch(es) need new/updated test(s).
88
- new feature(s) need test(s).
99

README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ ForceHttpsModule
1010
Introduction
1111
------------
1212

13-
ForceHttpsModule is a configurable module for force https in your [ZF Mvc](https://zendframework.github.io/tutorials/getting-started/overview/) and [ZF Expressive](https://zendframework.github.io/zend-expressive/) Application.
13+
ForceHttpsModule is a configurable module for force https in your [Laminas Mvc](https://docs.laminas.dev/tutorials/) and [Mezzio](https://docs.mezzio.dev/mezzio/) Application.
1414

15-
> This is README for version ^2.0 which only support ZF3 and ZF Expressive version 3 with php ^7.1.
15+
> This is README for version ^3.0 which only support Laminas Mvc version 3 and Mezzio version 3 with php ^7.1.
16+
17+
> For version ^2.0, you can read at [version 2 readme](https://github.com/samsonasik/ForceHttpsModule/tree/2.x.x) which only support ZF3 and ZF Expressive version 3 with php ^7.1.
1618
1719
> For version 1, you can read at [version 1 readme](https://github.com/samsonasik/ForceHttpsModule/tree/1.x.x) which still support ZF2 and ZF Expressive version 1 and 2 with php ^5.6|^7.0 support.
1820
@@ -39,7 +41,7 @@ composer require samsonasik/force-https-module
3941

4042
**2. Copy config**
4143

42-
***a. For [ZF3 Mvc](https://zendframework.github.io/tutorials/getting-started/overview/) application, copy `force-https-module.local.php.dist` config to your local's autoload and configure it***
44+
***a. For [Laminas Mvc](https://docs.laminas.dev/tutorials/) application, copy `force-https-module.local.php.dist` config to your local's autoload and configure it***
4345

4446
| source | destination |
4547
|------------------------------------------------------------------------------|---------------------------------------------|
@@ -51,23 +53,23 @@ Or run copy command:
5153
cp vendor/samsonasik/force-https-module/config/force-https-module.local.php.dist config/autoload/force-https-module.local.php
5254
```
5355

54-
***b. For [ZF Expressive](https://zendframework.github.io/zend-expressive/) application, copy `expressive-force-https-module.local.php.dist` config to your local's autoload and configure it***
56+
***b. For [Mezzio](https://docs.mezzio.dev/mezzio/) application, copy `mezzio-force-https-module.local.php.dist` config to your local's autoload and configure it***
5557

5658
| source | destination |
5759
|------------------------------------------------------------------------------|---------------------------------------------|
58-
| vendor/samsonasik/force-https-module/config/expressive-force-https-module.local.php.dist | config/autoload/expressive-force-https-module.local.php |
60+
| vendor/samsonasik/force-https-module/config/mezzio-force-https-module.local.php.dist | config/autoload/mezzio-force-https-module.local.php |
5961

6062
Or run copy command:
6163

6264
```sh
63-
cp vendor/samsonasik/force-https-module/config/expressive-force-https-module.local.php.dist config/autoload/expressive-force-https-module.local.php
65+
cp vendor/samsonasik/force-https-module/config/mezzio-force-https-module.local.php.dist config/autoload/mezzio-force-https-module.local.php
6466
```
6567

6668
When done, you can modify your local config:
6769

6870
```php
6971
<?php
70-
// config/autoload/force-https-module.local.php or config/autoload/expressive-force-https-module.local.php
72+
// config/autoload/force-https-module.local.php or config/autoload/mezzio-force-https-module.local.php
7173
return [
7274
'force-https-module' => [
7375
'enable' => true,
@@ -97,7 +99,7 @@ return [
9799

98100
**3. Lastly, enable it**
99101

100-
***a. For ZF Mvc application***
102+
***a. For Laminas Mvc application***
101103

102104
```php
103105
// config/modules.config.php or config/application.config.php
@@ -107,9 +109,9 @@ return [
107109
],
108110
```
109111

110-
***b. For ZF Expressive application***
112+
***b. For Mezzio application***
111113

112-
For [zend-expressive-skeleton](https://github.com/zendframework/zend-expressive-skeleton) ^3.0, you need to open `config/pipeline.php` and add:
114+
For [mezzio-skeleton](https://github.com/mezzio/mezzio-skeleton) ^3.0, you need to open `config/pipeline.php` and add:
113115

114116
```php
115117
$app->pipe(ForceHttpsModule\Middleware\ForceHttps::class);

composer.json

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
{
22
"name": "samsonasik/force-https-module",
33
"type": "library",
4-
"description": "Force Https Module",
4+
"description": "Force Https Module for Laminas Mvc and Mezzio application",
55
"keywords": [
6-
"zf2",
7-
"zf3",
6+
"laminas3",
87
"expressive",
98
"middleware",
109
"force",
@@ -27,20 +26,20 @@
2726
"require": {
2827
"php": "^7.1",
2928
"webmozart/assert": "^1.4",
30-
"zendframework/zend-console": "^2.5"
29+
"laminas/laminas-console": "^2.5"
3130
},
3231
"conflict": {
33-
"zendframework/zend-expressive": "<3.0",
34-
"zendframework/zend-mvc": "<3.0"
32+
"mezzio/mezzio": "<3.0",
33+
"laminas/laminas-mvc": "<3.0"
3534
},
3635
"require-dev": {
3736
"kahlan/kahlan": "^4.0",
3837
"php-coveralls/php-coveralls": "^2.1",
3938
"phpstan/phpstan": "^0.10.8",
4039
"phpstan/phpstan-webmozart-assert": "^0.10.0",
41-
"zendframework/zend-coding-standard": "^1.0",
42-
"zendframework/zend-expressive": "^3.0",
43-
"zendframework/zend-mvc": "^3.0"
40+
"laminas/laminas-coding-standard": "^2.0",
41+
"mezzio/mezzio": "^3.0",
42+
"laminas/laminas-mvc": "^3.0"
4443
},
4544
"config": {
4645
"bin-dir": "bin",
@@ -64,5 +63,7 @@
6463
"scripts": {
6564
"cs-check": "phpcs",
6665
"cs-fix": "phpcbf"
67-
}
66+
},
67+
"minimum-stability": "alpha",
68+
"prefer-stable": true
6869
}
File renamed without changes.

kahlan-config.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
file_put_contents('vendor/laminas/laminas-zendframework-bridge/src/autoload.php', '<?php');

phpcs.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
2-
<ruleset name="Zend Framework Coding Standard">
3-
<rule ref="./vendor/zendframework/zend-coding-standard/ruleset.xml"/>
2+
<ruleset name="Laminas Coding Standard">
3+
<rule ref="./vendor/laminas/laminas-coding-standard/src/LaminasCodingStandard/ruleset.xml"/>
44

55
<!-- Paths to check -->
66
<file>src</file>

spec/Listener/ForceHttpsSpec.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
use Kahlan\Plugin\Double;
77
use Kahlan\Plugin\Quit;
88
use Kahlan\QuitException;
9-
use Zend\Console\Console;
10-
use Zend\EventManager\EventManagerInterface;
11-
use Zend\Http\PhpEnvironment\Request;
12-
use Zend\Http\PhpEnvironment\Response;
13-
use Zend\Mvc\MvcEvent;
14-
use Zend\Router\RouteMatch;
15-
use Zend\Uri\Uri;
9+
use Laminas\Console\Console;
10+
use Laminas\EventManager\EventManagerInterface;
11+
use Laminas\Http\PhpEnvironment\Request;
12+
use Laminas\Http\PhpEnvironment\Response;
13+
use Laminas\Mvc\MvcEvent;
14+
use Laminas\Router\RouteMatch;
15+
use Laminas\Uri\Uri;
1616

1717
describe('ForceHttps', function () {
1818

spec/Middleware/ForceHttpsFactorySpec.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use ForceHttpsModule\Middleware\ForceHttpsFactory;
77
use Kahlan\Plugin\Double;
88
use Psr\Container\ContainerInterface;
9-
use Zend\Expressive\Router\RouterInterface;
9+
use Mezzio\Router\RouterInterface;
1010

1111
describe('ForceHttpsFactory', function () {
1212

spec/Middleware/ForceHttpsSpec.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
use Psr\Http\Message\UriInterface;
1010
use Psr\Http\Server\MiddlewareInterface;
1111
use Psr\Http\Server\RequestHandlerInterface;
12-
use Zend\Expressive\Router\Route;
13-
use Zend\Expressive\Router\RouteResult;
14-
use Zend\Expressive\Router\RouterInterface;
12+
use Mezzio\Router\Route;
13+
use Mezzio\Router\RouteResult;
14+
use Mezzio\Router\RouterInterface;
1515

1616
describe('ForceHttps', function () {
1717

src/HttpsTrait.php

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
namespace ForceHttpsModule;
66

7-
use Psr\Http\Message\ResponseInterface;
7+
use Laminas\Router\RouteMatch;
8+
use Mezzio\Router\RouteResult;
89
use Webmozart\Assert\Assert;
9-
use Zend\Expressive\Router\RouteResult;
10-
use Zend\Http\PhpEnvironment\Response;
11-
use Zend\Router\RouteMatch;
10+
11+
use function in_array;
12+
use function strpos;
13+
use function substr_replace;
1214

1315
trait HttpsTrait
1416
{
@@ -18,7 +20,7 @@ trait HttpsTrait
1820
/** @var bool */
1921
private $alreadyHasWwwPrefix;
2022

21-
private function isSchemeHttps(string $uriScheme) : bool
23+
private function isSchemeHttps(string $uriScheme): bool
2224
{
2325
return $uriScheme === 'https';
2426
}
@@ -28,7 +30,7 @@ private function isSchemeHttps(string $uriScheme) : bool
2830
*
2931
* @param RouteMatch|RouteResult|null $match
3032
*/
31-
private function isGoingToBeForcedToHttps($match = null) : bool
33+
private function isGoingToBeForcedToHttps($match = null): bool
3234
{
3335
if ($match === null || ($match instanceof RouteResult && $match->isFailure())) {
3436
return $this->config['allow_404'] ?? false;
@@ -39,7 +41,7 @@ private function isGoingToBeForcedToHttps($match = null) : bool
3941
}
4042

4143
Assert::notNull($match);
42-
if (! \in_array($match->getMatchedRouteName(), $this->config['force_specific_routes'])) {
44+
if (! in_array($match->getMatchedRouteName(), $this->config['force_specific_routes'])) {
4345
return false;
4446
}
4547

@@ -50,9 +52,8 @@ private function isGoingToBeForcedToHttps($match = null) : bool
5052
* Check if Setup Strict-Transport-Security need to be skipped.
5153
*
5254
* @param RouteMatch|RouteResult|null $match
53-
*
5455
*/
55-
private function isSkippedHttpStrictTransportSecurity(string $uriScheme, $match = null) : bool
56+
private function isSkippedHttpStrictTransportSecurity(string $uriScheme, $match = null): bool
5657
{
5758
return ! $this->isSchemeHttps($uriScheme) ||
5859
! $this->isGoingToBeForcedToHttps($match) ||
@@ -65,43 +66,40 @@ private function isSkippedHttpStrictTransportSecurity(string $uriScheme, $match
6566
/**
6667
* Add www. prefix when use add_www_prefix = true
6768
*/
68-
private function withWwwPrefixWhenRequired(string $httpsRequestUri) : string
69+
private function withWwwPrefixWhenRequired(string $httpsRequestUri): string
6970
{
7071
$this->needsWwwPrefix = $this->config['add_www_prefix'] ?? false;
71-
$this->alreadyHasWwwPrefix = \strpos($httpsRequestUri, 'www.', 8) === 8;
72+
$this->alreadyHasWwwPrefix = strpos($httpsRequestUri, 'www.', 8) === 8;
7273

7374
if (! $this->needsWwwPrefix || $this->alreadyHasWwwPrefix) {
7475
return $httpsRequestUri;
7576
}
7677

77-
return \substr_replace($httpsRequestUri, 'www.', 8, 0);
78+
return substr_replace($httpsRequestUri, 'www.', 8, 0);
7879
}
7980

8081
/**
8182
* Remove www. prefix when use remove_www_prefix = true
8283
* It only works if previous's config 'add_www_prefix' => false
8384
*/
84-
private function withoutWwwPrefixWhenNotRequired(string $httpsRequestUri) : string
85+
private function withoutWwwPrefixWhenNotRequired(string $httpsRequestUri): string
8586
{
8687
if ($this->needsWwwPrefix) {
8788
return $httpsRequestUri;
8889
}
8990

90-
$removeWwwPrefix = $this->config['remove_www_prefix'] ?? false;
91+
$removeWwwPrefix = $this->config['remove_www_prefix'] ?? false;
9192
if (! $removeWwwPrefix || ! $this->alreadyHasWwwPrefix) {
9293
return $httpsRequestUri;
9394
}
9495

95-
return \substr_replace($httpsRequestUri, '', 8, 4);
96+
return substr_replace($httpsRequestUri, '', 8, 4);
9697
}
9798

9899
/**
99100
* Get Final Request Uri with configured with or without www prefix
100-
*
101-
* @param string $httpsRequestUri
102-
* @return string
103101
*/
104-
private function getFinalhttpsRequestUri(string $httpsRequestUri) : string
102+
private function getFinalhttpsRequestUri(string $httpsRequestUri): string
105103
{
106104
$httpsRequestUri = $this->withWwwPrefixWhenRequired($httpsRequestUri);
107105
$httpsRequestUri = $this->withoutWwwPrefixWhenNotRequired($httpsRequestUri);

0 commit comments

Comments
 (0)