Skip to content

Commit f5c55ea

Browse files
committed
maintenance: Gt->GT
1 parent e6a2396 commit f5c55ea

4 files changed

Lines changed: 92 additions & 52 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
"autoload": {
5454
"files": [
55-
"./src/gt-compat.php"
55+
"./gt-compat.php"
5656
],
5757
"psr-4": {
5858
"GT\\WebEngine\\": "./src/"

composer.lock

Lines changed: 35 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gt-compat.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
const GT_COMPAT_LEGACY_PREFIX = "Gt\\";
3+
const GT_COMPAT_MODERN_PREFIX = "GT\\";
4+
const GT_COMPAT_LOCAL_PREFIX = "GT\\WebEngine\\";
5+
6+
spl_autoload_register(static function(string $className):void {
7+
if(!str_starts_with($className, GT_COMPAT_MODERN_PREFIX)
8+
|| str_starts_with($className, GT_COMPAT_LOCAL_PREFIX)) {
9+
return;
10+
}
11+
12+
$legacyClassName = GT_COMPAT_LEGACY_PREFIX . substr(
13+
$className,
14+
strlen(GT_COMPAT_MODERN_PREFIX)
15+
);
16+
17+
$classMapPath = __DIR__ . "/vendor/composer/autoload_classmap.php";
18+
if(is_file($classMapPath)) {
19+
/** @var array<string,string> $classMap */
20+
$classMap = require $classMapPath;
21+
if(isset($classMap[$legacyClassName])) {
22+
require_once $classMap[$legacyClassName];
23+
return;
24+
}
25+
}
26+
27+
$psr4Path = __DIR__ . "/vendor/composer/autoload_psr4.php";
28+
if(!is_file($psr4Path)) {
29+
return;
30+
}
31+
32+
/** @var array<string,list<string>> $psr4 */
33+
$psr4 = require $psr4Path;
34+
$prefix = $legacyClassName;
35+
36+
while(($separatorPos = strrpos($prefix, "\\")) !== false) {
37+
$prefix = substr($legacyClassName, 0, $separatorPos + 1);
38+
$relativeClass = substr($legacyClassName, $separatorPos + 1);
39+
40+
if(!isset($psr4[$prefix])) {
41+
$prefix = rtrim($prefix, "\\");
42+
continue;
43+
}
44+
45+
$relativePath = str_replace("\\", "/", $relativeClass) . ".php";
46+
foreach($psr4[$prefix] as $baseDirectory) {
47+
$pathName = $baseDirectory . "/" . $relativePath;
48+
if(is_file($pathName)) {
49+
require_once $pathName;
50+
return;
51+
}
52+
}
53+
54+
$prefix = rtrim($prefix, "\\");
55+
}
56+
});

src/Application.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ public function __construct(
6767
?Closure $handleShutdown = null,
6868
?Protection $globalProtection = null,
6969
) {
70-
$this->gtCompatibility();
7170
$this->redirect = $redirect ?? new Redirect();
7271
$this->config = $config ?? $this->loadConfig();
7372
$this->configureLoggerStreams();
@@ -214,21 +213,6 @@ private function finish(
214213
$this->timer->logDelta();
215214
}
216215

217-
/**
218-
* Registers a namespace compatibility autoloader to bridge the
219-
* legacy-to-GT namespace transition.
220-
*
221-
* As part of the PHP.GT rebranding for WebEngine v5, all references to
222-
* "GT" are being standardised to uppercase. However, the framework
223-
* consists of 40+ repositories that cannot all be refactored
224-
* simultaneously. This compatibility layer allows new code to reference
225-
* classes using the GT\ namespace while the underlying packages still
226-
* define classes with the legacy namespace casing.
227-
*/
228-
private function gtCompatibility():void {
229-
registerNamespaceCompatibilityAutoloader();
230-
}
231-
232216
private function protectGlobals():void {
233217
$this->globalProtection->overrideInternals(
234218
$this->globalProtection->removeGlobals([

0 commit comments

Comments
 (0)