PHP Class Kahlan\Jit\Interceptor

Show file Open project: crysalead/kahlan Class Usage Examples

Protected Properties

Property Type Description
$_add string Method name for adding a set of PSR-0 directories.
$_addPsr4 string Method name for adding a set of PSR-4 directories.
$_cachePath string Cache path. If false the caching is not enable.
$_exclude array Namespaces/classes which must not be patched.
$_findFile string Method name for finding files on original autoloader.
$_getPrefixes string Method name for adding a set of PSR-0 directories.
$_getPrefixesPsr4 string Method name for adding a set of PSR-4 directories.
$_include array Allowed namespaces/classes for being patched (if empty, mean all is allowed).
$_interceptor array Overrided loader reference.
$_loadClass string Method name for loading a class.
$_originalLoader array The patched loader reference.
$_patchers object The patchers container.
$_watched integer Additionnal watched files.
$_watchedTimestamp integer Most recent modification timestamps of the watched files.

Public Methods

Method Description
__call ( $method, $params ) : mixed Delegates call to original autoloader
__construct ( array $options = [] ) Constructs
allowed ( string $class ) : boolean Checks if a class is allowed to be patched.
cache ( string $file, string $content, $timestamp = null ) : string Cache helper.
cachePath ( ) : string Returns the cache path.
cached ( string $file ) : string | boolean Gets a cached file path.
clearCache ( ) Clear the cache.
composer ( ) : mixed Look for the composer autoloader.
findFile ( string $class ) : string | false Finds the path to the file where the class is defined.
findPath ( string $namespace, boolean $forceDir = false ) : string | null Returns the path of a namespace or fully namespaced class name.
getPrefixes ( ) : array Returns both PSR-0 & PSR-4 prefixes and related paths.
instance ( ) : object | null Returns the interceptor autoloader instance.
load ( $interceptor = null ) : boolean Loads an interceptor autoloader.
loadClass ( string $class ) : boolean | null Loads the given class or interface.
loadFile ( $filepath ) : boolean Loads a file.
loadFiles ( $files ) Manualy load files.
loader ( ) : array Returns the interceptor autoload function.
originalInstance ( ) : array Returns the patched autoloader instance.
originalLoader ( ) : array Returns the patched autoload function.
patch ( array $options = [] ) Patch the autoloader to be intercepted by the current autoloader.
patchable ( string $class ) : boolean Checks if a class can be patched or not.
patchers ( ) : mixed Returns the patchers container.
refreshWatched ( ) Refresh watched file timestamps
unpatch ( ) Restore the original autoloader behavior.
unwatch ( $files ) Unwatch a watched file
watch ( $files ) Sets some file to watch.
watched ( ) : The Returns watched files

Protected Methods

Method Description
_path ( string $path, boolean $forceDir ) : string | null Build full path according to a root path.

Method Details

__call() public method

Delegates call to original autoloader
public __call ( $method, $params ) : mixed
$method The method name.
$params The parameters
return mixed

__construct() public method

Constructs
public __construct ( array $options = [] )
$options array Options for the constructor.

_path() protected method

Build full path according to a root path.
protected _path ( string $path, boolean $forceDir ) : string | null
$path string A root path.
$forceDir boolean Only consider directories paths.
return string | null Returns the found path or `null` if not path is found.

allowed() public method

Checks if a class is allowed to be patched.
public allowed ( string $class ) : boolean
$class string The name of the class to check.
return boolean Returns `true` if the class is allowed to be patched, `false` otherwise.

cache() public method

Cache helper.
public cache ( string $file, string $content, $timestamp = null ) : string
$file string The source file path.
$content string The patched content to cache.
return string The patched file path or the cache path if called with no params.

cachePath() public method

Returns the cache path.
public cachePath ( ) : string
return string

cached() public method

Gets a cached file path.
public cached ( string $file ) : string | boolean
$file string The source file path.
return string | boolean The cached file path or `false` if the cached file is not valid or is not cached.

clearCache() public method

Clear the cache.
public clearCache ( )

composer() public static method

Look for the composer autoloader.
public static composer ( ) : mixed
return mixed The founded composer autolaoder or `null` if not found.

findFile() public method

Finds the path to the file where the class is defined.
public findFile ( string $class ) : string | false
$class string The name of the class
return string | false The path if found, false otherwise

findPath() public method

Returns the path of a namespace or fully namespaced class name.
public findPath ( string $namespace, boolean $forceDir = false ) : string | null
$namespace string A namespace.
$forceDir boolean Only consider directories paths.
return string | null Returns the found path or `null` if not path is found.

getPrefixes() public method

Returns both PSR-0 & PSR-4 prefixes and related paths.
public getPrefixes ( ) : array
return array

instance() public static method

Returns the interceptor autoloader instance.
public static instance ( ) : object | null
return object | null

load() public static method

Loads an interceptor autoloader.
public static load ( $interceptor = null ) : boolean
return boolean Returns `true` on success, `false` otherwise.

loadClass() public method

Loads the given class or interface.
public loadClass ( string $class ) : boolean | null
$class string The name of the class.
return boolean | null Returns `true` if loaded, `null` otherwise.

loadFile() public method

Loads a file.
public loadFile ( $filepath ) : boolean
return boolean Returns `true` if loaded, null otherwise.

loadFiles() public method

Manualy load files.
public loadFiles ( $files )

loader() public method

Returns the interceptor autoload function.
public loader ( ) : array
return array

originalInstance() public method

Returns the patched autoloader instance.
public originalInstance ( ) : array
return array

originalLoader() public method

Returns the patched autoload function.
public originalLoader ( ) : array
return array

patch() public static method

Patch the autoloader to be intercepted by the current autoloader.
public static patch ( array $options = [] )
$options array Options for the interceptor autoloader.

patchable() public method

Checks if a class can be patched or not.
public patchable ( string $class ) : boolean
$class string The name of the class to check.
return boolean Returns `true` if the class need to be patched, `false` otherwise.

patchers() public method

Returns the patchers container.
public patchers ( ) : mixed
return mixed

refreshWatched() public method

Refresh watched file timestamps
public refreshWatched ( )

unpatch() public static method

Restore the original autoloader behavior.
public static unpatch ( )

unwatch() public method

Unwatch a watched file
public unwatch ( $files )
$files The array of file paths to unwatch.

watch() public method

When a watched file is modified, any cached file are invalidated.
public watch ( $files )
$files The array of file paths to watch.

watched() public method

Returns watched files
public watched ( ) : The
return The array of wateched file paths.

Property Details

$_add protected property

Method name for adding a set of PSR-0 directories.
protected string $_add
return string

$_addPsr4 protected property

Method name for adding a set of PSR-4 directories.
protected string $_addPsr4
return string

$_cachePath protected property

Cache path. If false the caching is not enable.
protected string $_cachePath
return string

$_exclude protected property

Namespaces/classes which must not be patched.
protected array $_exclude
return array

$_findFile protected property

Method name for finding files on original autoloader.
protected string $_findFile
return string

$_getPrefixes protected property

Method name for adding a set of PSR-0 directories.
protected string $_getPrefixes
return string

$_getPrefixesPsr4 protected property

Method name for adding a set of PSR-4 directories.
protected string $_getPrefixesPsr4
return string

$_include protected property

Allowed namespaces/classes for being patched (if empty, mean all is allowed).
protected array $_include
return array

$_interceptor protected static property

Overrided loader reference.
protected static array $_interceptor
return array

$_loadClass protected property

Method name for loading a class.
protected string $_loadClass
return string

$_originalLoader protected property

The patched loader reference.
protected array $_originalLoader
return array

$_patchers protected property

The patchers container.
protected object $_patchers
return object

$_watched protected property

Additionnal watched files.
protected int $_watched
return integer

$_watchedTimestamp protected property

Most recent modification timestamps of the watched files.
protected int $_watchedTimestamp
return integer