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');