Skip to content

Commit a3d3703

Browse files
authored
Merge pull request #38 from michalsn/fix/ci44
Compatibility with CI 4.4
2 parents 7ffdb84 + deb6d57 commit a3d3703

File tree

8 files changed

+109
-80
lines changed

8 files changed

+109
-80
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ echo signedurl()->setExpiration(DAY * 2)->urlTo('namedRoute', 12);
2626
// https://example.com/route/name/12?expiration=1671980371&signature=signature-goes-here
2727
```
2828

29+
## Versions
30+
31+
Versions are not compatible - URLs generated in one version of Signed URL will not work with another version.
32+
33+
| CodeIgniter version | Signed URL version |
34+
|---------------------|--------------------|
35+
| `>= 4.4` | `2.*` |
36+
| `< 4.4` | `1.*` |
37+
2938
## Docs
3039

3140
https://michalsn.github.io/codeigniter-signed-url

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
},
1818
"require-dev": {
1919
"codeigniter4/devkit": "^1.0",
20-
"codeigniter4/framework": "^4.2",
20+
"codeigniter4/framework": "^4.4",
2121
"rector/rector": "0.18.0"
2222
},
2323
"minimum-stability": "dev",

docs/index.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,11 @@ echo signedurl()->setExpiration(DAY * 2)->urlTo('namedRoute', 12);
1616
// https://example.com/route/name/12?expiration=1671980371&signature=signature-goes-here
1717
```
1818

19+
## Versions
20+
21+
Versions are not compatible - URLs generated in one version of Signed URL will not work with another version.
22+
23+
| CodeIgniter version | Signed URL version |
24+
|---------------------|--------------------|
25+
| `>= 4.4` | `2.*` |
26+
| `< 4.4` | `1.*` |

rector.php

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
<?php
22

33
use Rector\CodeQuality\Rector\BooleanAnd\SimplifyEmptyArrayCheckRector;
4+
use Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector;
45
use Rector\CodeQuality\Rector\Expression\InlineIfToExplicitIfRector;
5-
use Rector\CodeQuality\Rector\For_\ForToForeachRector;
66
use Rector\CodeQuality\Rector\Foreach_\UnusedForeachValueToArrayKeysRector;
7-
use Rector\CodeQuality\Rector\FuncCall\AddPregQuoteDelimiterRector;
87
use Rector\CodeQuality\Rector\FuncCall\ChangeArrayPushToArrayAssignRector;
98
use Rector\CodeQuality\Rector\FuncCall\SimplifyRegexPatternRector;
109
use Rector\CodeQuality\Rector\FuncCall\SimplifyStrposLowerRector;
@@ -20,28 +19,32 @@
2019
use Rector\Config\RectorConfig;
2120
use Rector\Core\ValueObject\PhpVersion;
2221
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector;
23-
use Rector\DeadCode\Rector\MethodCall\RemoveEmptyMethodCallRector;
2422
use Rector\EarlyReturn\Rector\Foreach_\ChangeNestedForeachIfsToEarlyContinueRector;
2523
use Rector\EarlyReturn\Rector\If_\ChangeIfElseValueAssignToEarlyReturnRector;
2624
use Rector\EarlyReturn\Rector\If_\RemoveAlwaysElseRector;
2725
use Rector\EarlyReturn\Rector\Return_\PreparedValueToEarlyReturnRector;
2826
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
29-
use Rector\Php56\Rector\FunctionLike\AddDefaultValueForUndefinedVariableRector;
3027
use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector;
3128
use Rector\Php73\Rector\FuncCall\StringifyStrNeedlesRector;
32-
use Rector\Php80\Rector\Class_\AnnotationToAttributeRector;
33-
use Rector\PHPUnit\Set\PHPUnitLevelSetList;
3429
use Rector\PHPUnit\Set\PHPUnitSetList;
35-
use Rector\PSR4\Rector\FileWithoutNamespace\NormalizeNamespaceByPSR4ComposerAutoloadRector;
30+
use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector;
3631
use Rector\Set\ValueObject\LevelSetList;
3732
use Rector\Set\ValueObject\SetList;
33+
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector;
3834

