PHP code example of redcatphp / autoload

1. Go to this page and download the library: Download redcatphp/autoload library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

redcatphp / autoload example snippets


use RedCat\Autoload\Autoload;
/* register "MyNamespace\SubSpace" prefix to "myDirectory/src/myNamespacePath" directory */
Autoload::register('myDirectory/src/myNamespacePath','MyNamespace\SubSpace');

/* register the containing file directory as a root directory for autoload */
Autoload::register(__DIR__);
/* equivalent */
Autoload::register(__DIR__,'');

$autoload = Autoload::getInstance();

$autoload->splRegister();
$autoload->splUnregister();

$autoload->addNamespace('Prefix\Of\My\Namespace','target/directory');
$autoload->addNamespace('Prefix\Of\My\Namespace2',[
	'target/directory1',
	'target/directory2',
]);
$autoload->addNamespaces([
	'Prefix\Of\My\Namespace'=>'target/directory/for/my/namespace',
	'Prefix\Of\My\Namespace2'=>[
		'target/directory1',
		'target/directory2',
	]
]);

$autoload->useIncludePath(true); //default param to true but default property to false

$autoload->useCache(false); //default param and property to true

$autoload->addClass('My\Class','path/of/myclass.php');
$autoload->addClassMap([
	'My\Class'=>'path/of/myclass.php',
	'My\Class2'=>'path/of/myclass2.php',
]);