Skip to content

Commit dfc2fda

Browse files
authored
refactor: remove deprecated methods in Autoloader (#9973)
1 parent e3e85b4 commit dfc2fda

File tree

3 files changed

+3
-132
lines changed

3 files changed

+3
-132
lines changed

system/Autoloader/Autoloader.php

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -320,51 +320,6 @@ protected function includeFile(string $file)
320320
return false;
321321
}
322322

323-
/**
324-
* Check file path.
325-
*
326-
* Checks special characters that are illegal in filenames on certain
327-
* operating systems and special characters requiring special escaping
328-
* to manipulate at the command line. Replaces spaces and consecutive
329-
* dashes with a single dash. Trim period, dash and underscore from beginning
330-
* and end of filename.
331-
*
332-
* @return string The sanitized filename
333-
*
334-
* @deprecated No longer used. See https://github.com/codeigniter4/CodeIgniter4/issues/7055
335-
*/
336-
public function sanitizeFilename(string $filename): string
337-
{
338-
// Only allow characters deemed safe for POSIX portable filenames.
339-
// Plus the forward slash for directory separators since this might be a path.
340-
// http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_278
341-
// Modified to allow backslash and colons for on Windows machines.
342-
$result = preg_match_all('/[^0-9\p{L}\s\/\-_.:\\\\]/u', $filename, $matches);
343-
344-
if ($result > 0) {
345-
$chars = implode('', $matches[0]);
346-
347-
throw new InvalidArgumentException(
348-
'The file path contains special characters "' . $chars
349-
. '" that are not allowed: "' . $filename . '"',
350-
);
351-
}
352-
if ($result === false) {
353-
$message = preg_last_error_msg();
354-
355-
throw new RuntimeException($message . '. filename: "' . $filename . '"');
356-
}
357-
358-
// Clean up our filename edges.
359-
$cleanFilename = trim($filename, '.-_');
360-
361-
if ($filename !== $cleanFilename) {
362-
throw new InvalidArgumentException('The characters ".-_" are not allowed in filename edges: "' . $filename . '"');
363-
}
364-
365-
return $cleanFilename;
366-
}
367-
368323
/**
369324
* @param array{only?: list<string>, exclude?: list<string>} $composerPackages
370325
*/
@@ -442,44 +397,6 @@ private function loadComposerNamespaces(ClassLoader $composer, array $composerPa
442397
$this->addNamespace($newPaths);
443398
}
444399

445-
/**
446-
* Locates autoload information from Composer, if available.
447-
*
448-
* @deprecated No longer used.
449-
*
450-
* @return void
451-
*/
452-
protected function discoverComposerNamespaces()
453-
{
454-
if (! is_file(COMPOSER_PATH)) {
455-
return;
456-
}
457-
458-
/**
459-
* @var ClassLoader $composer
460-
*/
461-
$composer = include COMPOSER_PATH;
462-
$paths = $composer->getPrefixesPsr4();
463-
$classes = $composer->getClassMap();
464-
465-
unset($composer);
466-
467-
// Get rid of CodeIgniter so we don't have duplicates
468-
if (isset($paths['CodeIgniter\\'])) {
469-
unset($paths['CodeIgniter\\']);
470-
}
471-
472-
$newPaths = [];
473-
474-
foreach ($paths as $key => $value) {
475-
// Composer stores namespaces with trailing slash. We don't.
476-
$newPaths[rtrim($key, '\\ ')] = $value;
477-
}
478-
479-
$this->prefixes = array_merge($this->prefixes, $newPaths);
480-
$this->classmap = array_merge($this->classmap, $classes);
481-
}
482-
483400
/**
484401
* Loads helpers
485402
*/

tests/system/Autoloader/AutoloaderTest.php

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
use App\Controllers\Home;
1717
use Closure;
1818
use CodeIgniter\Exceptions\ConfigException;
19-
use CodeIgniter\Exceptions\InvalidArgumentException;
20-
use CodeIgniter\Exceptions\RuntimeException;
2119
use CodeIgniter\Test\CIUnitTestCase;
2220
use CodeIgniter\Test\ReflectionHelper;
2321
use Config\Autoload;
@@ -231,53 +229,6 @@ public function testloadClassNonNamespaced(): void
231229
$this->assertFalse(($this->classLoader)('Modules'));
232230
}
233231

234-
public function testSanitizationContailsSpecialChars(): void
235-
{
236-
$this->expectException(InvalidArgumentException::class);
237-
$this->expectExceptionMessage(
238-
'The file path contains special characters "${}!#" that are not allowed: "${../path}!#/to/some/file.php_"',
239-
);
240-
241-
$test = '${../path}!#/to/some/file.php_';
242-
243-
$this->loader->sanitizeFilename($test);
244-
}
245-
246-
public function testSanitizationFilenameEdges(): void
247-
{
248-
$this->expectException(InvalidArgumentException::class);
249-
$this->expectExceptionMessage(
250-
'The characters ".-_" are not allowed in filename edges: "/path/to/some/file.php_"',
251-
);
252-
253-
$test = '/path/to/some/file.php_';
254-
255-
$this->loader->sanitizeFilename($test);
256-
}
257-
258-
public function testSanitizationRegexError(): void
259-
{
260-
$this->expectException(RuntimeException::class);
261-
262-
$test = mb_convert_encoding('クラスファイル.php', 'EUC-JP', 'UTF-8');
263-
264-
$this->loader->sanitizeFilename($test);
265-
}
266-
267-
public function testSanitizationAllowUnicodeChars(): void
268-
{
269-
$test = 'Ä/path/to/some/file.php';
270-
271-
$this->assertSame($test, $this->loader->sanitizeFilename($test));
272-
}
273-
274-
public function testSanitizationAllowsWindowsFilepaths(): void
275-
{
276-
$test = 'C:\path\to\some/file.php';
277-
278-
$this->assertSame($test, $this->loader->sanitizeFilename($test));
279-
}
280-
281232
public function testFindsComposerRoutes(): void
282233
{
283234
$config = new Autoload();

user_guide_src/source/changelogs/v4.8.0.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ Method Signature Changes
3737
Removed Deprecated Items
3838
========================
3939

40+
- **Autoloader:** Removed the following deprecated methods:
41+
- ``CodeIgniter\Autoloader\Autoloader::sanitizeFileName()``
42+
- ``CodeIgniter\Autoloader\Autoloader::discoverComposerNamespaces()``
4043
- **Exceptions:** Removed the following properties and methods deprecated since v4.4.0:
4144
- ``CodeIgniter\Debug\Exceptions::$ob_level``
4245
- ``CodeIgniter\Debug\Exceptions::$viewPath``

0 commit comments

Comments
 (0)