3935
return static function (RectorConfig $rectorConfig): void {
40-
$rectorConfig->sets([SetList::DEAD_CODE, LevelSetList::UP_TO_PHP_80, PHPUnitSetList::PHPUNIT_SPECIFIC_METHOD, PHPUnitLevelSetList::UP_TO_PHPUNIT_100]);
36+
$rectorConfig->sets([
37+
SetList::DEAD_CODE,
38+
LevelSetList::UP_TO_PHP_80,
39+
PHPUnitSetList::PHPUNIT_CODE_QUALITY,
40+
PHPUnitSetList::PHPUNIT_100,
41+
]);
42+
4143
$rectorConfig->parallel();
44+
4245
// The paths to refactor (can also be supplied with CLI arguments)
4346
$rectorConfig->paths([
44-
__DIR__ . '/src/',
47+
__DIR__ . '/app/',
4548
__DIR__ . '/tests/',
4649
]);
4750

@@ -76,30 +79,16 @@
7679
// Note: requires php 8
7780
RemoveUnusedPromotedPropertyRector::class,
7881

79-
// Ignore tests that might make calls without a result
80-
RemoveEmptyMethodCallRector::class => [
81-
__DIR__ . '/tests',
82-
],
83-
84-
// Ignore files that should not be namespaced
85-
NormalizeNamespaceByPSR4ComposerAutoloadRector::class => [
86-
__DIR__ . '/src/Common.php',
87-
__DIR__ . '/tests/_support/Views/',
88-
],
89-
9082
// May load view files directly when detecting classes
9183
StringClassNameToClassConstantRector::class,
84+
]);
9285

93-
// May be uninitialized on purpose
94-
AddDefaultValueForUndefinedVariableRector::class,
86+
// auto import fully qualified class names
87+
$rectorConfig->importNames();
9588

96-
// PHPUnit attributes
97-
AnnotationToAttributeRector::class,
98-
]);
9989
$rectorConfig->rule(SimplifyUselessVariableRector::class);
10090
$rectorConfig->rule(RemoveAlwaysElseRector::class);
10191
$rectorConfig->rule(CountArrayToEmptyArrayComparisonRector::class);
102-
$rectorConfig->rule(ForToForeachRector::class);
10392
$rectorConfig->rule(ChangeNestedForeachIfsToEarlyContinueRector::class);
10493
$rectorConfig->rule(ChangeIfElseValueAssignToEarlyReturnRector::class);
10594
$rectorConfig->rule(SimplifyStrposLowerRector::class);
@@ -112,10 +101,19 @@
112101
$rectorConfig->rule(UnusedForeachValueToArrayKeysRector::class);
113102
$rectorConfig->rule(ChangeArrayPushToArrayAssignRector::class);
114103
$rectorConfig->rule(UnnecessaryTernaryExpressionRector::class);
115-
$rectorConfig->rule(AddPregQuoteDelimiterRector::class);
116104
$rectorConfig->rule(SimplifyRegexPatternRector::class);
117105
$rectorConfig->rule(FuncGetArgsToVariadicParamRector::class);
118106
$rectorConfig->rule(MakeInheritedMethodVisibilitySameAsParentRector::class);
119107
$rectorConfig->rule(SimplifyEmptyArrayCheckRector::class);
120-
$rectorConfig->rule(NormalizeNamespaceByPSR4ComposerAutoloadRector::class);
108+
$rectorConfig
109+
->ruleWithConfiguration(TypedPropertyFromAssignsRector::class, [
110+
/**
111+
* The INLINE_PUBLIC value is default to false to avoid BC break, if you use for libraries and want to preserve BC break, you don't need to configure it, as it included in LevelSetList::UP_TO_PHP_74
112+
* Set to true for projects that allow BC break
113+
*/
114+
TypedPropertyFromAssignsRector::INLINE_PUBLIC => true,
115+
]);
116+
$rectorConfig->rule(StringClassNameToClassConstantRector::class);
117+
$rectorConfig->rule(PrivatizeFinalClassPropertyRector::class);
118+
$rectorConfig->rule(CompleteDynamicPropertiesRector::class);
121119
};

src/Config/SignedUrl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class SignedUrl extends BaseConfig
2121
* If you're not sure what you're doing
2222
* please stay with the default option.
2323
*/
24-
public string $algorithm = 'sha1';
24+
public string $algorithm = 'sha256';
2525

