php-debugbar icon indicating copy to clipboard operation
php-debugbar copied to clipboard

autoload without composer

Open shorif2000 opened this issue 9 years ago • 1 comments

Is there any way to autoload this without composer? environment i have, has no web access to use composer.

Error I keep getting is Fatal error: Class 'DebugBar\StandardDebugBar' not found in /var/SP/oiadm/docroot/dev/uddins/dashboard/test.php

my autoloader is in /common/php/oi_autoload.php

function oi_autoload($className) { $classParts = explode('', $className); $className = end($classParts); $lib_path = ''; $oi_autoload_paths = array( DIR . '/../../vendor/phpoffice/PHPExcel/', DIR .'/../../common/php/' );
print "\n\n $className  \n\n";


//pear type classes
$tmpClass = explode('_', $className); 
if (count($tmpClass)>1) {
    $className = $tmpClass[count($tmpClass)-1];
}



foreach($oi_autoload_paths as $path) {
    if(substr($path, -1) == '/') {
        $path = substr($path, 0, -1);
    }
    if($file = locateFile((STRING)$path, $className)) {
        if(OI_DEBUG) {
            print "\n loading $file \n";
        }
        require_once $file;
    }
}

}

function locateFile($dir, $className) { $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir,FilesystemIterator::SKIP_DOTS));

while($it->valid()) {

    if (!$it->isDot()) {
        if(OI_DEBUG) {
            echo 'SubPathName: ' . $it->getSubPathName() . "\n";
            echo 'SubPath:   ' . $it->getSubPath() . "\n";
            echo 'Key:       ' . $it->key() . "\n\n";
            echo 'FileName: ' . $it->getFilename() . "\n\n";
        }

        if ($it->getFilename() == $className.'.php') {
            return $it->key();
        }
    }

    $it->next();
}
return false;

}

function _locateFile($dir, $className) { $return = false; $ommit = array('.','..'); if (is_file($dir . DIRECTORY_SEPARATOR . $className . '.php')) { return $dir . DIRECTORY_SEPARATOR . $className . '.php'; }

    if (is_dir($dir)) {
        foreach(scandir($dir) as $item) {
                if(!in_array($item, $ommit)) {

                    if (is_file($dir . DIRECTORY_SEPARATOR . $item . DIRECTORY_SEPARATOR . $className . '.php')) {
                        return $dir . DIRECTORY_SEPARATOR . $item . DIRECTORY_SEPARATOR .$className . '.php';
                    }
                    if(is_dir($dir . DIRECTORY_SEPARATOR .  $item)) {
                            $return =  locateFile($dir . DIRECTORY_SEPARATOR .  $item, $className); 
                    }

                }
        }
    }
return $return;

}

spl_autoload_register('oi_autoload');

shorif2000 avatar Jan 20 '16 17:01 shorif2000

you could make a vendor folder on your computer and ftp that to use the composer autoloader.

grepsedawk avatar Jan 21 '16 17:01 grepsedawk