| [ Index ] |
PHP Cross Reference of Akelos Framework |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * This file and the lib/constants.php file perform most part of Akelos 5 * environment guessing. 6 * 7 * You can retrieve a list of current settings by running Ak::get_constants(); 8 * 9 * If you're running a high load site you might want to fine tune this options 10 * according to your environment. If you set the options implicitly you might 11 * gain in performance but loose in flexibility when moving to a different 12 * environment. 13 * 14 * If you need to customize the framework default settings or specify 15 * internationalization options, edit the files at config/environments/* 16 */ 17 18 defined('AK_PHP5') ? null : define('AK_PHP5', version_compare(PHP_VERSION, '5', '>=') == 1 ? true : false); 19 20 defined('AK_CONFIG_DIR') ? null : define('AK_CONFIG_DIR', AK_BASE_DIR.DS.'config'); 21 22 23 defined('AK_CACHE_HANDLER_PEAR') ? null: define('AK_CACHE_HANDLER_PEAR',1); 24 defined('AK_CACHE_HANDLER_ADODB') ? null: define('AK_CACHE_HANDLER_ADODB',2); 25 defined('AK_CACHE_HANDLER_MEMCACHE') ? null: define('AK_CACHE_HANDLER_MEMCACHE',3); 26 27 // If you need to customize the framework default settings or specify internationalization options, 28 // edit the files config/testing.php, config/development.php, config/production.php 29 if(AK_ENVIRONMENT != 'setup'){ 30 require_once(AK_CONFIG_DIR.DS.'environments'.DS.AK_ENVIRONMENT.'.php'); 31 } 32 33 defined('AK_CACHE_HANDLER') ? null : define('AK_CACHE_HANDLER', AK_CACHE_HANDLER_PEAR); 34 35 36 if (!defined('AK_TEST_DATABASE_ON')) { 37 defined('AK_DEFAULT_DATABASE_PROFILE') ? null : define('AK_DEFAULT_DATABASE_PROFILE', AK_ENVIRONMENT); 38 } 39 40 // Locale settings ( you must create a file at /config/locales/ using en.php as departure point) 41 // Please be aware that your charset needs to be UTF-8 in order to edit the locales files 42 // auto will enable all the locales at config/locales/ dir 43 defined('AK_AVAILABLE_LOCALES') ? null : define('AK_AVAILABLE_LOCALES', 'auto'); 44 45 defined('AK_AVAILABLE_ENVIRONMENTS') ? null : define('AK_AVAILABLE_ENVIRONMENTS',"setup,testing,development,production"); 46 // Set these constants in order to allow only these locales on web requests 47 // defined('AK_ACTIVE_RECORD_DEFAULT_LOCALES') ? null : define('AK_ACTIVE_RECORD_DEFAULT_LOCALES','en,es'); 48 // defined('AK_APP_LOCALES') ? null : define('AK_APP_LOCALES','en,es'); 49 // defined('AK_PUBLIC_LOCALES') ? null : define('AK_PUBLIC_LOCALES','en,es'); 50 51 // defined('AK_URL_REWRITE_ENABLED') ? null : define('AK_URL_REWRITE_ENABLED', true); 52 53 defined('AK_TIME_DIFFERENCE') ? null : define('AK_TIME_DIFFERENCE', 0); // Time difference from the webserver 54 55 // COMMENT THIS LINE IF YOU DONT WANT THE FRAMEWORK TO CONNECT TO THE DATABASE ON EACH REQUEST AUTOMATICALLY 56 defined('AK_WEB_REQUEST_CONNECT_TO_DATABASE_ON_INSTANTIATE') ? null : define('AK_WEB_REQUEST_CONNECT_TO_DATABASE_ON_INSTANTIATE', true); 57 58 defined('AK_CLI') ? null : define('AK_CLI', php_sapi_name() == 'cli'); 59 defined('AK_WEB_REQUEST') ? null : define('AK_WEB_REQUEST', !empty($_SERVER['REQUEST_URI'])); 60 defined('AK_REQUEST_URI') ? null : define('AK_REQUEST_URI', isset($_SERVER['REQUEST_URI']) ? 61 $_SERVER['REQUEST_URI'] : 62 $_SERVER['PHP_SELF'] .'?'.(isset($_SERVER['argv']) ? $_SERVER['argv'][0] : $_SERVER['QUERY_STRING'])); 63 64 defined('AK_DEBUG') ? null : define('AK_DEBUG', AK_ENVIRONMENT == 'production' ? 0 : 1); 65 66 defined('AK_ERROR_REPORTING') ? null : define('AK_ERROR_REPORTING', AK_DEBUG ? E_ALL : 0); 67 68 @error_reporting(AK_ERROR_REPORTING); 69 70 71 defined('AK_APP_DIR') ? null : define('AK_APP_DIR', AK_BASE_DIR.DS.'app'); 72 defined('AK_APIS_DIR') ? null : define('AK_APIS_DIR', AK_APP_DIR.DS.'apis'); 73 defined('AK_MODELS_DIR') ? null : define('AK_MODELS_DIR', AK_APP_DIR.DS.'models'); 74 defined('AK_CONTROLLERS_DIR') ? null : define('AK_CONTROLLERS_DIR', AK_APP_DIR.DS.'controllers'); 75 defined('AK_VIEWS_DIR') ? null : define('AK_VIEWS_DIR', AK_APP_DIR.DS.'views'); 76 defined('AK_HELPERS_DIR') ? null : define('AK_HELPERS_DIR', AK_APP_DIR.DS.'helpers'); 77 defined('AK_PUBLIC_DIR') ? null : define('AK_PUBLIC_DIR', AK_BASE_DIR.DS.'public'); 78 defined('AK_TEST_DIR') ? null : define('AK_TEST_DIR', AK_BASE_DIR.DS.'test'); 79 defined('AK_SCRIPT_DIR') ? null : define('AK_SCRIPT_DIR',AK_BASE_DIR.DS.'script'); 80 defined('AK_APP_VENDOR_DIR') ? null : define('AK_APP_VENDOR_DIR',AK_APP_DIR.DS.'vendor'); 81 defined('AK_APP_PLUGINS_DIR') ? null : define('AK_APP_PLUGINS_DIR',AK_APP_VENDOR_DIR.DS.'plugins'); 82 83 84 /** 85 * Getting the temporary directory 86 */ 87 function ak_get_tmp_dir_name(){ 88 if(!defined('AK_TMP_DIR')){ 89 if(defined('AK_BASE_DIR') && is_writable(AK_BASE_DIR.DS.'tmp')){ 90 return AK_BASE_DIR.DS.'tmp'; 91 } 92 if(!function_exists('sys_get_temp_dir')){ 93 $dir = empty($_ENV['TMP']) ? (empty($_ENV['TMPDIR']) ? (empty($_ENV['TEMP']) ? false : $_ENV['TEMP']) : $_ENV['TMPDIR']) : $_ENV['TMP']; 94 if(empty($dir) && $fn = tempnam(md5(rand()),'')){ 95 $dir = dirname($fn); 96 unlink($fn); 97 } 98 }else{ 99 $dir = sys_get_temp_dir(); 100 } 101 if(empty($dir)){ 102 trigger_error('Could not find a path for temporary files. Please define AK_TMP_DIR in your config.php', E_USER_ERROR); 103 } 104 $dir = rtrim(realpath($dir), DS).DS.'ak_'.md5(AK_BASE_DIR); 105 if(!is_dir($dir)){ 106 mkdir($dir); 107 } 108 return $dir; 109 } 110 return AK_TMP_DIR; 111 } 112 113 114 115 // Now some static functions that are needed by the whole framework 116 117 function translate($string, $args = null, $controller = null) 118 { 119 return Ak::t($string, $args, $controller); 120 } 121 122 123 function ak_test($test_case_name, $use_sessions = false) 124 { 125 if(!defined('ALL_TESTS_CALL')){ 126 $use_sessions ? @session_start() : null; 127 $test = &new $test_case_name(); 128 if (defined('AK_CLI') && AK_CLI || TextReporter::inCli() || (defined('AK_CONSOLE_MODE') && AK_CONSOLE_MODE) || (defined('AK_WEB_REQUEST') && !AK_WEB_REQUEST)) { 129 $test->run(new TextReporter()); 130 }else{ 131 $test->run(new HtmlReporter()); 132 } 133 } 134 } 135 136 function ak_compat($function_name) 137 { 138 if(!function_exists($function_name)){ 139 require_once(AK_VENDOR_DIR.DS.'pear'.DS.'PHP'.DS.'Compat'.DS.'Function'.DS.$function_name.'.php'); 140 } 141 } 142 143 function ak_generate_mock($name) 144 { 145 static $Mock; 146 if(empty($Mock)){ 147 $Mock = new Mock(); 148 } 149 $Mock->generate($name); 150 } 151 152 /** 153 * This function sets a constant and returns it's value. If constant has been already defined it 154 * will reutrn its original value. 155 * 156 * Returns null in case the constant does not exist 157 * 158 * @param string $name 159 * @param mixed $value 160 */ 161 function ak_define($name, $value = null) 162 { 163 $name = strtoupper($name); 164 $name = substr($name,0,3) == 'AK_' ? $name : 'AK_'.$name; 165 return defined($name) ? constant($name) : (is_null($value) ? null : (define($name, $value) ? $value : null)); 166 } 167 168 AK_PHP5 || function_exists('clone') ? null : eval('function clone($object){return $object;}'); 169 170 defined('AK_TMP_DIR') ? null : define('AK_TMP_DIR', ak_get_tmp_dir_name()); 171 defined('AK_COMPILED_VIEWS_DIR') ? null : define('AK_COMPILED_VIEWS_DIR', AK_TMP_DIR.DS.'views'); 172 defined('AK_CACHE_DIR') ? null : define('AK_CACHE_DIR', AK_TMP_DIR.DS.'cache'); 173 174 175 defined('AK_DEFAULT_LAYOUT') ? null : define('AK_DEFAULT_LAYOUT', 'application'); 176 177 defined('AK_CONTRIB_DIR') ? null : define('AK_CONTRIB_DIR',AK_FRAMEWORK_DIR.DS.'vendor'); 178 defined('AK_VENDOR_DIR') ? null : define('AK_VENDOR_DIR', AK_CONTRIB_DIR); 179 defined('AK_DOCS_DIR') ? null : define('AK_DOCS_DIR',AK_FRAMEWORK_DIR.DS.'docs'); 180 181 182 183 defined('AK_CONFIG_INCLUDED') ? null : define('AK_CONFIG_INCLUDED',true); 184 defined('AK_FW') ? null : define('AK_FW',true); 185 186 if(AK_ENVIRONMENT != 'setup'){ 187 defined('AK_UPLOAD_FILES_USING_FTP') ? null : define('AK_UPLOAD_FILES_USING_FTP', !empty($ftp_settings)); 188 defined('AK_READ_FILES_USING_FTP') ? null : define('AK_READ_FILES_USING_FTP', false); 189 defined('AK_DELETE_FILES_USING_FTP') ? null : define('AK_DELETE_FILES_USING_FTP', !empty($ftp_settings)); 190 defined('AK_FTP_AUTO_DISCONNECT') ? null : define('AK_FTP_AUTO_DISCONNECT', !empty($ftp_settings)); 191 192 if(!empty($ftp_settings)){ 193 defined('AK_FTP_PATH') ? null : define('AK_FTP_PATH', $ftp_settings); 194 unset($ftp_settings); 195 } 196 } 197 198 @ini_set("arg_separator.output","&"); 199 200 @ini_set("include_path",(AK_LIB_DIR.PATH_SEPARATOR.AK_MODELS_DIR.PATH_SEPARATOR.AK_CONTRIB_DIR.DS.'pear'.PATH_SEPARATOR.ini_get("include_path"))); 201 202 if(!AK_CLI && AK_WEB_REQUEST){ 203 204 if (!defined('AK_SITE_URL_SUFFIX')) 205 { 206 $__ak_site_url_suffix_userdir = substr(AK_REQUEST_URI,1,1) == '~' ? substr(AK_REQUEST_URI, 0, strpos(AK_REQUEST_URI, '/', 1)) : ''; 207 $__ak_site_url_suffix = str_replace(array(join(DS,array_diff((array)@explode(DS,AK_BASE_DIR), (array)@explode('/',AK_REQUEST_URI))), DS,'//'), array('','/','/'), AK_BASE_DIR); 208 define('AK_SITE_URL_SUFFIX', $__ak_site_url_suffix_userdir.$__ak_site_url_suffix); 209 unset($__ak_site_url_suffix_userdir, $__ak_site_url_suffix); 210 } 211 212 defined('AK_AUTOMATIC_SSL_DETECTION') ? null : define('AK_AUTOMATIC_SSL_DETECTION', 1); 213 214 defined('AK_PROTOCOL') ? null : define('AK_PROTOCOL',isset($_SERVER['HTTPS']) ? 'https://' : 'http://'); 215 defined('AK_HOST') ? null : define('AK_HOST', $_SERVER['SERVER_NAME'] == 'localhost' ? 216 // Will force to IP4 for localhost until IP6 is supported by helpers 217 ($_SERVER['SERVER_ADDR'] == '::1' ? '127.0.0.1' : $_SERVER['SERVER_ADDR']) : 218 $_SERVER['SERVER_NAME']); 219 defined('AK_REMOTE_IP') ? null : define('AK_REMOTE_IP',(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']); 220 221 defined('AK_SERVER_STANDARD_PORT') ? null : define('AK_SERVER_STANDARD_PORT', AK_PROTOCOL == 'https://' ? '443' : '80'); 222 223 $_ak_port = ($_SERVER['SERVER_PORT'] != AK_SERVER_STANDARD_PORT) 224 ? (empty($_SERVER['SERVER_PORT']) ? '' : ':'.$_SERVER['SERVER_PORT']) : ''; 225 226 if(isset($_SERVER['HTTP_HOST']) && strstr($_SERVER['HTTP_HOST'],':')){ 227 $_ak_port = substr($_SERVER['HTTP_HOST'], strpos($_SERVER['HTTP_HOST'],':')); 228 } 229 $_ak_suffix = ''; 230 if(defined('AK_SITE_HTPSS_URL_SUFFIX') && isset($_SERVER['HTTPS'])){ 231 $_ak_suffix = AK_SITE_HTPSS_URL_SUFFIX; 232 $_ak_port = strstr(AK_SITE_HTPSS_URL_SUFFIX,':') ? '' : $_ak_port; 233 }elseif(defined('AK_SITE_URL_SUFFIX') && AK_SITE_URL_SUFFIX != ''){ 234 $_ak_suffix = AK_SITE_URL_SUFFIX; 235 $_ak_port = strstr(AK_SITE_URL_SUFFIX,':') ? '' : $_ak_port; 236 } 237 if(!defined('AK_SITE_URL')){ 238 defined('AK_SITE_URL') ? null : define('AK_SITE_URL', trim(AK_PROTOCOL.AK_HOST, '/').$_ak_port.$_ak_suffix); 239 defined('AK_URL') ? null : define('AK_URL', AK_SITE_URL); 240 }else{ 241 if(AK_AUTOMATIC_SSL_DETECTION){ 242 defined('AK_URL') ? null : define('AK_URL', str_replace(array('https://','http://'),AK_PROTOCOL, AK_SITE_URL).$_ak_port.$_ak_suffix); 243 }else{ 244 defined('AK_URL') ? null : define('AK_URL', AK_SITE_URL.$_ak_port.$_ak_suffix); 245 } 246 } 247 248 defined('AK_CURRENT_URL') ? null : define('AK_CURRENT_URL', substr(AK_SITE_URL,0,strlen($_ak_suffix)*-1).AK_REQUEST_URI); 249 250 defined('AK_SERVER_PORT') ? null : define('AK_SERVER_PORT', empty($_ak_port) ? AK_SERVER_STANDARD_PORT : trim($_ak_port,':')); 251 252 unset($_ak_suffix, $_ak_port); 253 defined('AK_COOKIE_DOMAIN') ? null : define('AK_COOKIE_DOMAIN', AK_HOST); 254 // ini_set('session.cookie_domain', AK_COOKIE_DOMAIN); 255 256 defined('AK_INSECURE_APP_DIRECTORY_LAYOUT') ? null : define('AK_INSECURE_APP_DIRECTORY_LAYOUT', false); 257 258 if(!defined('AK_ASSET_URL_PREFIX')){ 259 defined('AK_ASSET_URL_PREFIX') ? null : define('AK_ASSET_URL_PREFIX', AK_INSECURE_APP_DIRECTORY_LAYOUT ? AK_SITE_URL_SUFFIX.str_replace(array(AK_BASE_DIR,'\\','//'),array('','/','/'), AK_PUBLIC_DIR) : AK_SITE_URL_SUFFIX); 260 } 261 262 263 }else{ 264 defined('AK_PROTOCOL') ? null : define('AK_PROTOCOL','http://'); 265 defined('AK_HOST') ? null : define('AK_HOST', 'localhost'); 266 defined('AK_REMOTE_IP') ? null : define('AK_REMOTE_IP','127.0.0.1'); 267 defined('AK_SITE_URL') ? null : define('AK_SITE_URL', 'http://localhost'); 268 defined('AK_URL') ? null : define('AK_URL', 'http://localhost/'); 269 defined('AK_CURRENT_URL') ? null : define('AK_CURRENT_URL', 'http://localhost/'); 270 defined('AK_COOKIE_DOMAIN') ? null : define('AK_COOKIE_DOMAIN', AK_HOST); 271 272 defined('AK_ASSET_URL_PREFIX') ? null : define('AK_ASSET_URL_PREFIX', ''); 273 } 274 275 defined('AK_SESSION_HANDLER') ? null : define('AK_SESSION_HANDLER', 0); 276 defined('AK_SESSION_EXPIRE') ? null : define('AK_SESSION_EXPIRE', 600); 277 defined('AK_SESSION_NAME') ? null : define('AK_SESSION_NAME', 'AK_'.substr(md5(AK_HOST.AK_APP_DIR),0,6)); 278 @ini_set("session.name", AK_SESSION_NAME); 279 280 defined('AK_DESKTOP') ? null : define('AK_DESKTOP', AK_SITE_URL == 'http://akelos'); 281 282 defined('AK_ASSET_HOST') ? null : define('AK_ASSET_HOST',''); 283 284 defined('AK_DEV_MODE') ? null : define('AK_DEV_MODE', AK_ENVIRONMENT == 'development'); 285 defined('AK_AUTOMATICALLY_UPDATE_LANGUAGE_FILES') ? null : define('AK_AUTOMATICALLY_UPDATE_LANGUAGE_FILES', AK_DEV_MODE); 286 defined('AK_ENABLE_PROFILER') ? null : define('AK_ENABLE_PROFILER', false); 287 defined('AK_PROFILER_GET_MEMORY') ? null : define('AK_PROFILER_GET_MEMORY',false); 288 289 $ADODB_CACHE_DIR = AK_CACHE_DIR; 290 291 /** 292 * Mode types for error reporting and loggin 293 */ 294 defined('AK_MODE_DISPLAY') ? null : define('AK_MODE_DISPLAY', 1); 295 defined('AK_MODE_MAIL') ? null : define('AK_MODE_MAIL', 2); 296 defined('AK_MODE_FILE') ? null : define('AK_MODE_FILE', 4); 297 defined('AK_MODE_DATABASE') ? null : define('AK_MODE_DATABASE', 8); 298 defined('AK_MODE_DIE') ? null : define('AK_MODE_DIE', 16); 299 300 defined('AK_LOG_DIR') ? null : define('AK_LOG_DIR', AK_BASE_DIR.DS.'log'); 301 defined('AK_LOG_EVENTS') ? null : define('AK_LOG_EVENTS', false); 302 303 defined('AK_ROUTES_MAPPING_FILE') ? null : define('AK_ROUTES_MAPPING_FILE', AK_CONFIG_DIR.DS.'routes.php'); 304 defined('AK_OS') ? null : define('AK_OS', (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? 'WINDOWS' : 'UNIX')); 305 defined('AK_CHARSET') ? null : define('AK_CHARSET', 'UTF-8'); 306 307 defined('AK_ACTION_CONTROLLER_DEFAULT_REQUEST_TYPE') ? null : define('AK_ACTION_CONTROLLER_DEFAULT_REQUEST_TYPE', 'web_request'); 308 defined('AK_ACTION_CONTROLLER_DEFAULT_ACTION') ? null : define('AK_ACTION_CONTROLLER_DEFAULT_ACTION', 'index'); 309 310 defined('AK_ERROR_REPORTING_ON_SCRIPTS') ? null : define('AK_ERROR_REPORTING_ON_SCRIPTS', E_ALL); 311 defined('AK_BEEP_ON_ERRORS_WHEN_TESTING') ? null : define('AK_BEEP_ON_ERRORS_WHEN_TESTING', false); 312 313 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Oct 27 12:43:49 2008 | Cross-referenced by PHPXref 0.6 |