Skip to content

Commit 8e5ed05

Browse files
committed
Merge branch 'v4.x'
2 parents 78f325c + bb05dbc commit 8e5ed05

18 files changed

+359
-99
lines changed

Diff for: .github/workflows/code_analysis.yaml

+17-8
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ name: Code Analysis
44
on:
55
pull_request:
66
push:
7-
branches:
8-
- master
97

108

119
jobs:
@@ -23,10 +21,20 @@ jobs:
2321
php:
2422
- "7.4"
2523
- "8.0"
24+
- "8.1"
25+
- "8.2"
2626

27-
name: ${{ matrix.actions.name }} on PHP ${{ matrix.php }}
28-
runs-on: ubuntu-latest
27+
jwt:
28+
- name: JWT 5
29+
key: jtw5
30+
arg: '"firebase/php-jwt:^5.0"'
31+
32+
- name: JWT 6
33+
key: jwt6
34+
arg: '"firebase/php-jwt:^6.0"'
2935

36+
name: ${{ matrix.actions.name }} on PHP ${{ matrix.php }} with ${{ matrix.jwt.name }}
37+
runs-on: ubuntu-latest
3038

3139
steps:
3240
- name: Checkout
@@ -53,18 +61,19 @@ jobs:
5361
with:
5462
path: |
5563
${{ steps.composer-cache.outputs.dir }}
56-
key: ${{ runner.os }}-composer-data-${{ hashFiles('composer.json') }}-php-${{ matrix.php }}
64+
key: ${{ runner.os }}-composer-data-${{ hashFiles('composer.json') }}-php-${{ matrix.php }}-${{ matrix.jwt.name }}
5765

5866

5967
- uses: actions/cache@v2
6068
with:
6169
path: |
6270
**/composer.lock
63-
key: ${{ runner.os }}-composer-lock-${{ hashFiles('composer.json') }}-php-${{ matrix.php }}
71+
key: ${{ runner.os }}-composer-lock-${{ hashFiles('composer.json') }}-php-${{ matrix.php }}-${{ matrix.jwt.key }}
6472

6573

6674
- name: Install Composer
67-
run: composer install --no-progress
75+
run: composer update --no-progress --with ${{ matrix.jwt.arg }}
6876

6977

70-
- run: ${{ matrix.actions.run }}
78+
- name: Run job
79+
run: ${{ matrix.actions.run }}

Diff for: .phpstorm.meta.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<?php
22
/**
33
* The MIT License (MIT)
4-
* Copyright (c) 2022 Redbit s.r.o., Jakub Bouček
4+
* Copyright (c) 2023 Redbit s.r.o., Jakub Bouček
55
*/
66

