Skip to content

Instantly share code, notes, and snippets.

@sshilko
Last active January 14, 2016 20:00
Show Gist options
  • Select an option

  • Save sshilko/edaf7863d4738fb51868 to your computer and use it in GitHub Desktop.

Select an option

Save sshilko/edaf7863d4738fb51868 to your computer and use it in GitHub Desktop.

Revisions

  1. sshilko renamed this gist Jan 14, 2016. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. sshilko created this gist Jan 14, 2016.
    41 changes: 41 additions & 0 deletions psr0autoload.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    <?php
    /**
    * PSR-0 Autoloader
    * http://www.php-fig.org/psr/psr-0/
    * works PHP5 & PHP7
    * @sshilko
    */
    function autoload_psr0($className)
    {
    $oname = $className;
    $className = ltrim($className, '\\');
    $fileName = '';
    if ($lastNsPos = strrpos($className, '\\')) {
    $namespace = substr($className, 0, $lastNsPos);
    $className = substr($className, $lastNsPos + 1);
    $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
    }
    $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
    $filePath = stream_resolve_include_path($fileName);
    if ($filePath) {
    /**
    * put your mostly used files high in include_path
    * some frequent packages are directly mapped
    * to prevent full composer autoloaded
    */
    return include $filePath;
    } else {
    /**
    * Only need autoloader once
    * check correct paths
    */
    if (!isset($GLOBALS['composer_autoloaded'])) {
    $GLOBALS['composer_autoloaded'] = true;
    $loader = require __DIR__ . '/../composer/autoload.php';
    $loader->loadClass($oname);
    }
    return false;
    }
    }
    //include __DIR__ . '/../composer/autoload.php';
    spl_autoload_register('autoload_psr0');