From cfae9c5eba35b33a048d5e6b1746dfe77a1b6c76 Mon Sep 17 00:00:00 2001 From: "Timothy M. Crider" Date: Sun, 18 Aug 2013 05:53:19 +0000 Subject: [PATCH] Added spl autoloader for toggle objects. --- src/TogglAutoload.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/TogglAutoload.php diff --git a/src/TogglAutoload.php b/src/TogglAutoload.php new file mode 100644 index 0000000..7822159 --- /dev/null +++ b/src/TogglAutoload.php @@ -0,0 +1,36 @@ + + */ + +/** + * Use current directory of the autoloader file as the base toggl directory + */ +if (!defined('TOGGL_DIR')) { + define('TOGGL_DIR', dirname(__FILE__).'/'); +} + +/** + * Autoloader function + */ +function togglAutoload($class) { + // Do not try to load non toggl classes + if (!preg_match('/^toggl/i', $class)) { + return false; + } + + $tryFile = sprintf("%s%s.php", TOGGL_DIR, $class); + return (file_exists($tryFile) && is_readable($tryFile)) ? include $tryFile : false; +} + +/** + * Register the autoloader with PHP + */ +spl_autoload_register('togglAutoload');