/** * Registers an autoloader instance SPL with highest priority for loading classes of the app. * * @param object $app The app configuration object * * @author Benjamin Carl <*****@*****.**> */ protected function registerAutoloader($app) { // now configure a new autoloader spl configuration $autoloaderApp = new Doozr_Loader_Autoloader_Spl_Config(); $autoloaderApp->_namespace($app->namespace)->namespaceSeparator('_')->addExtension('php')->path(substr($app->path, 0, -1))->description('Autoloader for App classes with namespace: "' . $app->namespace . '"')->priority(0); Doozr_Loader_Autoloader_Spl_Facade::attach([$autoloaderApp]); }
require_once DOOZR_DOCUMENT_ROOT . 'Doozr/Loader/Autoloader/Spl/Facade.php'; // now configure a new autoloader spl configuration $autoloaderDoozr = new Doozr_Loader_Autoloader_Spl_Config(); $autoloaderDoozr->_namespace('Doozr')->namespaceSeparator('_')->addExtension('php')->path(substr(DOOZR_DOCUMENT_ROOT, 0, -1))->description('Doozr\'s autoloader for loading classes of Doozr below "src/".')->priority(0); /* * Autoloader for Doozr - Services (native) */ $autoloaderService = new Doozr_Loader_Autoloader_Spl_Config(); $autoloaderService->_namespace('Doozr')->namespaceSeparator('_')->addExtension('php')->path(DOOZR_DOCUMENT_ROOT . 'Service')->description('Doozr\'s autoloader for loading Services of Doozr below "src/Service".')->priority(1); /* * The facade itself is auto instanciating singleton within the * register method if not already instantiated! So don't worry * just call the register() method pass a configuration and everything * is handled magically (: */ Doozr_Loader_Autoloader_Spl_Facade::attach(array($autoloaderDoozr, $autoloaderService)); /*---------------------------------------------------------------------------------------------------------------------- | ERROR & EXCEPTION-HANDLING (HOOK) ---------------------------------------------------------------------------------------------------------------------*/ // Install error handler which is used in case that DOOZR_APP_ENVIRONMENT is not development (= make use of Whoops) if (Doozr_Kernel::APP_ENVIRONMENT_TESTING !== DOOZR_APP_ENVIRONMENT) { // ERROR-HANDLER: register error-handler require_once DOOZR_DOCUMENT_ROOT . 'Doozr/Handler/Error.php'; // Set own error_handler set_error_handler(array('Doozr_Handler_Error', 'handle')); // Hook for theoretically "unhandable error(s)" like E_PARSE (smart-hack) register_shutdown_function(array('Doozr_Handler_Error', 'handleUnhandable')); // EXCEPTION-HANDLER: register exception-handler require_once DOOZR_DOCUMENT_ROOT . 'Doozr/Handler/Exception.php'; // Set own exception_handler set_exception_handler(array('Doozr_Handler_Exception', 'handle'));
/** * Initialize autoloader for this service. * * Each service get its own autoloader attached to SPL autoloaders. * * @param string $service The name of the service to init autoloader for * * @author Benjamin Carl <*****@*****.**> * @return void * @access protected */ protected function initAutoloader($service) { // Register services custom autoloader $autoloaderService = new Doozr_Loader_Autoloader_Spl_Config(); $autoloaderService->_namespace('Doozr_' . $service)->namespaceSeparator('_')->addExtension('php')->path(DOOZR_DOCUMENT_ROOT . 'Service')->description('Doozr\'s ' . $service . ' service autoloader. Timestamp: ' . time()); // Add to SPL through facade $this->autoloader = Doozr_Loader_Autoloader_Spl_Facade::attach($autoloaderService); }
/** * This method is intend to initialize the basic setup. * * @param bool $checkMagicAutoload TRUE to keep magic function __autoload working, otherwise FALSE * * @author Benjamin Carl <*****@*****.**> * @return void * @access public * @static */ public static function init($checkMagicAutoload = true) { // check first if init wasn't done already if (!self::$initialized) { // clear stack spl_autoload_register(null, false); // check if a magic __autoload function exists if ($checkMagicAutoload && function_exists('__autoload')) { spl_autoload_register('__autoload'); } // mark init done self::$initialized = true; } }