PHP Class flight\core\Loader

显示文件 Open project: mikecao/flight Class Usage Examples

Protected Properties

Property Type Description
$classes array Registered classes.
$dirs array Autoload directories.
$instances array Class instances.

Public Methods

Method Description
addDirectory ( mixed $dir ) Adds a directory for autoloading classes.
autoload ( boolean $enabled = true, mixed $dirs = [] ) Starts/stops autoloader.
get ( string $name ) : mixed
getInstance ( string $name ) : object Gets a single instance of a class.
load ( string $name, boolean $shared = true ) : object Loads a registered class.
loadClass ( string $class ) Autoloads classes.
newInstance ( string | callable $class, array $params = [] ) : object Gets a new instance of a class.
register ( string $name, string | callable $class, array $params = [], callback $callback = null ) Registers a class.
reset ( ) Resets the object to the initial state.
unregister ( string $name ) Unregisters a class.

Method Details

addDirectory() public static method

Adds a directory for autoloading classes.
public static addDirectory ( mixed $dir )
$dir mixed Directory path

autoload() public static method

Starts/stops autoloader.
public static autoload ( boolean $enabled = true, mixed $dirs = [] )
$enabled boolean Enable/disable autoloading
$dirs mixed Autoload directories

get() public method

public get ( string $name ) : mixed
$name string Registry name
return mixed Class information or null if not registered

getInstance() public method

Gets a single instance of a class.
public getInstance ( string $name ) : object
$name string Instance name
return object Class instance

load() public method

Loads a registered class.
public load ( string $name, boolean $shared = true ) : object
$name string Method name
$shared boolean Shared instance
return object Class instance

loadClass() public static method

Autoloads classes.
public static loadClass ( string $class )
$class string Class name

newInstance() public method

Gets a new instance of a class.
public newInstance ( string | callable $class, array $params = [] ) : object
$class string | callable Class name or callback function to instantiate class
$params array Class initialization parameters
return object Class instance

register() public method

Registers a class.
public register ( string $name, string | callable $class, array $params = [], callback $callback = null )
$name string Registry name
$class string | callable Class name or function to instantiate class
$params array Class initialization parameters
$callback callback Function to call after object instantiation

reset() public method

Resets the object to the initial state.
public reset ( )

unregister() public method

Unregisters a class.
public unregister ( string $name )
$name string Registry name

Property Details

$classes protected_oe property

Registered classes.
protected array $classes
return array

$dirs protected_oe static_oe property

Autoload directories.
protected static array $dirs
return array

$instances protected_oe property

Class instances.
protected array $instances
return array