Skip to content

Commit b072ec0

Browse files
authored
Merge pull request #20 from samsonasik/php8
Add PHP 8 support
2 parents 90a79e5 + 819e348 commit b072ec0

File tree

6 files changed

+42
-17
lines changed

6 files changed

+42
-17
lines changed

.travis.yml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,35 @@
11
language: php
22

33
php:
4-
- 7.1
5-
- 7.2
64
- 7.3
75
- 7.4
6+
- 8.0
7+
8+
env:
9+
- XDEBUG_MODE=coverage
810

911
before_script:
1012
- mkdir -p build/logs
1113
- composer self-update
12-
- travis_retry composer install --prefer-source --no-interaction
14+
- |
15+
if [ $(phpenv version-name) != '8.0' ]; then
16+
travis_retry composer install --prefer-source --no-interaction
17+
fi
18+
if [ $(phpenv version-name) == '8.0' ]; then
19+
travis_retry composer install --prefer-source --no-interaction --ignore-platform-req=php
20+
fi
1321
- composer dump-autoload -o
1422

1523
script:
1624
- composer cs-check
1725
- bin/phpstan analyse src/ --level=max
18-
- bin/kahlan --coverage=4 --reporter=verbose --clover=build/logs/clover.xml
19-
- bin/php-coveralls -v --exclude-no-stmt
26+
- |
27+
if [ $(phpenv version-name) != '8.0' ]; then
28+
bin/kahlan --coverage=4 --reporter=verbose --clover=build/logs/clover.xml && bin/php-coveralls -v --exclude-no-stmt
29+
fi
30+
if [ $(phpenv version-name) == '8.0' ]; then
31+
bin/kahlan --reporter=verbose
32+
fi
2033
2134
notifications:
2235
email: false

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ ForceHttpsModule
22
================
33

44
[![Latest Version](https://img.shields.io/github/release/samsonasik/ForceHttpsModule.svg?style=flat-square)](https://github.com/samsonasik/ForceHttpsModule/releases)
5-
[![Build Status](https://travis-ci.org/samsonasik/ForceHttpsModule.svg?branch=master)](https://travis-ci.org/samsonasik/ForceHttpsModule)
5+
[![Build Status](https://travis-ci.com/samsonasik/ForceHttpsModule.svg?branch=master)](https://travis-ci.org/samsonasik/ForceHttpsModule)
66
[![Coverage Status](https://coveralls.io/repos/github/samsonasik/ForceHttpsModule/badge.svg?branch=master)](https://coveralls.io/github/samsonasik/ForceHttpsModule?branch=master)
77
[![PHPStan](https://img.shields.io/badge/PHPStan-enabled-brightgreen.svg?style=flat)](https://github.com/phpstan/phpstan)
88
[![Downloads](https://poser.pugx.org/samsonasik/force-https-module/downloads)](https://packagist.org/packages/samsonasik/force-https-module)

composer.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,18 @@
2424
}
2525
],
2626
"require": {
27-
"php": "^7.1",
28-
"webmozart/assert": "^1.4",
29-
"laminas/laminas-console": "^2.5"
27+
"php": "^7.3|~8.0",
28+
"webmozart/assert": "^1.9"
3029
},
3130
"conflict": {
3231
"mezzio/mezzio": "<3.0",
3332
"laminas/laminas-mvc": "<3.0"
3433
},
3534
"require-dev": {
36-
"kahlan/kahlan": "^4.0",
35+
"kahlan/kahlan": "^5.0",
3736
"php-coveralls/php-coveralls": "^2.1",
38-
"phpstan/phpstan": "^0.10.8",
39-
"phpstan/phpstan-webmozart-assert": "^0.10.0",
37+
"phpstan/phpstan": "^0.12",
38+
"phpstan/phpstan-webmozart-assert": "^0.12",
4039
"laminas/laminas-coding-standard": "^2.0",
4140
"mezzio/mezzio": "^3.0",
4241
"laminas/laminas-mvc": "^3.0"

phpstan.neon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
includes:
22
- vendor/phpstan/phpstan-webmozart-assert/extension.neon
33

4+
parameters:
5+
checkMissingIterableValueType: false
6+

spec/Listener/ForceHttpsSpec.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
it('not attach on route on console', function () {
2626

27-
Console::overrideIsConsole(true);
27+
allow(ForceHttps::class)->toReceive('isInConsole')->andReturn(true);
2828
$listener = new ForceHttps([
2929
'enable' => true,
3030
'force_all_routes' => true,
@@ -40,7 +40,7 @@
4040

4141
it('not attach when not enabled', function () {
4242

43-
Console::overrideIsConsole(false);
43+
allow(ForceHttps::class)->toReceive('isInConsole')->andReturn(false);
4444
$listener = new ForceHttps([
4545
'enable' => false,
4646
'force_all_routes' => true,
@@ -56,7 +56,7 @@
5656

5757
it('attach on route event on non-console and enable', function () {
5858

59-
Console::overrideIsConsole(false);
59+
allow(ForceHttps::class)->toReceive('isInConsole')->andReturn(false);
6060
$listener = new ForceHttps([
6161
'enable' => true,
6262
'force_all_routes' => true,

src/Listener/ForceHttps.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@
55
namespace ForceHttpsModule\Listener;
66

77
use ForceHttpsModule\HttpsTrait;
8-
use Laminas\Console\Console;
98
use Laminas\EventManager\AbstractListenerAggregate;
109
use Laminas\EventManager\EventManagerInterface;
1110
use Laminas\Http\PhpEnvironment\Request;
1211
use Laminas\Http\PhpEnvironment\Response;
1312
use Laminas\Mvc\MvcEvent;
1413
use Laminas\Router\RouteMatch;
1514

15+
use function defined;
1616
use function sprintf;
1717

18+
use const PHP_SAPI;
19+
1820
class ForceHttps extends AbstractListenerAggregate
1921
{
2022
use HttpsTrait;
@@ -32,7 +34,7 @@ public function __construct(array $config)
3234
*/
3335
public function attach(EventManagerInterface $events, $priority = 1): void
3436
{
35-
if (Console::isConsole() || ! $this->config['enable']) {
37+
if ($this->isInConsole() || ! $this->config['enable']) {
3638
return;
3739
}
3840

@@ -105,4 +107,12 @@ public function forceHttpsScheme(MvcEvent $e): void
105107

106108
exit(0);
107109
}
110+
111+
/**
112+
* Check if currently running in console
113+
*/
114+
private function isInConsole(): bool
115+
{
116+
return PHP_SAPI === 'cli' || defined('STDIN');
117+
}
108118
}

0 commit comments

Comments
 (0)