PHP code example of morningtrain / php-loader

1. Go to this page and download the library: Download morningtrain/php-loader 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/ */

    

morningtrain / php-loader example snippets


    // Loading all PHP files in ./MyDir
    use Morningtrain\PHPLoader\Loader;
    
    Loader::create(__DIR__ . '/MyDir');

    // Loading all PHP files in ./MyDir and ./MyOtherDir
    use Morningtrain\PHPLoader\Loader;
    
    Loader::create([__DIR__ . '/MyDir',__DIR__ . '/MyOtherDir']);

    // Loading all PHP files that end with "Foo" in ./MyDir
    use Morningtrain\PHPLoader\Loader;
    
    Loader::create(__DIR__ . '/MyDir')
        ->fileName('*Foo.php');

    // Loading all PHP files in ./MyDir and invoke them if they have the method myMethod
    use Morningtrain\PHPLoader\Loader;
    
    Loader::create(__DIR__ . '/MyDir')
        ->hasMethod('myMethod')
        ->invoke();

    // Loading all PHP files in ./MyDir and call a static method on it if it is of the class Foo
    use Morningtrain\PHPLoader\Loader;
    
    Loader::create(__DIR__ . '/MyDir')
        ->isA(\Foo::class)
        ->callStatic('myMethod');

    // Loading all PHP files in ./MyDir and call a static method on it if it is of the class Foo
    use Morningtrain\PHPLoader\Loader;
    
    Loader::create(__DIR__ . '/MyDir')
        ->isA(\Foo::class)
        ->callStatic('myMethod');

    // Loading all PHP files in ./MyDir, construct them and then call 'myMethod'
    use Morningtrain\PHPLoader\Loader;
    
    Loader::create(__DIR__ . '/MyDir')
        ->call('myMethod');
bash
composer