mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
Removing addClass and removeClass from Autoloader because simply using require() elsewhere makes more sense.
This commit is contained in:
parent
c821688f06
commit
4ca722025e
@ -105,39 +105,6 @@ class Autoloader
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Adds a new item to the class map.
|
||||
*
|
||||
* @param $class
|
||||
* @param $path
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addClass($class, $path)
|
||||
{
|
||||
$this->classmap[$class] = $path;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Removes an entry from the classmap.
|
||||
*
|
||||
* @param $class
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function removeClass($class)
|
||||
{
|
||||
unset($this->classmap[$class]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Registers a namespace with the autoloader.
|
||||
*
|
||||
|
@ -25,22 +25,6 @@ class MockAutoloaderClass extends \CodeIgniter\Autoloader\Autoloader
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
public function addClass($class, $path)
|
||||
{
|
||||
$this->files[] = $path;
|
||||
|
||||
return parent::addClass($class, $path);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
public function removeClass($class)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -146,18 +130,6 @@ class AutoloaderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
public function testAddClassWorks()
|
||||
{
|
||||
$this->loader->addClass('myClass', '/path/to/class.php');
|
||||
|
||||
$actual = $this->loader->loadClass('myClass');
|
||||
$expected = '/path/to/class.php';
|
||||
|
||||
$this->assertSame($expected, $actual);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
public function testAddNamespaceWorks()
|
||||
{
|
||||
$this->assertFalse($this->loader->loadClass('My\App\Class'));
|
||||
|
@ -26,16 +26,11 @@ The key of each row is the namespace itself. This does not need a trailing slash
|
||||
The classmap is used extensively by CodeIgniter to eek the last ounces of performance out of the system by not hitting the file-system with extra `file_exists()` calls. You can use the classmap to link to third-party libraries that are not namespaced.
|
||||
|
||||
$config['classmap'] = [
|
||||
'Markdown' => APPPATH .'third_party/mardown.php'
|
||||
'Markdown' => APPPATH .'third_party/markdown.php'
|
||||
];
|
||||
|
||||
The key of each row is the name of the class that you want to locate. The value is the path to locate it at.
|
||||
|
||||
You can manage additional classes at runtime with the `addClass()` and `removeClass()` methods.
|
||||
|
||||
$loader->addClass('Markdown', APPPATH .'third_party/mardown.php');
|
||||
$loader->removeClass('Markdown');
|
||||
|
||||
### Legacy Support
|
||||
If neither of the above methods find the class, and the class is not namespace, the autoloader will look in the `/application/libraries` and `/application/models` directories to attempt to locate the files. This provides a measure to help ease the transition from previous versions.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user