php bootstrap.php - old school coding with a 2016 approach

<?php // NogEffe Management System: bootstrap.php // old school coding standards with a 2016 approach // 0.0.1 - 2016-02-09 - https://codepad.co/cheers define('NEMS_BASE', dirname(__FILE__)); /* override or add default directories; NEMS_APP NEMS_CONFIG NEMS_STORAGE NEMS_TEMPLATES */ define('NEMS_MICROSTART', microtime(true)); // Create required exception classes to make sure the errors are shown as they are supposed to class ClassNotFoundException extends Exception { protected $message = 'Class not found'; // Exception message private $string; // Unknown protected $code = 0; // User-defined exception code protected $file; // Source filename of exception protected $line; // Source line of exception private $trace; // Unknown public function __construct($message = null, $code = 0) { if (!$message) { throw new $this('Unknown '. get_class($this)); } parent::__construct($message, $code); } public function __toString() { $maskedFile = str_replace(dirname(dirname(__FILE__)), '', $this->file); $maskedTrace = $this->getTrace(); $maskedTrace[0] = ['function' => 'ClassNotFound', 'init' => 'bootstrap']; unset($maskedTrace[1]); $maskedTrace = array_values($maskedTrace); return "Class \"{$this->message}\" in {$maskedFile} on line {$this->line} could not be found. Traceback:\n" . print_r($maskedTrace, true); } } // Autoload register based on a simple method; Directory\Name\File(.php | strtolower) spl_autoload_register(function ($class) { if (file_exists($filePath = strtolower(dirname(dirname(__FILE__)) . '/' . str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php'))) { require_once $filePath; return; } // Throw the exception to make sure it gets handled appropriately throw new ClassNotFoundException($class); }); // Create the initial bootstrap with required classes; these don't exist, we can't run try { new DefinitlyNotFound(''); } // Definitly a big ass error, or they're installing/moving/whatever. Better give some info catch (ClassNotFoundException $e) { exit('<pre>' . $e->__toString() . '</pre>'); }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.