2626
/**
2727
* Query string key names.

src/SignedUrl.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
namespace Michalsn\CodeIgniterSignedUrl;
44

55
use CodeIgniter\HTTP\IncomingRequest;
6+
use CodeIgniter\HTTP\SiteURI;
67
use CodeIgniter\HTTP\URI;
78
use CodeIgniter\I18n\Time;
89
use CodeIgniter\Router\Exceptions\RouterException;
10+
use Config\App;
911
use Michalsn\CodeIgniterSignedUrl\Config\SignedUrl as SignedUrlConfig;
1012
use Michalsn\CodeIgniterSignedUrl\Exceptions\SignedUrlException;
1113

@@ -72,7 +74,11 @@ public function siteUrl(array|string $relativePath): string
7274
$relativePath = implode('/', $relativePath);
7375
}
7476

75-
$uri = _get_uri($relativePath);
77+
$host = service('request')->getUri()->getHost();
78+
79+
$config = config(App::class);
80+
81+
$uri = new SiteURI($config, $relativePath, $host);
7682

7783
return $this->sign($uri);
7884
}
@@ -146,7 +152,7 @@ public function verify(IncomingRequest $request): bool
146152
$uri = $request->getUri();
147153
$uri->stripQuery($this->config->signatureKey);
148154

149-
$url = URI::createURIString('', site_url(), $uri->getPath(), $uri->getQuery(), $uri->getFragment());
155+
$url = URI::createURIString('', base_url(), $uri->getPath(), $uri->getQuery(), $uri->getFragment());
150156
$signature = hash_hmac($queryAlgorithm, $url, $this->key, true);
151157

152158
if (! hash_equals($querySignature, $signature)) {

tests/CommonTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testSignedurl(): void
3030
public function testSignedUrlSiteUrl(): void
3131
{
3232
$this->assertSame(
33-
'https://example.com/index.php/controller/method?signature=ZFCzKztQmn2yGb-ShnNyT5mF4eQ',
33+
'https://example.com/index.php/controller/method?signature=I0a1XPGLCTlRQo5c5f3LCz9R-tKP244-6pKCRV54AEk',
3434
signedurl()->siteUrl(['controller', 'method'])
3535
);
3636
}
@@ -40,7 +40,7 @@ public function testSignedUrlSiteUrlWithExpirationTime(): void
4040
Time::setTestNow('2022-12-25 14:59:11', 'UTC');
4141

4242
$this->assertSame(
43-
'https://example.com/index.php/controller/method?expires=1671980361&signature=byUOHLW6p45GrUpMsVz3AlEBMYs',
43+
'https://example.com/index.php/controller/method?expires=1671980361&signature=9ZKau6qjzGOPY6unRPozK7dtZB1k_5hHQ9j3pwaQmzU',
4444
signedurl()->setExpiration(SECOND * 10)->siteUrl('controller/method')
4545
);
4646
}
@@ -51,7 +51,7 @@ public function testSignedUrlTo(): void
5151
$routes->add('path/(:num)', 'myController::goto/$1', ['as' => 'gotoPage']);
5252

5353
$this->assertSame(
54-
'https://example.com/index.php/path/13?signature=iZd5igbJp6uYIjjLKdiiPkmON0E',
54+
'https://example.com/index.php/path/13?signature=niwm-RgYXkGSKzuEH1semjC6TU5T8WrHs7FvEEyD8uQ',
5555
signedurl()->urlTo('gotoPage', 13)
5656
);
5757
}
@@ -64,7 +64,7 @@ public function testSignedUrlToWithExpirationTime(): void
6464
Time::setTestNow('2022-12-25 14:59:11', 'UTC');
6565

6666
$this->assertSame(
67-
'https://example.com/index.php/path/13?expires=1671980361&signature=HTGY25XucRbwm9LffdsTWHzn1Eg',
67+
'https://example.com/index.php/path/13?expires=1671980361&signature=pHMHFrXI74G5JuQc1mUUETznuUNnpHkwhAOsjazxlUw',
6868
signedurl()->setExpiration(SECOND * 10)->urlTo('gotoPage', 13)
6969
);
7070
}

0 commit comments

Comments
 (0)