Sledgehammer Framework

Autoloader extends Base
in package
Uses Singleton

Load class and interface definitions on demand.

Improves performance (parsetime & memory usage), only classes that are used are loaded.

Validates definiton files according to $this->settings. Detects and corrects namespace issues.

Table of Contents

$enableCache  : bool
Bij true worden de resultaten (per module) gecached, de cache zal opnieuw opgebouwt worden als er bestanden gewijzigd of toegevoegd zijn.
$instances  : array<string|int, static>
The instances that are accessible by class::instance() [ 'id' => instance, // direct mapping to an instance 'id2' => 'id' // indirect mapping to an instance 'id3' => function () { return new Sington() } // lazy creation of an instance.
$resolveNamespaces  : bool
If a class or interface doesn't exist in a namespace use the class from a higher namespace.
$ambiguous  : array<string|int, mixed>
Array containing skipped ambiguous definitions.
$defaultSettings  : array<string|int, mixed>
Checks that are enabled when the module contains a classes folder.
$definitions  : array<string|int, mixed>
Array containing the filename per class or interface.
$path  : string
The project basepath.
__call()  : mixed
Report that the $method doesn't exist.
__callStatic()  : mixed
Report that the $method doesn't exist.
__construct()  : mixed
Constructor.
__get()  : mixed
Report that $property doesn't exist.
__set()  : mixed
Report that $property doesn't exist and set the property to the given $value.
__toString()  : string
The object is used as an string.
defaultInstance()  : mixed
define()  : mixed
include() the file containing the class of interface.
enable()  : mixed
Configure and register the AutoLoader
exposePrivates()  : mixed
Convert the scope of all properties and methods to public.
getDefinitions()  : array<string|int, mixed>
Returns all definitions the AutoLoaders has detected.
getFilename()  : string|null
Get the filename.
importFile()  : array<string|int, mixed>
Import the definition in a file.
importFolder()  : mixed
Import definitions inside a folder.
importModule()  : mixed
Import definitions inside a module.
instance()  : static
Get the singleton instance.
lazyRegister()  : mixed
loadDatabase()  : bool
Load definitions from a static file or detect definition for all modules.
saveDatabase()  : mixed
Save all imported definitions to database file.
fullPath()  : mixed
Geeft aan een absoluut path terug voor $filename.
hint()  : mixed
Report the notice but prevent the (Laravel) error_handler to throw an exception.
isLast()  : bool
Is this the last autoload function?
loadSettings()  : array<string|int, mixed>
Load settings from a ini file which overrides settings for that folder & subfolders.
mergeSettings()  : array<string|int, mixed>
Merge settings.
relativePath()  : mixed
Maakt van een absoluut path een relatief path (waar mogelijk).
resolveNamespace()  : bool
Import a class into the required namespace.
unexpectedToken()  : mixed
Report the offending token.

Properties

$enableCache

Bij true worden de resultaten (per module) gecached, de cache zal opnieuw opgebouwt worden als er bestanden gewijzigd of toegevoegd zijn.

public bool $enableCache = false

$instances

The instances that are accessible by class::instance() [ 'id' => instance, // direct mapping to an instance 'id2' => 'id' // indirect mapping to an instance 'id3' => function () { return new Sington() } // lazy creation of an instance.

public static array<string|int, static> $instances = []

].

$resolveNamespaces

If a class or interface doesn't exist in a namespace use the class from a higher namespace.

public bool $resolveNamespaces = true

$ambiguous

Array containing skipped ambiguous definitions.

private array<string|int, mixed> $ambiguous = []

$defaultSettings

Checks that are enabled when the module contains a classes folder.

private array<string|int, mixed> $defaultSettings = array( 'matching_filename' => false, // The classname should match the filename. 'mandatory_definition' => false, // A php-file should declare a class or interface 'mandatory_superclass' => false, // A class should extend another class (preferably \Sledgehammer\Object as base) 'one_definition_per_file' => false, // A php-file should only contain one class or inferface definition. 'ignore_folders' => ['.git'], // Exclude these folders (relative from autoloader.ini) otherwise use absolute paths 'ignore_files' => [], // Exclude these files (relative from autoloader.ini) otherwise use absolute paths 'revalidate_cache_delay' => 10, // Check/detect changes every x seconds. 'detect_accidental_output' => true, // Check if the php-file contains html parts (which would send the http headers) 'cache_level' => 1, // Number of (sub)folders to create caches for 'filesize_limit' => 524288, // Skip files larger than 512KiB (to prevent out of memory issues) 'notice_ambiguous' => true, )

The settings can be overridden with by placing an autoloader.ini in the offending folder.

$definitions

Array containing the filename per class or interface.

private array<string|int, mixed> $definitions = []

$path

The project basepath.

private string $path

Methods

__call()

Report that the $method doesn't exist.

public __call(string $method, array<string|int, mixed> $arguments) : mixed
Parameters
$method : string
$arguments : array<string|int, mixed>
Return values
mixed

__callStatic()

Report that the $method doesn't exist.

public static __callStatic(string $method, array<string|int, mixed> $arguments) : mixed
Parameters
$method : string
$arguments : array<string|int, mixed>
Return values
mixed

__construct()

Constructor.

public __construct(string $path) : mixed
Parameters
$path : string

Project path

Return values
mixed

__get()

Report that $property doesn't exist.

public __get(string $property) : mixed
Parameters
$property : string
Return values
mixed

__set()

Report that $property doesn't exist and set the property to the given $value.

public __set(string $property, mixed $value) : mixed
Parameters
$property : string
$value : mixed
Return values
mixed

__toString()

The object is used as an string.

public __toString() : string
Return values
string

defaultInstance()

public static defaultInstance() : mixed
Return values
mixed

define()

include() the file containing the class of interface.

public define(string $definition) : mixed
Parameters
$definition : string

Fully qualified class or interface name

Return values
mixed

enable()

Configure and register the AutoLoader

public static enable() : mixed
Return values
mixed

exposePrivates()

Convert the scope of all properties and methods to public.

public exposePrivates(string $definition[, string $targetDefinition = null ]) : mixed

Allows you to inspect the private parts of an object from unittests. Don't use exposePrivates in production code.

Parameters
$definition : string

Name of the definition with private properties en methods.

$targetDefinition : string = null

(optional) Specify an alternative classname for the exposed code.

Tags
throws
Exceptions

when the (target)definition is already defined. (Prevent the fatal error: "Cannot redeclare class/interface")

Return values
mixed

getDefinitions()

Returns all definitions the AutoLoaders has detected.

public getDefinitions() : array<string|int, mixed>
Return values
array<string|int, mixed>

getFilename()

Get the filename.

public getFilename(string $definition) : string|null
Parameters
$definition : string

Fully qualified class/interface name

Return values
string|null

Return null if the definion can't be found

importFile()

Import the definition in a file.

public importFile(string $filename[, array<string|int, mixed> $settings = [] ]) : array<string|int, mixed>
Parameters
$filename : string
$settings : array<string|int, mixed> = []
Return values
array<string|int, mixed>

definitions

importFolder()

Import definitions inside a folder.

public importFolder(string $path[, array<string|int, mixed> $settings = [] ]) : mixed

Checks "autoloader.ini" for additional settings.

Parameters
$path : string
$settings : array<string|int, mixed> = []
Return values
mixed

importModule()

Import definitions inside a module.

public importModule(array<string|int, mixed> $module) : mixed

Uses strict validation rules when the module contains a classes folder.

Parameters
$module : array<string|int, mixed>
Return values
mixed

instance()

Get the singleton instance.

public static instance([string $identifier = 'default' ]) : static
Parameters
$identifier : string = 'default'

The identifier (string),

Return values
static

lazyRegister()

public static lazyRegister(mixed $definition) : mixed
Parameters
$definition : mixed
Return values
mixed

loadDatabase()

Load definitions from a static file or detect definition for all modules.

public loadDatabase(string $filename[, bool $merge = false ][, int $expectedScanCount = false ]) : bool
Parameters
$filename : string

Location of the database file.

$merge : bool = false

Merge the definitions with the existing definitions. (false: overwrite all definitions)

$expectedScanCount : int = false

The expected scanCount in the database.

Return values
bool

saveDatabase()

Save all imported definitions to database file.

public saveDatabase(string $filename[, null|string $pathFilter = null ][, int $scanCount = false ]) : mixed
Parameters
$filename : string

The location of the database file.

$pathFilter : null|string = null

Only save definition in this path. null: saves all imported definitions.

$scanCount : int = false

The number of files scanned (for delete detection)

Return values
mixed

fullPath()

Geeft aan een absoluut path terug voor $filename.

private fullPath(string $filename) : mixed
Parameters
$filename : string

relatief of absoluut path van het bestand

Return values
mixed

hint()

Report the notice but prevent the (Laravel) error_handler to throw an exception.

private static hint(mixed $message[, mixed $information = null ]) : mixed
Parameters
$message : mixed
$information : mixed = null
Return values
mixed

isLast()

Is this the last autoload function?

private isLast() : bool
Return values
bool

loadSettings()

Load settings from a ini file which overrides settings for that folder & subfolders.

private loadSettings(string $path[, array<string|int, mixed> $settings = [] ]) : array<string|int, mixed>
Parameters
$path : string
$settings : array<string|int, mixed> = []
Return values
array<string|int, mixed>

mergeSettings()

Merge settings.

private mergeSettings(array<string|int, mixed> $settings[, array<string|int, mixed> $overrides = [] ]) : array<string|int, mixed>
Parameters
$settings : array<string|int, mixed>
$overrides : array<string|int, mixed> = []
Return values
array<string|int, mixed>

relativePath()

Maakt van een absoluut path een relatief path (waar mogelijk).

private relativePath( $filename) : mixed
Parameters
$filename :

Absoluut path

Return values
mixed

resolveNamespace()

Import a class into the required namespace.

private resolveNamespace(string $definition) : bool
Parameters
$definition : string

Fully qualified class/interface name

Return values
bool

unexpectedToken()

Report the offending token.

private unexpectedToken(string|array<string|int, mixed> $token) : mixed
Parameters
$token : string|array<string|int, mixed>
Return values
mixed

Search results