Skip to content

Instantly share code, notes, and snippets.

@bilalucar
Created February 20, 2017 08:29
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save bilalucar/89d1674c3026762d9c217834e0abbc28 to your computer and use it in GitHub Desktop.
PSR-0
//autoload fonksiyonu, PSR-0 standartların nasıl otomatik yüklendiğini gösterir.
<?php
function autoload($className)
{
$className = ltrim($className, '\\');
$fileName = '';
$namespace = '';
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';
require $fileName;
}
spl_autoload_register('autoload');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment