liberty_code/autoload

v1.0.0 2021-12-29 17:49 UTC

This package is auto-updated.

Last update: 2024-04-29 03:41:33 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

  1. Requirement

    It requires composer installation. For more information: https://getcomposer.org

  2. Command: Move in project root path

     cd "<project_root_path>"
    
  3. Command: Installation

     php composer.phar require liberty_code/autoload ["<version>"]
    
  4. 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 "/composer.json", following configuration:

        {
            "require": {
                "liberty_code/autoload": "<version>"
            }
        }
      

Include

  1. Download

    • Download following repository.
    • Put it on repository root path.
  2. 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();
...