PHP Class Jamm\Autoload\Autoloader

A fully-qualified namespace and class must have the following structure \\(\)* Each namespace must have a top-level namespace ("Vendor Name"). Each namespace can have as many sub-namespaces as it wishes. Each namespace separator is converted to DIRECTORY_SEPARATOR when loading from the file system. Each "_" character in the CLASS NAME is converted to DIRECTORY_SEPARATOR. The "_" character has no special meaning in the namespace. The fully-qualified namespace and class is suffixed with ".php" when loading from the file system. Alphabetic characters in vendor names, namespaces, and class names may be of any combination of lower case and upper case. Default place of "vendors" folder is __DIR__.'/../../' directory, you can change it: use set_modules_dir() method Classes of all packages (libraries), placed in the "vendors" folder, will be autoloaded automatically (in first use). You can map namespace of package, placed in any folder: use register_namespace_dir() method. You can map any class also: use register_class() method. In case of errors E_USER_WARNING will be triggered Methods of this class doesn't throws exceptions
Author: OZ ([email protected])
Show file Open project: jamm/memory

Protected Properties

Property Type Description
$classes
$functions
$modules_dir
$namespaces_dirs
$search_log
$warn_about_not_found

Public Methods

Method Description
__construct ( boolean $autostart = true )
autoload ( string $class_name ) : boolean
get_modules_dir ( ) : string Return modules dir like "/home/dir/modules" By default will be taken directory of this file without two last folders (__DIR__.'/.
get_namespaces ( )
get_search_log ( )
register_class ( string $class_name, string $path ) : boolean Register class - associate name of the class with path to the file (mapping)
register_namespace_dir ( string $namespace, string $dir ) Associate namespace with directory For example, if namespace '\name\space' will be associated with directory '/home/name/space', class '\name\space\subnamespace\Class_Name.php' will be looked in /home/name/space/subnamespace/Class_Name.php
set_modules_dir ( string $dir ) : void Set directory of modules ("vendors")
set_warn_about_not_found ( $warn_about_not_found = true )
start ( ) start autoloader (register in spl_autoload)

Protected Methods

Method Description
define_home_dir_constant ( ) Define HOME_DIR - by this constant other modules can check, if autoloader is exists
generate_filepath ( $dir, $class_path )
include_class_file ( $class_name, $file )
log_search_variant ( string $method_title, string $class_name, string $filepath = '' ) Add next variant of filepath from searching method to the log

Private Methods

Method Description
find_in_classes ( string $class_name ) : boolean Find classname in registered classes
find_in_namespaces ( string $class ) : boolean | string Find path to the file of class in registered namespaces (root namespace is registered automatically)
lookFileInNamespaceDir ( $class_namespace, $mapped_namespace, $class_name, $mapped_dir )
register_root_namespace ( ) : void Register "vendors" directory as root namespace
warning_class_not_found ( $class_name )

Method Details

__construct() public method

public __construct ( boolean $autostart = true )
$autostart boolean - call method start in constructor

autoload() public method

public autoload ( string $class_name ) : boolean
$class_name string
return boolean

define_home_dir_constant() protected method

Define HOME_DIR - by this constant other modules can check, if autoloader is exists
protected define_home_dir_constant ( )

generate_filepath() protected method

protected generate_filepath ( $dir, $class_path )

get_modules_dir() public method

./../')
public get_modules_dir ( ) : string
return string

get_namespaces() public method

public get_namespaces ( )

get_search_log() public method

public get_search_log ( )

include_class_file() protected method

protected include_class_file ( $class_name, $file )

log_search_variant() protected method

Add next variant of filepath from searching method to the log
protected log_search_variant ( string $method_title, string $class_name, string $filepath = '' )
$method_title string
$class_name string
$filepath string

register_class() public method

Register class - associate name of the class with path to the file (mapping)
public register_class ( string $class_name, string $path ) : boolean
$class_name string
$path string
return boolean

register_namespace_dir() public method

Associate namespace with directory For example, if namespace '\name\space' will be associated with directory '/home/name/space', class '\name\space\subnamespace\Class_Name.php' will be looked in /home/name/space/subnamespace/Class_Name.php
public register_namespace_dir ( string $namespace, string $dir )
$namespace string name\space\ (last symbol - slash, and no slashes in start)
$dir string

set_modules_dir() public method

Set directory of modules ("vendors")
public set_modules_dir ( string $dir ) : void
$dir string
return void

set_warn_about_not_found() public method

public set_warn_about_not_found ( $warn_about_not_found = true )

start() public method

start autoloader (register in spl_autoload)
public start ( )

Property Details

$classes protected property

protected $classes

$functions protected property

protected $functions

$modules_dir protected property

protected $modules_dir

$namespaces_dirs protected property

protected $namespaces_dirs

$search_log protected property

protected $search_log

$warn_about_not_found protected property

protected $warn_about_not_found