Skip to content

Commit

Permalink
Autoloader for future and legacy namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
arokettu committed Jan 14, 2023
1 parent 616a6ab commit 8bd1809
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 96 deletions.
27 changes: 27 additions & 0 deletions autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace SandFox\Bencode\Legacy;

const NS = 'SandFox\\PhpStorm\\Metadata\\';
const PREFIX_1 = 'Arokettu\\PhpStorm\\Metadata\\';
const PREFIX_1_LEN = 27;
const PREFIX_2 = 'SandFoxMe\\PhpStorm\\Metadata\\';
const PREFIX_2_LEN = 28;

spl_autoload_register(function (string $class_name) {
if (strncmp($class_name, PREFIX_1, PREFIX_1_LEN) === 0) {
$realName = NS . substr($class_name, PREFIX_1_LEN);
class_alias($realName, $class_name);
return true;
}

if (strncmp($class_name, PREFIX_2, PREFIX_2_LEN) === 0) {
$realName = NS . substr($class_name, PREFIX_2_LEN);
class_alias($realName, $class_name);
return true;
}

return null;
});
11 changes: 8 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@
}
],
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
},
"sort-packages": true
},
"autoload": {
"psr-4": {
"SandFox\\PhpStorm\\Metadata\\": "src",
"SandFoxMe\\PhpStorm\\Metadata\\": "legacy"
}
"SandFox\\PhpStorm\\Metadata\\": "src"
},
"files": [
"autoload.php"
]
},
"require": {
"php": "^7.0 || ^8.0",
Expand Down
25 changes: 0 additions & 25 deletions legacy/Generator.php

This file was deleted.

17 changes: 0 additions & 17 deletions legacy/Integration/Psr15/ContainerExportMiddleware.php

This file was deleted.

17 changes: 0 additions & 17 deletions legacy/Integration/Silex/ContainerExportProvider.php

This file was deleted.

17 changes: 0 additions & 17 deletions legacy/Integration/Slim/ContainerExportMiddleware.php

This file was deleted.

17 changes: 0 additions & 17 deletions legacy/StaticMap.php

This file was deleted.

0 comments on commit 8bd1809

Please sign in to comment.