<?php

class CommoditechAppsAutoload
{
    public function __construct()
    {
        $directoriesToScan = [
            'includes',
        ];

        foreach( $directoriesToScan as $directoryToScan ) {
            $this->scanDir($directoryToScan);
        }
    }

    private function scanDir(string $dir): void
    {
        $fullPath = __DIR__ . "/$dir";

        $filesToRequire = array_diff(scandir($fullPath), array('..', '.'));
        foreach( $filesToRequire as $fileToRequire ) {
            if(strpos($fileToRequire, ".php") === false) {
                $this->scanDir("$dir/$fileToRequire");
                continue;
            }

            require_once "$fullPath/$fileToRequire";
        }
    }
}

new CommoditechAppsAutoload();