Created
May 11, 2012 08:18
-
-
Save cmbuckley/2658317 to your computer and use it in GitHub Desktop.
Example structure for http://stackoverflow.com/q/10542012
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 | |
// file: ./bootstrap.php | |
spl_autoload_register(function($className) { | |
$className = ltrim($className, '\\'); | |
$fileName = ''; | |
$namespace = ''; | |
if ($lastNsPos = strripos($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'; | |
var_dump($fileName); // to see which file is loaded | |
require $fileName; | |
}); | |
new Shape\Circle(); |
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 | |
// file: ./Shape/Circle.php | |
namespace Shape; | |
class Circle extends Shape implements ShapeInterface { | |
public function __construct() { | |
var_dump($this); | |
} | |
} |
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 | |
// file: ./Shape/Shape.php | |
namespace Shape; | |
abstract class Shape {} |
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 | |
// file: ./Shape/ShapeInterface.php | |
namespace Shape; | |
interface ShapeInterface {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment