Skip to content

Commit f4f9a63

Browse files
authored
Fix up for cake only use. (#756)
1 parent 2ac8fd5 commit f4f9a63

File tree

6 files changed

+39
-43
lines changed

6 files changed

+39
-43
lines changed

docs/en/upgrade-3-to-4.rst

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ URL Checker Renamed and Restructured
111111
URL checkers have been completely restructured:
112112

113113
- ``CakeRouterUrlChecker`` has been renamed to ``DefaultUrlChecker``
114-
- The old ``DefaultUrlChecker`` (framework-agnostic) has been renamed to ``GenericUrlChecker``
114+
- The old ``DefaultUrlChecker`` has been renamed to ``StringUrlChecker``
115115
- Auto-detection has been removed - ``DefaultUrlChecker`` is now hardcoded
116116

117117
**Before (3.x):**
@@ -127,7 +127,7 @@ URL checkers have been completely restructured:
127127
],
128128
]);
129129
130-
// Using DefaultUrlChecker explicitly (framework-agnostic)
130+
// Using DefaultUrlChecker explicitly
131131
$service->loadAuthenticator('Authentication.Form', [
132132
'urlChecker' => 'Authentication.Default',
133133
'loginUrl' => '/users/login',
@@ -150,9 +150,9 @@ URL checkers have been completely restructured:
150150
],
151151
]);
152152
153-
// For framework-agnostic projects, explicitly use GenericUrlChecker
153+
// For string-only URL checking, explicitly use StringUrlChecker
154154
$service->loadAuthenticator('Authentication.Form', [
155-
'urlChecker' => 'Authentication.Generic',
155+
'urlChecker' => 'Authentication.String',
156156
'loginUrl' => '/users/login',
157157
]);
158158
@@ -207,11 +207,10 @@ Auto-Detection Removed
207207
URL Checkers
208208
^^^^^^^^^^^^
209209

210-
**Important:** Auto-detection has been removed. ``DefaultUrlChecker`` is now hardcoded
211-
and assumes CakePHP is available.
210+
**Important:** Auto-detection has been removed. ``DefaultUrlChecker`` is now hardcoded.
212211

213212
- **4.x default:** Always uses ``DefaultUrlChecker`` (formerly ``CakeUrlChecker``)
214-
- **Framework-agnostic:** Must explicitly configure ``GenericUrlChecker``
213+
- **String URLs only:** Must explicitly configure ``StringUrlChecker``
215214
- **Multiple URLs:** Must explicitly configure ``MultiUrlChecker``
216215

217216
DefaultUrlChecker is Now CakePHP-Based
@@ -220,7 +219,7 @@ DefaultUrlChecker is Now CakePHP-Based
220219
``DefaultUrlChecker`` is now the CakePHP checker (formerly ``CakeRouterUrlChecker``).
221220
It requires CakePHP Router and supports both string and array URLs.
222221

223-
The 3.x framework-agnostic ``DefaultUrlChecker`` has been renamed to ``GenericUrlChecker``.
222+
The 3.x ``DefaultUrlChecker`` has been renamed to ``StringUrlChecker``.
224223

225224
.. code-block:: php
226225
@@ -229,8 +228,8 @@ The 3.x framework-agnostic ``DefaultUrlChecker`` has been renamed to ``GenericUr
229228
$checker->check($request, ['controller' => 'Users', 'action' => 'login']); // Works
230229
$checker->check($request, '/users/login'); // Also works
231230
232-
// For framework-agnostic usage:
233-
$checker = new GenericUrlChecker();
231+
// For string URL only usage:
232+
$checker = new StringUrlChecker();
234233
$checker->check($request, '/users/login'); // Works
235234
$checker->check($request, ['controller' => 'Users']); // Throws exception
236235
@@ -285,17 +284,17 @@ Migration Tips
285284
- ``IdentifierCollection`` → ``IdentifierFactory``
286285
- ``'Authentication.CakeRouter'`` → Remove (no longer needed, default is now CakePHP-based)
287286
- ``CakeRouterUrlChecker`` → ``DefaultUrlChecker``
288-
- Old 3.x ``DefaultUrlChecker`` (framework-agnostic) → ``GenericUrlChecker``
287+
- Old 3.x ``DefaultUrlChecker`` → ``StringUrlChecker``
289288

290-
2. **Framework-Agnostic Projects**:
289+
2. **String URL Checking**:
291290

