Skip to content

ruslan-avantis/auto-require

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AutoRequire

Autoload to PSR-0 and PSR-4 standards without Composer

define("BASE_PATH", dirname(__FILE__));
define("APP_PATH", BASE_PATH . '/..');
define("CORE_PATH", APP_PATH . '/core');

// Looking for the path to the vendor folder
if (file_exists(APP_PATH . '/vendor')) {
    define("VENDOR_PATH", BASE_PATH . '/vendor');
} elseif (APP_PATH . '/../vendor') {
    define("VENDOR_PATH", BASE_PATH . '/../vendor');
}

// Specify the path to the file AutoRequire
$autoRequire = VENDOR_PATH .'/AutoRequire.php';
// Specify the path to the file auto_require.json
$auto_require = VENDOR_PATH .'/auto_require.json';

if (file_exists($autoRequire) && file_exists($auto_require)) {

    // We get the list and configuration of packages
    $package = json_decode(file_get_contents($auto_require), true);
    // Connect \Pllano\AutoRequire\Autoloader
    require $autoRequire;
    // instantiate the loader
    $require = new \Pllano\AutoRequire\Autoloader();
    // Start AutoRequire\Autoloader
    $require->run(VENDOR_PATH, $auto_require);
    // Additionally, register your namespace
    $require->addNamespace('\App\Core', CORE_PATH);
    
}

The same with the minimum code

// Connect the AutoRequire file
require __DIR__ . '/../vendor/AutoRequire.php';
// Start Autoloader
(new \AutoRequire\Autoloader)->run(__DIR__ . '/../vendor', __DIR__ . '/../vendor/auto_require.json');

auto_require.json

  • namespace - Namespace
  • files - File name
  • dir - The directory in which, after unpacking the archive, there will be package files
  • link - Direct link to the zip package archive
  • name - Directory name package
  • vendor - Directory name vendor
  • version - Package version

Examples

auto_require.json

auto_require.json

Your Class

{
    "require": [
        {
            "namespace": "YourName\\YourClass",
            "dir": "/your-name/your-class"
        }
    ]
}

Connect file

{
    "require": [
        {
            "files": "file_name.php",
            "dir": "/your-name/your-dir"
        }
    ]
}

Connect package

{
    "require": [
        {
            "namespace": "VendorName\\ClassName",
            "dir": "/vendor-name/class-name/src",
            "link": "https://github.com/vendor-name/class-name/archive/1.0.1.zip",
            "git": "",
            "name": "class-name",
            "version": "1.0.1",
            "vendor": "vendor-name",
            "state": 1,
            "system_package": 1,
            "settings": {
                "debug": 0
            }
        }
    ]
}

Connect Slim 4

"slim.slim": {
    "namespace": "Slim",
    "dir": "\/slim\/Slim\/Slim",
    "link": "https:\/\/github.com\/slimphp\/Slim\/archive\/4.x.zip",
    "git": "https:\/\/github.com\/slimphp\/Slim",
    "name": "Slim",
    "version": "4.x",
    "vendor": "slim",
    "state": 1,
    "system_package": 1,
    "settings": {
        "debug": 0,
        "displayErrorDetails": 0,
        "addContentLengthHeader": 0,
        "determineRouteBeforeAppMiddleware": 1
    }
}

Support, feedback, news

Contact: open.source@pllano.com

License

The MIT License (MIT). Please see LICENSE for more information.

About

AutoRequire - Auto-load namespace by PSR-0 and PSR-4 standards

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages