Dotclear  2.29
 All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
Autoloader Class Reference

The helper to autoload class using php namespace. More...

Public Member Functions

 __construct (string $root_prefix= '', string $root_base_dir= '', bool $prepend=false)
 
 getRootPrefix ()
 
 getRootBaseDir ()
 
 normalizePrefix (string $prefix)
 
 normalizeBaseDir (string $base_dir)
 
 qualifyNamespace (string $str)
 
 addNamespace (string $prefix, string $base_dir, bool $prepend=false)
 
 getNamespaces ()
 
 loadClass (string $class)
 
 getLoadsCount ()
 
 getRequestsCount ()
 

Static Public Member Functions

static me ()
 

Data Fields

const DIR_SEP = DIRECTORY_SEPARATOR
 
const NS_SEP = '\\'
 

Private Member Functions

 loadMappedFile (string $prefix, string $relative_class)
 
 requireFile (string $file)
 

Private Attributes

string $root_prefix = ''
 
string $root_base_dir = ''
 
array $prefixes = []
 
int $loads_count = 0
 
int $request_count = 0
 

Static Private Attributes

static self $instance
 

Detailed Description

The helper to autoload class using php namespace.

Based on PSR-4 Autoloader https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md

A root prefix and base directory can be added to all ns to work with non full standardized project.

Since
2.25

Constructor & Destructor Documentation

__construct ( string  $root_prefix = '',
string  $root_base_dir = '',
bool  $prepend = false 
)

Register loader with SPL autoloader stack.

Parameters
string$root_prefixCommon ns prefix
string$root_base_dirCommon dir prefix
bool$prependAdd loader on top of stack

References loadClass(), normalizeBaseDir(), and normalizePrefix().

Here is the call graph for this function:

Member Function Documentation

static me ( )
static

Get Autoloader singleton instance.

Returns
self

Referenced by dcCore\__construct(), App\autoload(), Page\debugInfo(), and Modules\loadModules().

Here is the caller graph for this function:

getRootPrefix ( )

Get root prefix.

Returns
string Root prefix

References $root_prefix.

getRootBaseDir ( )

Get root base directory.

Returns
string Root base directory

References $root_base_dir.

normalizePrefix ( string  $prefix)

Normalize namespace prefix.

Parameters
string$prefixNs prefix
Returns
string Prefix with only right namesapce separator

Referenced by __construct(), addNamespace(), and qualifyNamespace().

Here is the caller graph for this function:

normalizeBaseDir ( string  $base_dir)

Normalize base directory.

Parameters
string$base_dirDir prefix
Returns
string Base dir with right directory separator

Referenced by __construct(), and addNamespace().

Here is the caller graph for this function:

qualifyNamespace ( string  $str)

Clean up a string into namespace part.

Parameters
string$strString to clean
Returns
null|string Cleaned string or null if empty

References normalizePrefix().

Here is the call graph for this function:

addNamespace ( string  $prefix,
string  $base_dir,
bool  $prepend = false 
)

Adds a base directory for a namespace prefix.

Parameters
string$prefixThe namespace prefix
string$base_dirA base directory for class files in the namespace
bool$prependIf true, prepend the base directory to the stack instead of appending it; this causes it to be searched first rather than last

References normalizeBaseDir(), and normalizePrefix().

Here is the call graph for this function:

getNamespaces ( )

Get list of registered namespace.

Returns
array<string,array<int,string>> List of namesapce prefix / base dir

References $prefixes.

loadClass ( string  $class)

Loads the class file for a given class name.

Parameters
string$classThe fully-qualified class name
Returns
null|string The mapped file name on success, or null on failure

References $request_count, and loadMappedFile().

Referenced by __construct().

Here is the call graph for this function:

Here is the caller graph for this function:

loadMappedFile ( string  $prefix,
string  $relative_class 
)
private

Load the mapped file for a namespace prefix and relative class.

Parameters
string$prefixThe namespace prefix
string$relative_classThe relative class name
Returns
null|string Null if no mapped file can be loaded, or the name of the mapped file that was loaded

References requireFile().

Referenced by loadClass().

Here is the call graph for this function:

Here is the caller graph for this function:

requireFile ( string  $file)
private

If a file exists, require it from the file system.

Parameters
string$fileThe file to require
Returns
bool True if the file exists, false if not

References $loads_count.

Referenced by loadMappedFile().

Here is the caller graph for this function:

getLoadsCount ( )

Get number of loads on this autoloader.

Returns
int Number of loads

References $loads_count.

getRequestsCount ( )

Get number of requests on this autoloader.

Returns
int Number of requests

References $request_count.

Field Documentation

string DIR_SEP = DIRECTORY_SEPARATOR

Directory separator.

string $root_prefix = ''
private

Root namespace prepend to added ns.

Referenced by getRootPrefix().

string $root_base_dir = ''
private

Root directory prepend to added ns.

Referenced by getRootBaseDir().

array $prefixes = []
private

Referenced by getNamespaces().

int $loads_count = 0
private

Keep track of loads count.

Referenced by getLoadsCount(), and requireFile().

int $request_count = 0
private

Keep track of request count.

Referenced by getRequestsCount(), and loadClass().

Autoloader $instance
staticprivate

Instance singleton.


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