Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/TogglAutoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Toggl SPL Autoloader
*
* Allow class autoloading using SPL. Only loads classes that begin with 'toggl' and is
* case insensitive.
*
* @file
* @link http://php.net/manual/en/function.spl-autoload-register.php
* @author Timothy M. Crider <[email protected]>
*/

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