Galette API documentation
Gestionnaire d’Adhérents en Ligne Extrêmement Tarabiscoté mais Tellement Efficace
1.0.0
Galette\Common\ClassLoader Class Reference

Public Member Functions

 __construct (string $ns=null, string $includePath=null)
 
 setNamespaceSeparator (string $sep)
 
 getNamespaceSeparator ()
 
 setIncludePath (string $includePath)
 
 getIncludePath ()
 
 setFileExtension (string $fileExtension)
 
 getFileExtension ()
 
 register ()
 
 unregister ()
 
 loadClass (string $className)
 
 canLoadClass (string $className)
 

Static Public Member Functions

static classExists (string $className)
 
static getClassLoader (string $className)
 

Protected Attributes

string $fileExtension = '.php'
 
string $namespace
 
string $includePath
 
string $namespaceSeparator = '\\'
 

Constructor & Destructor Documentation

◆ __construct()

Galette\Common\ClassLoader::__construct ( string  $ns = null,
string  $includePath = null 
)

Creates a new ClassLoader that loads classes of the specified namespace from the specified include path.

If no include path is given, the ClassLoader relies on the PHP include_path. If neither a namespace nor an include path is given, the ClassLoader will be responsible for loading all classes, thereby relying on the PHP include_path.

Parameters
?string$ns The namespace of the classes to load.
?string$includePath The base include path to use.

Member Function Documentation

◆ canLoadClass()

Galette\Common\ClassLoader::canLoadClass ( string  $className)

Asks this ClassLoader whether it can potentially load the class (file) with the given name.

Parameters
string$classNameThe fully-qualified name of the class.
Returns
boolean TRUE if this ClassLoader can load the class, FALSE otherwise.

◆ classExists()

static Galette\Common\ClassLoader::classExists ( string  $className)
static

Checks whether a class with a given name exists. A class "exists" if it is either already defined in the current request or if there is an autoloader on the SPL autoload stack that is a) responsible for the class in question and b) is able to load a class file in which the class definition resides.

If the class is not already defined, each autoloader in the SPL autoload stack is asked whether it is able to tell if the class exists. If the autoloader is a ClassLoader, canLoadClass is used, otherwise the autoload function of the autoloader is invoked and expected to return a value that evaluates to TRUE if the class (file) exists. As soon as one autoloader reports that the class exists, TRUE is returned.

Note that, depending on what kinds of autoloaders are installed on the SPL autoload stack, the class (file) might already be loaded as a result of checking for its existence. This is not the case with a ClassLoader, who separates these responsibilities.

Parameters
string$classNameThe fully-qualified name of the class.
Returns
boolean TRUE if the class exists as per the definition given above, FALSE otherwise.

◆ getClassLoader()

static Galette\Common\ClassLoader::getClassLoader ( string  $className)
static

Gets the ClassLoader from the SPL autoload stack that is responsible for (and is able to load) the class with the given name.

Parameters
string$classNameThe name of the class.
Returns
ClassLoader|null The ClassLoader responsible for the class or NULL if no such

◆ getFileExtension()

Galette\Common\ClassLoader::getFileExtension ( )

Gets the file extension of class files in the namespace of this ClassLoader.

Returns
string

◆ getIncludePath()

Galette\Common\ClassLoader::getIncludePath ( )

Gets the base include path for all class files in the namespace of this ClassLoader.

Returns
string

◆ getNamespaceSeparator()

Galette\Common\ClassLoader::getNamespaceSeparator ( )

Gets the namespace separator used by classes in the namespace of this ClassLoader.

Returns
string

◆ loadClass()

Galette\Common\ClassLoader::loadClass ( string  $className)

Loads the given class or interface.

Parameters
string$classNameThe name of the class to load.
Returns
boolean TRUE if the class has been successfully loaded, FALSE otherwise.

◆ register()

Galette\Common\ClassLoader::register ( )

Registers this ClassLoader on the SPL autoload stack.

Returns
void

◆ setFileExtension()

Galette\Common\ClassLoader::setFileExtension ( string  $fileExtension)

Sets the file extension of class files in the namespace of this ClassLoader.

Parameters
string$fileExtensionFile extension
Returns
void

◆ setIncludePath()

Galette\Common\ClassLoader::setIncludePath ( string  $includePath)

Sets the base include path for all class files in the namespace of this ClassLoader.

Parameters
string$includePathInclude path
Returns
void

◆ setNamespaceSeparator()

Galette\Common\ClassLoader::setNamespaceSeparator ( string  $sep)

Sets the namespace separator used by classes in the namespace of this ClassLoader.

Parameters
string$sepThe separator to use.
Returns
void

◆ unregister()

Galette\Common\ClassLoader::unregister ( )

Removes this ClassLoader from the SPL autoload stack.

Returns
void

The documentation for this class was generated from the following file: