Created
September 20, 2012 12:13
-
-
Save renan/3755544 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Controller; | |
use App\Model\News; | |
class News { | |
public function test() { | |
News::doSomething(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Model; | |
class News { | |
public static function doSomething() { | |
echo 'Done!'; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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