Skip to content

Instantly share code, notes, and snippets.

@renan
Created September 20, 2012 12:13
Show Gist options
  • Save renan/3755544 to your computer and use it in GitHub Desktop.
Save renan/3755544 to your computer and use it in GitHub Desktop.
<?php
namespace App\Controller;
use App\Model\News;
class News {
public function test() {
News::doSomething();
}
}
<?php
namespace App\Model;
class News {
public static function doSomething() {
echo 'Done!';
}
}
<?php
set_include_path('App' . PATH_SEPARATOR . get_include_path());
/**
* Autoloader that implements the PSR-0 spec for interoperability between
* PHP software.
*/
spl_autoload_register(
function($className) {
$fileParts = explode('\\', ltrim($className, '\\'));
if (strpos(end($fileParts), '_') !== false) {
array_splice($fileParts, -1, 1, explode('_', current($fileParts)));
}
$file = implode(DIRECTORY_SEPARATOR, $fileParts) . '.php';
foreach (explode(PATH_SEPARATOR, get_include_path()) as $path) {
if (file_exists($path = $path . DIRECTORY_SEPARATOR . $file)) {
return require $path;
}
}
}
);
use App\Controller\News;
$controller = new News();
$controller->test();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment