PHP code example of 00f100 / fcphp-autoload

1. Go to this page and download the library: Download 00f100/fcphp-autoload library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

00f100 / fcphp-autoload example snippets




return [
    \path\to\SomeClass::class,
    \path\to\package\Cool::class
];



return [
    'path/to/route' => [
        'post' => 'SiteController@method'
    ]
];



use FcPhp\Autoload\Autoload;

/**
 * Method to load path and find match's
 *
 * @param string $pathExpression Directory to find file(s)
 * @param array $fileNameMatch List of filename
 * @param array $extensionMatch List of enable extensions
 * @return void
 */
$autoload = Autoload::getInstance();
$autoload->path(string $pathExpression, array $fileNameMatch, array $extensionMatch);

/*
    Example to find inside composer directory

    ============================================
    Example directory:
    ============================================

    vendor/
        00f100/
            fcphp-di/
                autoload/
                    providers.php
                    prividers.txt
            fcphp-i18n/
            fcphp-provider/
                autoload/
                    routes.php
        doctrine/
            doctrine/
            instructor/
        cake/
            bin/
            cake/
                autoload/
                    providers.php

*/
$autoload->path('vendor/*/*/autoload', ['providers', 'routes'], ['php']);
/*
    ============================================
    Below example match this files:
    ============================================

    vendor/00f100/fcphp-di/autoload/providers.php
    vendor/00f100/fcphp-provider/autoload/routes.php
    vendor/cake/cake/autoload/providers.php
*/

/*
    ============================================
    Get the content using 'get' method
    ============================================
    [
        'path/to/route' => [
            'post' => 'SiteController@method'
        ]
    ]
    $arrayProviders = $autoload->get('providers');

    [
        \path\to\SomeClass,
        \path\to\package\Cool
    ]
    $arrayRoutes = $autoload->get('routes');
*/
/**
 * Method to return autoloaded files
 *
 * @param string $key Filename
 * @return array
 */
$autoload->get(string $fileName);



$instance->beforeMatch(function(string $pathExpression, array $fileNameMatch, array $extensionMatch) {
    // your code here
});



$instance->beforeMatchAgain(function(array $paths, array $files, array $extensions, string $path, string $now) {
    // your code here
});



$instance->beforeStorage(function(string $file, string $filePath) {
    // your code here
});