diff --git a/docs/en/upgrade-3-to-4.rst b/docs/en/upgrade-3-to-4.rst index b465eb9c..e631c1b0 100644 --- a/docs/en/upgrade-3-to-4.rst +++ b/docs/en/upgrade-3-to-4.rst @@ -111,7 +111,7 @@ URL Checker Renamed and Restructured URL checkers have been completely restructured: - ``CakeRouterUrlChecker`` has been renamed to ``DefaultUrlChecker`` -- The old ``DefaultUrlChecker`` (framework-agnostic) has been renamed to ``GenericUrlChecker`` +- The old ``DefaultUrlChecker`` has been renamed to ``StringUrlChecker`` - Auto-detection has been removed - ``DefaultUrlChecker`` is now hardcoded **Before (3.x):** @@ -127,7 +127,7 @@ URL checkers have been completely restructured: ], ]); - // Using DefaultUrlChecker explicitly (framework-agnostic) + // Using DefaultUrlChecker explicitly $service->loadAuthenticator('Authentication.Form', [ 'urlChecker' => 'Authentication.Default', 'loginUrl' => '/users/login', @@ -150,9 +150,9 @@ URL checkers have been completely restructured: ], ]); - // For framework-agnostic projects, explicitly use GenericUrlChecker + // For string-only URL checking, explicitly use StringUrlChecker $service->loadAuthenticator('Authentication.Form', [ - 'urlChecker' => 'Authentication.Generic', + 'urlChecker' => 'Authentication.String', 'loginUrl' => '/users/login', ]); @@ -207,11 +207,10 @@ Auto-Detection Removed URL Checkers ^^^^^^^^^^^^ -**Important:** Auto-detection has been removed. ``DefaultUrlChecker`` is now hardcoded -and assumes CakePHP is available. +**Important:** Auto-detection has been removed. ``DefaultUrlChecker`` is now hardcoded. - **4.x default:** Always uses ``DefaultUrlChecker`` (formerly ``CakeUrlChecker``) -- **Framework-agnostic:** Must explicitly configure ``GenericUrlChecker`` +- **String URLs only:** Must explicitly configure ``StringUrlChecker`` - **Multiple URLs:** Must explicitly configure ``MultiUrlChecker`` DefaultUrlChecker is Now CakePHP-Based @@ -220,7 +219,7 @@ DefaultUrlChecker is Now CakePHP-Based ``DefaultUrlChecker`` is now the CakePHP checker (formerly ``CakeRouterUrlChecker``). It requires CakePHP Router and supports both string and array URLs. -The 3.x framework-agnostic ``DefaultUrlChecker`` has been renamed to ``GenericUrlChecker``. +The 3.x ``DefaultUrlChecker`` has been renamed to ``StringUrlChecker``. .. code-block:: php @@ -229,8 +228,8 @@ The 3.x framework-agnostic ``DefaultUrlChecker`` has been renamed to ``GenericUr $checker->check($request, ['controller' => 'Users', 'action' => 'login']); // Works $checker->check($request, '/users/login'); // Also works - // For framework-agnostic usage: - $checker = new GenericUrlChecker(); + // For string URL only usage: + $checker = new StringUrlChecker(); $checker->check($request, '/users/login'); // Works $checker->check($request, ['controller' => 'Users']); // Throws exception @@ -285,17 +284,17 @@ Migration Tips - ``IdentifierCollection`` → ``IdentifierFactory`` - ``'Authentication.CakeRouter'`` → Remove (no longer needed, default is now CakePHP-based) - ``CakeRouterUrlChecker`` → ``DefaultUrlChecker`` - - Old 3.x ``DefaultUrlChecker`` (framework-agnostic) → ``GenericUrlChecker`` + - Old 3.x ``DefaultUrlChecker`` → ``StringUrlChecker`` -2. **Framework-Agnostic Projects**: +2. **String URL Checking**: - If you're using this library without CakePHP, you **must** explicitly configure - ``GenericUrlChecker``: + If you want to use string-only URL checking, explicitly configure + ``StringUrlChecker``: .. code-block:: php $service->loadAuthenticator('Authentication.Form', [ - 'urlChecker' => 'Authentication.Generic', + 'urlChecker' => 'Authentication.String', 'loginUrl' => '/users/login', ]); diff --git a/docs/en/url-checkers.rst b/docs/en/url-checkers.rst index 6e7db9db..fc6a33e2 100644 --- a/docs/en/url-checkers.rst +++ b/docs/en/url-checkers.rst @@ -1,9 +1,8 @@ URL Checkers ############ -To provide an abstract and framework agnostic solution there are URL -checkers implemented that allow you to customize the comparison of the -current URL if needed. For example to another frameworks routing. +There are URL checkers implemented that allow you to customize the comparison +of the current URL if needed. All checkers support single URLs in either string or array format (like ``Router::url()``). For multiple login URLs, use ``MultiUrlChecker``. @@ -43,16 +42,15 @@ Options: - **checkFullUrl**: To compare the full URL, including protocol, host and port or not. Default is ``false``. -GenericUrlChecker ------------------- +StringUrlChecker +----------------- -Framework-agnostic checker for string URLs. Supports regex matching. -Use this for non-CakePHP projects. +Checker for string URLs. Supports regex matching. .. code-block:: php $service->loadAuthenticator('Authentication.Form', [ - 'urlChecker' => 'Authentication.Generic', + 'urlChecker' => 'Authentication.String', 'loginUrl' => '/users/login', ]); @@ -62,7 +60,7 @@ Using regex: $service->loadAuthenticator('Authentication.Form', [ 'urlChecker' => [ - 'className' => 'Authentication.Generic', + 'className' => 'Authentication.String', 'useRegex' => true, ], 'loginUrl' => '%^/[a-z]{2}/users/login/?$%', diff --git a/src/UrlChecker/GenericUrlChecker.php b/src/UrlChecker/StringUrlChecker.php similarity index 94% rename from src/UrlChecker/GenericUrlChecker.php rename to src/UrlChecker/StringUrlChecker.php index e36da18c..15f3ac9c 100644 --- a/src/UrlChecker/GenericUrlChecker.php +++ b/src/UrlChecker/StringUrlChecker.php @@ -20,9 +20,9 @@ use RuntimeException; /** - * Generic URL checker for framework-agnostic usage. Supports also regex. + * URL checker for string URLs. Supports also regex. */ -class GenericUrlChecker implements UrlCheckerInterface +class StringUrlChecker implements UrlCheckerInterface { /** * Default Options @@ -44,8 +44,7 @@ public function check(ServerRequestInterface $request, array|string $loginUrls, { if (is_array($loginUrls)) { throw new RuntimeException( - 'Array-based login URLs require CakePHP Router and DefaultUrlChecker. ' . - 'Use string URLs instead.', + 'Array-based login URLs require CakePHP Router and DefaultUrlChecker.', ); } diff --git a/tests/TestCase/Authenticator/EnvironmentAuthenticatorTest.php b/tests/TestCase/Authenticator/EnvironmentAuthenticatorTest.php index e4c0fe0d..464e835b 100644 --- a/tests/TestCase/Authenticator/EnvironmentAuthenticatorTest.php +++ b/tests/TestCase/Authenticator/EnvironmentAuthenticatorTest.php @@ -378,7 +378,7 @@ public function testRegexLoginUrlSuccess() $envAuth = new EnvironmentAuthenticator($this->identifier, [ 'loginUrl' => '%^/[a-z]{2}/users/secure/?$%', 'urlChecker' => [ - 'className' => 'Authentication.Generic', + 'className' => 'Authentication.String', 'useRegex' => true, ], 'fields' => [ @@ -409,7 +409,7 @@ public function testFullRegexLoginUrlFailure() $envAuth = new EnvironmentAuthenticator($this->identifier, [ 'loginUrl' => '%auth\.localhost/[a-z]{2}/users/secure/?$%', 'urlChecker' => [ - 'className' => 'Authentication.Generic', + 'className' => 'Authentication.String', 'useRegex' => true, 'checkFullUrl' => true, ], @@ -441,7 +441,7 @@ public function testFullRegexLoginUrlSuccess() $envAuth = new EnvironmentAuthenticator($this->identifier, [ 'loginUrl' => '%auth\.localhost/[a-z]{2}/users/secure/?$%', 'urlChecker' => [ - 'className' => 'Authentication.Generic', + 'className' => 'Authentication.String', 'useRegex' => true, 'checkFullUrl' => true, ], diff --git a/tests/TestCase/Authenticator/FormAuthenticatorTest.php b/tests/TestCase/Authenticator/FormAuthenticatorTest.php index 13d4701b..96103f52 100644 --- a/tests/TestCase/Authenticator/FormAuthenticatorTest.php +++ b/tests/TestCase/Authenticator/FormAuthenticatorTest.php @@ -313,7 +313,7 @@ public function testRegexLoginUrlSuccess() $form = new FormAuthenticator($identifier, [ 'loginUrl' => '%^/[a-z]{2}/users/login/?$%', 'urlChecker' => [ - 'className' => 'Authentication.Generic', + 'className' => 'Authentication.String', 'useRegex' => true, ], ]); @@ -345,7 +345,7 @@ public function testFullRegexLoginUrlFailure() $form = new FormAuthenticator($identifier, [ 'loginUrl' => '%auth\.localhost/[a-z]{2}/users/login/?$%', 'urlChecker' => [ - 'className' => 'Authentication.Generic', + 'className' => 'Authentication.String', 'useRegex' => true, 'checkFullUrl' => true, ], @@ -379,7 +379,7 @@ public function testFullRegexLoginUrlSuccess() $form = new FormAuthenticator($identifier, [ 'loginUrl' => '%auth\.localhost/[a-z]{2}/users/login/?$%', 'urlChecker' => [ - 'className' => 'Authentication.Generic', + 'className' => 'Authentication.String', 'useRegex' => true, 'checkFullUrl' => true, ], @@ -410,7 +410,7 @@ public function testFullLoginUrlFailureWithoutCheckFullUrlOption() $form = new FormAuthenticator($identifier, [ 'loginUrl' => 'http://localhost/users/login', 'urlChecker' => [ - 'className' => 'Authentication.Generic', + 'className' => 'Authentication.String', ], ]); diff --git a/tests/TestCase/UrlChecker/GenericUrlCheckerTest.php b/tests/TestCase/UrlChecker/StringUrlCheckerTest.php similarity index 89% rename from tests/TestCase/UrlChecker/GenericUrlCheckerTest.php rename to tests/TestCase/UrlChecker/StringUrlCheckerTest.php index cbf2b827..f865bc27 100644 --- a/tests/TestCase/UrlChecker/GenericUrlCheckerTest.php +++ b/tests/TestCase/UrlChecker/StringUrlCheckerTest.php @@ -17,13 +17,13 @@ namespace Authentication\Test\TestCase\UrlChecker; use Authentication\Test\TestCase\AuthenticationTestCase as TestCase; -use Authentication\UrlChecker\GenericUrlChecker; +use Authentication\UrlChecker\StringUrlChecker; use Cake\Http\ServerRequestFactory; /** - * GenericUrlCheckerTest + * StringUrlCheckerTest */ -class GenericUrlCheckerTest extends TestCase +class StringUrlCheckerTest extends TestCase { /** * testCheckFailure @@ -32,7 +32,7 @@ class GenericUrlCheckerTest extends TestCase */ public function testCheckFailure() { - $checker = new GenericUrlChecker(); + $checker = new StringUrlChecker(); $request = ServerRequestFactory::fromGlobals( ['REQUEST_URI' => '/users/does-not-match'], @@ -49,7 +49,7 @@ public function testCheckFailure() */ public function testCheckSimple() { - $checker = new GenericUrlChecker(); + $checker = new StringUrlChecker(); $request = ServerRequestFactory::fromGlobals( ['REQUEST_URI' => '/users/login'], ); @@ -67,7 +67,7 @@ public function testCheckSimple() */ public function testCheckRegexp() { - $checker = new GenericUrlChecker(); + $checker = new StringUrlChecker(); $request = ServerRequestFactory::fromGlobals( ['REQUEST_URI' => '/en/users/login'], ); @@ -85,7 +85,7 @@ public function testCheckRegexp() */ public function testCheckFull() { - $checker = new GenericUrlChecker(); + $checker = new StringUrlChecker(); $request = ServerRequestFactory::fromGlobals( ['REQUEST_URI' => '/users/login'], ); @@ -103,7 +103,7 @@ public function testCheckFull() */ public function testCheckBase() { - $checker = new GenericUrlChecker(); + $checker = new StringUrlChecker(); $request = ServerRequestFactory::fromGlobals( ['REQUEST_URI' => '/users/login'], );