292-
If you're using this library without CakePHP, you **must** explicitly configure
293-
``GenericUrlChecker``:
291+
If you want to use string-only URL checking, explicitly configure
292+
``StringUrlChecker``:
294293

295294
.. code-block:: php
296295
297296
$service->loadAuthenticator('Authentication.Form', [
298-
'urlChecker' => 'Authentication.Generic',
297+
'urlChecker' => 'Authentication.String',
299298
'loginUrl' => '/users/login',
300299
]);
301300

docs/en/url-checkers.rst

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
URL Checkers
22
############
33

4-
To provide an abstract and framework agnostic solution there are URL
5-
checkers implemented that allow you to customize the comparison of the
6-
current URL if needed. For example to another frameworks routing.
4+
There are URL checkers implemented that allow you to customize the comparison
5+
of the current URL if needed.
76

87
All checkers support single URLs in either string or array format (like ``Router::url()``).
98
For multiple login URLs, use ``MultiUrlChecker``.
@@ -43,16 +42,15 @@ Options:
4342
- **checkFullUrl**: To compare the full URL, including protocol, host
4443
and port or not. Default is ``false``.
4544

46-
GenericUrlChecker
47-
------------------
45+
StringUrlChecker
46+
-----------------
4847

49-
Framework-agnostic checker for string URLs. Supports regex matching.
50-
Use this for non-CakePHP projects.
48+
Checker for string URLs. Supports regex matching.
5149

