* @package tao */ class tao_helpers_Mode { /** * Development mode */ const DEVELOPMENT = 2; /** * Alias for development */ const DEBUG = 2; /** * Production mode */ const PRODUCTION = 3; /** * @var int the current mode */ private static $currentMode; /** * Check the TAO instance current mode * @example tao_helpers_Mode::is('production') * @param int|string $mode * @return boolean */ public static function is($mode) { if (is_int($mode) && self::get() == $mode) { return true; } if (is_string($mode) && self::get() == self::getModeByName($mode)) { return true; } return false; } /** * Get the current mode * @example (tao_helpers_Mode::get() == tao_helpers_Mode::DEVELOPMENT) * @return int matching the constants */ public static function get() { if (empty(self::$currentMode)) { self::$currentMode = self::getCurrentMode(); } return self::$currentMode; } /** * Get the mode constant by name * @param string $name the mode name * @return int|boolean false if not exists */ public static function getModeByName($name) { switch (strtolower($name)) { case 'development': case 'debug': return self::DEVELOPMENT; case 'production': return self::PRODUCTION; default: return false; } } /** * Reads the current value of DEBUG_MODE * * @return int matching the constants * @throws common_Exception */ private static function getCurrentMode() { //read the mode from variable DEBUG_MODE if (!defined('DEBUG_MODE')) { throw new common_Exception('The DEBUG MODE constant is not defined, it should never occurs'); } if (DEBUG_MODE == true) { return self::DEVELOPMENT; } return self::PRODUCTION; } }