77
namespace PHPSTORM_META {
8-
98
expectedArguments(
109
\Redbitcz\DebugMode\Detector::__construct(),
1110
0,
@@ -29,7 +28,7 @@
2928
);
3029

3130
expectedArguments(
32-
\Redbitcz\DebugMode\Detector::detectProductionMode(),
31+
\Redbitcz\DebugMode\Detector::detectProduction(),
3332
0,
3433
\Redbitcz\DebugMode\Detector::MODE_FULL,
3534
\Redbitcz\DebugMode\Detector::MODE_SIMPLE,
@@ -40,7 +39,7 @@
4039
);
4140

4241
expectedArguments(
43-
\Redbitcz\DebugMode\Plugin\SignedUrl::__construct(),
42+
\Redbitcz\DebugMode\Plugin\SignedUrl::create(),
4443
1,
4544
'ES384',
4645
'ES256',

Diff for: LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2022 Redbit s.r.o., Jakub Bouček
3+
Copyright (c) 2023 Redbit s.r.o., Jakub Bouček
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

Diff for: README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@ Package is optimized for invoking in very early lifecycle phase of your App
2020
## Requirements
2121
Package requires:
2222

23-
- PHP version at least 7.4
23+
- PHP version 7.4, 8.0, 8.1 or 8.2
2424

2525
Enabler requires:
2626

2727
- Temporary directory with writable access
2828

29+
SignUrl plugin requires:
30+
31+
- [Firebase JWT](https://github.com/firebase/php-jwt) v5 or v6
32+
2933
## Installation
3034
```shell
3135
composer require redbitcz/debug-mode-enabler
@@ -165,7 +169,7 @@ $detector->isDebugMode(); // <---- this invoke all Plugins
165169
`SignUrl` plugin provide secure way to share link with activated Debug Mode.
166170

167171
```php
168-
$plugin = new \Redbitcz\DebugMode\Plugin\SignedUrl('secretkey', 'HS256', 'https://myapp.cz');
172+
$plugin = \Redbitcz\DebugMode\Plugin\SignedUrl::create('secretkey', 'HS256', 'https://myapp.cz');
169173
$detector->appendPlugin($plugin);
170174
171175
$signedUrl = $plugin->signUrl('https://myapp.cz/failingPage', '+1 hour');

Diff for: composer.json

+16-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
{
22
"name": "redbitcz/debug-mode-enabler",
33
"description": "Debug mode enabler - safe and clean way to manage Debug Mode in your App",
4-
"keywords": ["debug"],
5-
"license": ["MIT"],
6-
"homepage": "https://github.com/redbitcz/php-debug-mode-enabler",
4+
"license": [
5+
"MIT"
6+
],
7+
"keywords": [
8+
"debug"
9+
],
710
"authors": [
811
{
912
"name": "Redbit s.r.o.",
@@ -14,18 +17,19 @@
1417
"homepage": "https://www.jakub-boucek.cz/"
1518
}
1619
],
20+
"homepage": "https://github.com/redbitcz/php-debug-mode-enabler",
1721
"require": {
18-
"php": ">=7.4",
22+
"php": "~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0",
1923
"ext-json": "*",
2024
"nette/utils": "^3.0"
2125
},
2226
"require-dev": {
23-
"firebase/php-jwt": "^5.0",
24-
"nette/tester": "^2.4",
25-
"phpstan/phpstan": "^0.12.98"
27+
"firebase/php-jwt": "^5.0 || ^6.0",
28+
"nette/tester": "2.4.3",
29+
"phpstan/phpstan": "1.9.14"
2630
},
2731
"suggest": {
28-
"firebase/php-jwt": "Optional, required for SignedUrl plugin"
32+
"firebase/php-jwt": "Optional, required for SignedUrl plugin, compatible with version 5.x and 6.x"
2933
},
3034
"autoload": {
3135
"psr-4": {
@@ -37,8 +41,11 @@
3741
"Redbitcz\\DebugModeTests\\": "tests/"
3842
}
3943
},
44+
"config": {
45+
"sort-packages": true
46+
},
4047
"scripts": {
41-
"phpstan": "phpstan analyze src -c phpstan.neon --level 8",
48+
"phpstan": "phpstan analyze -c phpstan.neon --level 5",
4249
"tester": "tester tests"
4350
}
4451
}

Diff for: phpstan.neon

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
parameters:
2+
paths:
3+
- src
4+
excludePaths:
5+
analyse:
6+
- src/Plugin/JWT/*
7+
28
ignoreErrors:
3-
-
9+
- # Too variants of parameters signature between PHP versions
410
message: '#Parameter \#3 \$options of function setcookie expects .+#'
11+
reportUnmatched: false
512
path: src/Enabler.php
613
count: 2
14+
15+
- # Weird bug by PhpStan - the `path` fiealt is still nullable
16+
message: '#Offset ''path'' on array.+ on left side of \?\? always exists and is not nullable\.#'
17+
path: src/Plugin/SignedUrl.php
18+
count: 1
19+
20+
-
21+
message: '#.+ has unknown class (OpenSSLAsymmetricKey|OpenSSLCertificate) as its type.#' # PHP 7 compatibility
22+
reportUnmatched: false
23+
24+
-
25+
message: '#.+ has invalid type (OpenSSLAsymmetricKey|OpenSSLCertificate).#' # PHP 7 compatibility
26+
reportUnmatched: false

Diff for: src/Detector.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* The MIT License (MIT)
4-
* Copyright (c) 2022 Redbit s.r.o., Jakub Bouček
4+
* Copyright (c) 2023 Redbit s.r.o., Jakub Bouček
55
*/
66

77
declare(strict_types=1);
@@ -254,10 +254,10 @@ public static function detect(
254254
* @param string|null $tempDir Path to temp directory. Optional, but required when Enabler mode is enabled
255255
* @param bool|null $default Default value when no method matches
256256
*/
257-
public static function detectProductionMode(
257+
public static function detectProduction(
258258
int $mode = self::MODE_SIMPLE,
259259
?string $tempDir = null,
260-
?bool $default = false
260+
?bool $default = true
261261
): ?bool {
262262
if (is_bool($default)) {
263263
$default = !$default;

Diff for: src/Enabler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* The MIT License (MIT)
4-
* Copyright (c) 2022 Redbit s.r.o., Jakub Bouček
4+
* Copyright (c) 2023 Redbit s.r.o., Jakub Bouček
55
*/
66

77
declare(strict_types=1);

Diff for: src/InconsistentEnablerModeException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* The MIT License (MIT)
4-
* Copyright (c) 2022 Redbit s.r.o., Jakub Bouček
4+
* Copyright (c) 2023 Redbit s.r.o., Jakub Bouček
55
*/
66

77
declare(strict_types=1);

Diff for: src/Plugin/JWT/JWTFirebaseV5.php

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
/**
4+
* The MIT License (MIT)
5+
* Copyright (c) 2023 Redbit s.r.o., Jakub Bouček
6+
*
7+
* @noinspection PhpUndefinedClassInspection OpenSSL only optional dependency
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace Redbitcz\DebugMode\Plugin\JWT;
13+
14+
use Firebase\JWT\JWT;
15+
use ReflectionMethod;
16+
use stdClass;
17+
18+
class JWTFirebaseV5 implements JWTImpl
19+
{
20+
/** @var OpenSSLAsymmetricKey|OpenSSLCertificate|resource|string */
21+
protected $key;
22+
protected string $algorithm;
23+
24+
/**
25+
* @param OpenSSLAsymmetricKey|OpenSSLCertificate|resource|string $key
26+
* @param string $algorithm
27+
*/
28+
public function __construct($key, string $algorithm = 'HS256')
29+
{
30+
$this->key = $key;
31+
$this->algorithm = $algorithm;
32+
}
33+
34+
public static function isAvailable(): bool
35+
{
36+
if (class_exists(JWT::class) === false) {
37+
return false;
38+
}
39+
40+
$params = (new ReflectionMethod(JWT::class, 'decode'))->getParameters();
41+
42+
// JWT v5 has second parameter named `$key`
43+
if ($params[1]->getName() === 'key') {
44+
return true;
45+
}
46+
47+
// JWT v5.5.0 already second parameter named `$keyOrKeyArray`, detect by third param (future compatibility)
48+
return $params[1]->getName() === 'keyOrKeyArray'
49+
&& isset($params[2])
50+
&& $params[2]->getName() === 'allowed_algs';
51+
}
52+
53+
public function decode(string $jwt): stdClass
54+
{
55+
return JWT::decode($jwt, $this->key, [$this->algorithm]);
56+
}
57+
58+
public function encode(array $payload): string
59+
{
60+
return JWT::encode($payload, $this->key, $this->algorithm);
61+
}
62+
63+
public function setTimestamp(?int $timestamp): void
64+
{
65+
JWT::$timestamp = $timestamp;
66+
}
67+
}

Diff for: src/Plugin/JWT/JWTFirebaseV6.php

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
/**
4+
* The MIT License (MIT)
5+
* Copyright (c) 2023 Redbit s.r.o., Jakub Bouček
6+
*
7+
* @noinspection PhpUndefinedClassInspection Library support JWT 5.0
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace Redbitcz\DebugMode\Plugin\JWT;
13+
14+
use Firebase\JWT\JWT;
15+
use Firebase\JWT\Key;
16+
use ReflectionMethod;
17+
use stdClass;
18+
19+
class JWTFirebaseV6 extends JWTFirebaseV5
20+
{
21+
public static function isAvailable(): bool
22+
{
23+
if (class_exists(JWT::class) === false) {
24+
return false;
25+
}
26+
27+
$params = (new ReflectionMethod(JWT::class, 'decode'))->getParameters();
28+
29+
// JWT v6 has always second parameter named `$keyOrKeyArray`
30+
if ($params[1]->getName() !== 'keyOrKeyArray') {
31+
return false;
32+
}
33+
34+
// JWT v5.5.0 already second parameter named `$keyOrKeyArray`, detect by third param (future compatibility)
35+
return isset($params[2]) === false || $params[2]->getName() !== 'allowed_algs';
36+
}
37+
38+
public function decode(string $jwt): stdClass
39+
{
40+
return JWT::decode($jwt, new Key($this->key, $this->algorithm));
41+
}
42+
43+
44+
}

Diff for: src/Plugin/JWT/JWTImpl.php

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/**
4+
* The MIT License (MIT)
5+
* Copyright (c) 2023 Redbit s.r.o., Jakub Bouček
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Redbitcz\DebugMode\Plugin\JWT;
11+
12+
use stdClass;
13+
14+
interface JWTImpl
15+
{
16+
public static function isAvailable(): bool;
17+
18+
public function decode(string $jwt): stdClass;
19+
20+
public function encode(array $payload): string;
21+
22+
public function setTimestamp(?int $timestamp): void;
23+
}

Diff for: src/Plugin/Plugin.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* The MIT License (MIT)
4-
* Copyright (c) 2022 Redbit s.r.o., Jakub Bouček
4+
* Copyright (c) 2023 Redbit s.r.o., Jakub Bouček
55
*/
66

77
declare(strict_types=1);

0 commit comments

Comments
 (0)