5250
.. code-block:: php
5351
5452
$service->loadAuthenticator('Authentication.Form', [
55-
'urlChecker' => 'Authentication.Generic',
53+
'urlChecker' => 'Authentication.String',
5654
'loginUrl' => '/users/login',
5755
]);
5856
@@ -62,7 +60,7 @@ Using regex:
6260
6361
$service->loadAuthenticator('Authentication.Form', [
6462
'urlChecker' => [
65-
'className' => 'Authentication.Generic',
63+
'className' => 'Authentication.String',
6664
'useRegex' => true,
6765
],
6866
'loginUrl' => '%^/[a-z]{2}/users/login/?$%',
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
use RuntimeException;
2121

2222
/**
23-
* Generic URL checker for framework-agnostic usage. Supports also regex.
23+
* URL checker for string URLs. Supports also regex.
2424
*/
25-
class GenericUrlChecker implements UrlCheckerInterface
25+
class StringUrlChecker implements UrlCheckerInterface
2626
{
2727
/**
2828
* Default Options
@@ -44,8 +44,7 @@ public function check(ServerRequestInterface $request, array|string $loginUrls,
4444
{
4545
if (is_array($loginUrls)) {
4646
throw new RuntimeException(
47-
'Array-based login URLs require CakePHP Router and DefaultUrlChecker. ' .
48-
'Use string URLs instead.',
47+
'Array-based login URLs require CakePHP Router and DefaultUrlChecker.',
4948
);
5049
}
5150

tests/TestCase/Authenticator/EnvironmentAuthenticatorTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ public function testRegexLoginUrlSuccess()
378378
$envAuth = new EnvironmentAuthenticator($this->identifier, [
379379
'loginUrl' => '%^/[a-z]{2}/users/secure/?$%',
380380
'urlChecker' => [
381-
'className' => 'Authentication.Generic',
381+
'className' => 'Authentication.String',
382382
'useRegex' => true,
383383
],
384384
'fields' => [
@@ -409,7 +409,7 @@ public function testFullRegexLoginUrlFailure()
409409
$envAuth = new EnvironmentAuthenticator($this->identifier, [
410410
'loginUrl' => '%auth\.localhost/[a-z]{2}/users/secure/?$%',
411411
'urlChecker' => [
412-
'className' => 'Authentication.Generic',
412+
'className' => 'Authentication.String',
413413
'useRegex' => true,
414414
'checkFullUrl' => true,
415415
],
@@ -441,7 +441,7 @@ public function testFullRegexLoginUrlSuccess()
441441
$envAuth = new EnvironmentAuthenticator($this->identifier, [
442442
'loginUrl' => '%auth\.localhost/[a-z]{2}/users/secure/?$%',
443443
'urlChecker' => [
444-
'className' => 'Authentication.Generic',
444+
'className' => 'Authentication.String',
445445
'useRegex' => true,
446446
'checkFullUrl' => true,
447447
],

tests/TestCase/Authenticator/FormAuthenticatorTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ public function testRegexLoginUrlSuccess()
313313
$form = new FormAuthenticator($identifier, [
314314
'loginUrl' => '%^/[a-z]{2}/users/login/?$%',
315315
'urlChecker' => [
316-
'className' => 'Authentication.Generic',
316+
'className' => 'Authentication.String',
317317
'useRegex' => true,
318318
],
319319
]);
@@ -345,7 +345,7 @@ public function testFullRegexLoginUrlFailure()
345345
$form = new FormAuthenticator($identifier, [
346346
'loginUrl' => '%auth\.localhost/[a-z]{2}/users/login/?$%',
347347
'urlChecker' => [
348-
'className' => 'Authentication.Generic',
348+
'className' => 'Authentication.String',
349349
'useRegex' => true,
350350
'checkFullUrl' => true,
351351
],
@@ -379,7 +379,7 @@ public function testFullRegexLoginUrlSuccess()
379379
$form = new FormAuthenticator($identifier, [
380380
'loginUrl' => '%auth\.localhost/[a-z]{2}/users/login/?$%',
381381
'urlChecker' => [
382-
'className' => 'Authentication.Generic',
382+
'className' => 'Authentication.String',
383383
'useRegex' => true,
384384
'checkFullUrl' => true,
385385
],
@@ -410,7 +410,7 @@ public function testFullLoginUrlFailureWithoutCheckFullUrlOption()
410410
$form = new FormAuthenticator($identifier, [
411411
'loginUrl' => 'http://localhost/users/login',
412412
'urlChecker' => [
413-
'className' => 'Authentication.Generic',
413+
'className' => 'Authentication.String',
414414
],
415415
]);
416416

tests/TestCase/UrlChecker/GenericUrlCheckerTest.php renamed to tests/TestCase/UrlChecker/StringUrlCheckerTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
namespace Authentication\Test\TestCase\UrlChecker;
1818

1919
use Authentication\Test\TestCase\AuthenticationTestCase as TestCase;
20-
use Authentication\UrlChecker\GenericUrlChecker;
20+
use Authentication\UrlChecker\StringUrlChecker;
2121
use Cake\Http\ServerRequestFactory;
2222

2323
/**
24-
* GenericUrlCheckerTest
24+
* StringUrlCheckerTest
2525
*/
26-
class GenericUrlCheckerTest extends TestCase
26+
class StringUrlCheckerTest extends TestCase
2727
{
2828
/**
2929
* testCheckFailure
@@ -32,7 +32,7 @@ class GenericUrlCheckerTest extends TestCase
3232
*/
3333
public function testCheckFailure()
3434
{
35-
$checker = new GenericUrlChecker();
35+
$checker = new StringUrlChecker();
3636

3737
$request = ServerRequestFactory::fromGlobals(
3838
['REQUEST_URI' => '/users/does-not-match'],
@@ -49,7 +49,7 @@ public function testCheckFailure()
4949
*/
5050
public function testCheckSimple()
5151
{
52-
$checker = new GenericUrlChecker();
52+
$checker = new StringUrlChecker();
5353
$request = ServerRequestFactory::fromGlobals(
5454
['REQUEST_URI' => '/users/login'],
5555
);
@@ -67,7 +67,7 @@ public function testCheckSimple()
6767
*/
6868
public function testCheckRegexp()
6969
{
70-
$checker = new GenericUrlChecker();
70+
$checker = new StringUrlChecker();
7171
$request = ServerRequestFactory::fromGlobals(
7272
['REQUEST_URI' => '/en/users/login'],
7373
);
@@ -85,7 +85,7 @@ public function testCheckRegexp()
8585
*/
8686
public function testCheckFull()
8787
{
88-
$checker = new GenericUrlChecker();
88+
$checker = new StringUrlChecker();
8989
$request = ServerRequestFactory::fromGlobals(
9090
['REQUEST_URI' => '/users/login'],
9191
);
@@ -103,7 +103,7 @@ public function testCheckFull()
103103
*/
104104
public function testCheckBase()
105105
{
106-
$checker = new GenericUrlChecker();
106+
$checker = new StringUrlChecker();
107107
$request = ServerRequestFactory::fromGlobals(
108108
['REQUEST_URI' => '/users/login'],
109109
);

0 commit comments

Comments
 (0)