Created
July 11, 2013 17:22
-
-
Save geilt/5977401 to your computer and use it in GitHub Desktop.
Registry Class
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 | |
| /** | |
| * Registry | |
| * Used as an Object Store of all Data used through a page load. It is a static class with a protected static variable. | |
| * All Data is meant to be built off the registry that needs to be passed around instead of using Global Variables | |
| * @package SimpulFramework | |
| * @version 1.0 | |
| */ | |
| class Registry{ | |
| protected static $object = array(); | |
| public static function exists($key, $var = false) { | |
| if($var) | |
| return isset(Registry::$object[$key]->{$var}); | |
| else | |
| return isset(Registry::$object[$key]); | |
| } | |
| public static function get($key, $var = false) { | |
| if(Registry::exists($key, $var)): | |
| if($var) | |
| return Registry::$object[$key]->{$var}; | |
| else | |
| return Registry::$object[$key]; | |
| endif; | |
| return; | |
| } | |
| public static function set($key, $var, $value) { | |
| if(empty(Registry::$object[$key])) Registry::$object[$key] = new stdClass; | |
| Registry::$object[$key]->{$var} = $value; | |
| } | |
| public static function delete($key, $var = false) { | |
| if($var) | |
| unset(Registry::$objects[$key]); | |
| else | |
| unset(Registry::$objects[$key]->{$var}); | |
| } | |
| public static function dump($key = false, $var = false, $php = true, $js = true){ | |
| if(!$key && !$var): | |
| $dump = Registry::$object; | |
| else: | |
| $dump = Registry::get($key, $var); | |
| endif; | |
| if($php): | |
| echo '<pre>'; | |
| print_r($dump); | |
| echo '</pre>'; | |
| endif; | |
| if($js): | |
| echo '<script type="text/javascript">'; | |
| echo 'var dump = ' . json_encode($dump) . ';'; | |
| echo 'console.log(dump);'; | |
| echo '</script>'; | |
| endif; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment