/** * Sets and return or return an environment status * * @since ADD MVC 0.8 */ public static function environment_status($new_status = null) { if ($new_status) { if (is_string($new_status)) { if ($new_status === 'development') { if (add::is_developer()) { add::$environment_status = $new_status; } else { add::$environment_status = "live"; } } else { if ($new_status === 'live') { add::$environment_status = 'live'; } else { throw new e_developer("Invalid environment_status: {$new_status}"); } } } /** * No errors if live * * @since ADD MVC 0.7.2 */ if (add::is_live()) { error_reporting(0); add::$handle_shutdown = false; } else { error_reporting(E_ALL); /** * When development, record the time spent on script execution * * @since ADD MVC 0.7.2 */ if (add::is_development()) { add::$handle_shutdown = true; if (!isset($GLOBALS['add_mvc_root_timer'])) { $GLOBALS['add_mvc_root_timer'] = add_development_timer::start("Framework Configuration"); } add::config()->root_timer = $GLOBALS['add_mvc_root_timer']; } } } return add::$environment_status; }
/** * Sets and return or return an environment status * * @since ADD MVC 0.8 */ public static function environment_status($new_status = null) { /** * * @see http://code.google.com/p/add-mvc-framework/issues/detail?id=33 */ if (!add::is_developer()) { if (add::$environment_status != 'live' || isset($new_status) && $new_status != 'live') { $new_status = 'live'; } } if ($new_status) { if (is_string($new_status)) { if ($new_status === 'development') { if (add::is_developer()) { add::$environment_status = $new_status; } else { add::$environment_status = "live"; } } else { if ($new_status === 'live') { add::$environment_status = 'live'; } else { throw new e_developer("Invalid environment_status: {$new_status}"); } } } else { if ($new_status !== true) { throw new e_developer("Invalid new environment status", $new_status); } } /** * No errors if live * * @since ADD MVC 0.7.2 */ if (add::is_live()) { error_reporting(0); ini_set('display_errors', 0); add::$handle_shutdown = false; } else { error_reporting(E_ALL); ini_set('display_errors', 1); /** * When development, record the time spent on script execution * * @since ADD MVC 0.7.2 */ if (add::is_development()) { add::$handle_shutdown = true; if (!isset($GLOBALS['add_mvc_root_timer'])) { $GLOBALS['add_mvc_root_timer'] = add_development_timer::start("Framework Configuration"); } add::config()->root_timer = $GLOBALS['add_mvc_root_timer']; } } } return add::$environment_status; }
<?php require '../config.php'; require_once "{$C->add_dir}/init.php"; $exceptions = array('e_developer', 'e_syntax', 'e_hack', 'e_spam', 'e_system'); $exception = (string) $_GET['exception']; $email = (string) $_GET['email']; if ($exception) { if ($_REQUEST['is_live']) { add::environment_status('live'); } add::content_type($_REQUEST['content_type']); e_add::$email_addresses = $email; $e = new $exception("Test Error Message"); #debug::var_dump($e->mail_body()); throw $e; } ?> <form method="GET"> <select name="exception"> <option><?php echo implode("</option><option>", $exceptions); ?> </option> </select> <label>Email<input type="text" name="email" /></label> <label><input name="is_live" type="checkbox" />Live</label> <label> Content Type<select name="content_type"> <option>text/html</option> <option>text/plain</option>
$C->caches_dir = sys_get_temp_dir() . '/add_mvc_caches_' . sha1($C->root_dir); if (!file_exists($C->caches_dir)) { umask(0); mkdir($C->caches_dir); } else { if (!is_dir($C->caches_dir)) { throw new e_system("Cache directory is not a directory", $C->caches_dir); } } } if (!is_writeable($C->caches_dir)) { if (!file_exists($C->caches_dir)) { throw new e_system("Cache directory is not existing ", $C->caches_dir); } if (!is_dir($C->caches_dir)) { throw new e_system("Cache directory is not a directory (environment status: " . add::environment_status() . ")", $C->caches_dir); } $cache_files = new DirectoryIterator($C->caches_dir); foreach ($cache_files as $cache_file) { if ($cache_file->isDot()) { continue; } if (!is_writable($cache_file->getPathname())) { throw new e_system("Cache directory is not writeable and one (or more) of it's files are not writeable", array($C->caches_dir, $cache_file->getPathname())); } } trigger_error("Cache directory is not writeable", E_USER_WARNING); unset($cache_file, $cache_files); } if (!isset($C->assets_dir)) { $C->assets_dir = $C->root_dir . '/assets';
register_shutdown_function('add::handle_shutdown'); if (!isset($C->incs_dir)) { $C->incs_dir = $C->root_dir . '/includes'; } $C->classes_dirs = array_merge(array($C->incs_dir . '/classes'), isset($C->classes_dirs) ? is_array($C->classes_dirs) ? $C->classes_dirs : (array) $C->classes_dirs : array(), array($C->add_dir . '/classes')); if (!isset($C->configs_dir)) { $C->configs_dir = $C->incs_dir . '/configs'; } if (!isset($C->views_dir)) { $C->views_dir = $C->incs_dir . '/views'; } if (!isset($C->caches_dir)) { $C->caches_dir = $C->incs_dir . '/caches'; } add::load_functions('common'); add::environment_status(true); /** * Set the exception emails * * @see http://code.google.com/p/add-mvc-framework/issues/detail?id=38 * * */ if (isset($C->developer_emails)) { if (is_string($C->developer_emails)) { e_add::$email_addresses = $C->developer_emails; } else { if (is_object($C->developer_emails) || is_array($C->developer_emails)) { e_add::$email_addresses = implode(", ", (array) $C->developer_emails); } }
} if (!isset($C)) { die("No config found"); } require $C->add_dir . '/classes/add.class.php'; $GLOBALS[add::CONFIG_VARNAME] = add::config($C); spl_autoload_register('add::load_class'); set_exception_handler('add::handle_exception'); set_error_handler('add::handle_error'); register_shutdown_function('add::handle_shutdown'); $C->incs_dir = $C->root_dir . '/includes'; $C->classes_dirs = array_merge(array($C->incs_dir . '/classes', $C->add_dir . '/classes'), isset($C->classes_dirs) && is_array($C->classes_dirs) ? $C->classes_dirs : array()); $C->configs_dir = $C->incs_dir . '/configs'; $C->views_dir = $C->incs_dir . '/views'; $C->caches_dir = $C->incs_dir . '/caches'; add::environment_status(add::config()->environment_status); if (add::is_development() && !is_writeable($C->caches_dir)) { $C->caches_dir = sys_get_temp_dir() . '/add_mvc_caches'; if (!file_exists($C->caches_dir)) { mkdir($C->caches_dir, 0700); } } $C->assets_dir = $C->root_dir . '/assets'; $C->images_dir = $C->assets_dir . '/images'; $C->css_dir = $C->assets_dir . '/css'; $C->js_dir = $C->assets_dir . '/js'; $C->domain = ($C->sub_domain ? "{$C->sub_domain}." : "") . $C->super_domain; $C->base_url = "http://{$C->domain}" . $C->path; set_include_path($C->incs_dir); /** * assets