liberty_code / autoload
Library
Requires
- php: ~7 || ~8
- liberty_code/di: ^1.0.
- liberty_code/library: ^1.0.
This package is auto-updated.
Last update: 2025-01-29 05:22:42 UTC
README
Description
Library contains auto-loading components, allows to manage automatically file inclusion, using rules system.
Requirement
- Script language: PHP: version 7 || 8
Installation
Several ways are possible:
Composer
Requirement
It requires composer installation. For more information: https://getcomposer.org
Command: Move in project root path
cd "<project_root_path>"
Command: Installation
php composer.phar require liberty_code/autoload ["<version>"]
Note
Include vendor
If project uses composer, vendor must be included:
require_once('<project_root_path>/vendor/autoload.php');
Configuration
Installation command allows to add, on composer file "
{ "require": { "liberty_code/autoload": "<version>" } }
Include
Download
- Download following repository.
- Put it on repository root path.
Include source
require_once('<repository_root_path>/include/Include.php');
Configuration
Main configuration
Use following class to configure specific elements
use liberty_code\autoload\config\model\DefaultConfig; DefaultConfig::instanceGetDefault()->get|set...();
Elements configurables
- Regular expression options, used in rules
- Global information
Usage
Rule
Rules system allows to retrieve file path from specified source.
Elements
Rule
Allows to design a rule, who is an item containing configuration array:
- To check matching, from a specified string source.
- To get file path, from a specified string source.
PatternRule
Extends rule features. Uses regular expressions in configuration array, to check matching and get file path, from a specified string source.
RuleCollection
Allows to design collection of rules. Uses list of rules:
- To check matching, from a specified string source.
- To get file path, from a specified string source.
RuleFactory
Allows to design a rule factory, to provide new or specified rule instance, from specified configuration.
StandardRuleFactory
Extends rule factory features. Provides rule instance.
Example
// Get rule factory
use liberty_code\autoload\rule\factory\standard\model\StandardRuleFactory;
$ruleFactory = new StandardRuleFactory();
...
// Get new rule from configuration
$rule = $ruleFactory->getObjRule(array(...));
...
Builder
Builder allows to hydrate rule collection with rules, from a specified data source.
Elements
DefaultBuilder
Uses array of source data to hydrate rule collection.
Example
// Get rule collection
use liberty_code\autoload\rule\model\DefaultRuleCollection;
$ruleCollection = new DefaultRuleCollection();
...
// Get rule builder
use liberty_code\autoload\build\model\DefaultBuilder;
$ruleBuilder = new DefaultBuilder($ruleFactory);
...
// Hydrate rule collection
$ruleBuilder->setTabDataSrc(array(...));
$ruleBuilder->hydrateRuleCollection($ruleCollection);
...
foreach($ruleCollection->getTabKey() as $key) {
echo($ruleCollection->getObjRule($key)->getStrKey() . '<br />');
}
/**
* Show:
* Rule key 1
* ...
* Rule key N
*/
...
Loader
Loader allows to register auto-loading function, using rule collection.
Example
use liberty_code\autoload\load\model\Loader;
$loader = Loader::instanceGetDefault();
$loader->setObjRuleCollection($ruleCollection);
...
// Autoload registering
$loader->registerSet();
...