Last active
December 12, 2015 12:18
-
-
Save bobmagicii/4770620 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 an exception handler so that we can render nice errors when bad thigns | |
// happen instead of spaming the user with garbage. | |
set_exception_handler(function(){ | |
echo 'somebody derped in the waterhole'; | |
// your framework logging utility to log this | |
// ... | |
// goes here. | |
}); | |
// a super simplified theme engine. | |
class ThemeEngine { | |
protected $HasRendered = false; | |
public function __destruct() { | |
if(!$this->HasRendered) $this->Render(); | |
} | |
public function Render() { | |
throw new Exception('Theme Not Found!'); | |
} | |
} | |
// my framework manages a copy of the theme engine for me, so i do not need to | |
// create it nor destroy it. by design when the script ended i wanted it to be | |
// smart and say "oh end of script? i haven't rendered! i'll do it now!" | |
$theme = new ThemeEngine; | |
// so lets pretend this instance above was actually created by the system and | |
// we do not have to explicitly interact with it except when we want. now lets | |
// let the script end... the exact same things are going to happen, the object | |
// is going to destruct and attempt to render a page, but not be able to find | |
// the theme. | |
/* | |
Fatal error: Uncaught exception 'Exception' with message 'Theme Not Found!' | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment