Alexander Solonik
Alexander Solonik

Reputation: 10260

Invisible autoloading in PhilePhP

I was just going through the code of PhileCMS and came across the following lines of code:

if (Registry::isRegistered('Phile_Settings')) {
    $config = Registry::get('Phile_Settings');
    if (!empty($config['base_url'])) {
        return $config['base_url'];
    }
}

The file can be seen HERE

How come the static method of class Registry can be used here, when the file is not included or required at all? Is there some kind of auto loading going on in the backend that can't be seen? If so, what is this new kind of auto loading mechanism that has emerged?

Upvotes: 1

Views: 52

Answers (1)

Pavel Sadchenko
Pavel Sadchenko

Reputation: 141

Read more about of classes autoloading in PHP: http://php.net/manual/en/language.oop5.autoload.php

In PhileCMS the classes autoloading is confugired in the Phile\Bootstrap::initializeAutoloader() method (copy-paste of method body from the github for convinience):

spl_autoload_extensions(".php");
// load phile core
spl_autoload_register(function ($className) {
    $fileName = LIB_DIR . str_replace("\\", DIRECTORY_SEPARATOR, $className) . '.php';
    if (file_exists($fileName)) {
        require_once $fileName;
    }
});
// load phile plugins
spl_autoload_register('\Phile\Plugin\PluginRepository::autoload');
require(LIB_DIR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php');

https://github.com/PhileCMS/Phile/blob/master/lib/Phile/Bootstrap.php#L93

Upvotes: 1

Related Questions