2010-10-15 05:54:31 +02:00
|
|
|
<?php
|
2008-02-25 03:10:37 +01:00
|
|
|
/**
|
2012-03-24 04:38:57 +01:00
|
|
|
* This file is the Framework bootstrap. It will get your environment ready to call Director::direct().
|
2008-02-25 03:10:37 +01:00
|
|
|
*
|
2008-09-30 01:41:50 +02:00
|
|
|
* It takes care of:
|
|
|
|
* - Including _ss_environment.php
|
|
|
|
* - Normalisation of $_SERVER values
|
2010-10-19 05:44:24 +02:00
|
|
|
* - Initialisation of necessary constants (mostly paths)
|
2008-09-30 01:41:50 +02:00
|
|
|
* - Checking of PHP memory limit
|
|
|
|
* - Including all the files needed to get the manifest built
|
|
|
|
* - Building and including the manifest
|
|
|
|
*
|
2010-10-19 05:44:24 +02:00
|
|
|
* Initialized constants:
|
|
|
|
* - BASE_URL: Full URL to the webroot, e.g. "http://my-host.com/my-webroot" (no trailing slash).
|
|
|
|
* - BASE_PATH: Absolute path to the webroot, e.g. "/var/www/my-webroot" (no trailing slash).
|
|
|
|
* See Director::baseFolder(). Can be overwritten by Director::setBaseFolder().
|
|
|
|
* - TEMP_FOLDER: Absolute path to temporary folder, used for manifest and template caches. Example: "/var/tmp"
|
|
|
|
* See getTempFolder(). No trailing slash.
|
|
|
|
* - MODULES_DIR: Not used at the moment
|
|
|
|
* - MODULES_PATH: Not used at the moment
|
|
|
|
* - THEMES_DIR: Path relative to webroot, e.g. "themes"
|
|
|
|
* - THEMES_PATH: Absolute filepath, e.g. "/var/www/my-webroot/themes"
|
2012-03-24 04:38:57 +01:00
|
|
|
* - FRAMEWORK_DIR: Path relative to webroot, e.g. "framework"
|
|
|
|
* - FRAMEWORK_PATH:Absolute filepath, e.g. "/var/www/my-webroot/framework"
|
|
|
|
* - FRAMEWORK_ADMIN_DIR: Path relative to webroot, e.g. "framework/admin"
|
|
|
|
* - FRAMEWORK_ADMIN_PATH: Absolute filepath, e.g. "/var/www/my-webroot/framework/admin"
|
|
|
|
* - THIRDPARTY_DIR: Path relative to webroot, e.g. "framework/thirdparty"
|
|
|
|
* - THIRDPARTY_PATH: Absolute filepath, e.g. "/var/www/my-webroot/framework/thirdparty"
|
2010-10-19 05:44:24 +02:00
|
|
|
*
|
2008-09-30 01:41:50 +02:00
|
|
|
* @todo This file currently contains a lot of bits and pieces, and its various responsibilities should probably be
|
|
|
|
* moved into different subsystems.
|
|
|
|
* @todo A lot of this stuff is very order-independent; for example, the require_once calls have to happen after the defines.'
|
|
|
|
* This could be decoupled.
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2008-02-25 03:10:37 +01:00
|
|
|
* @subpackage core
|
|
|
|
*/
|
|
|
|
|
2008-09-30 01:41:50 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// ENVIRONMENT CONFIG
|
|
|
|
|
2012-04-12 02:01:15 +02:00
|
|
|
// ALL errors are reported, including E_STRICT by default *unless* the site is in
|
|
|
|
// live mode, where reporting is limited to fatal errors and warnings (see later in this file)
|
2012-04-13 03:23:26 +02:00
|
|
|
error_reporting(E_ALL | E_STRICT);
|
2010-04-12 07:00:40 +02:00
|
|
|
|
2008-09-30 01:41:50 +02:00
|
|
|
/**
|
|
|
|
* Include _ss_environment.php files
|
|
|
|
*/
|
2010-10-15 05:54:12 +02:00
|
|
|
$envFiles = array('_ss_environment.php', '../_ss_environment.php', '../../_ss_environment.php', '../../../_ss_environment.php');
|
2008-09-30 01:41:50 +02:00
|
|
|
foreach($envFiles as $envFile) {
|
2009-03-10 23:08:52 +01:00
|
|
|
if(@file_exists($envFile)) {
|
2008-11-18 02:48:37 +01:00
|
|
|
define('SS_ENVIRONMENT_FILE', $envFile);
|
2008-10-20 15:26:52 +02:00
|
|
|
include_once($envFile);
|
2008-09-30 01:41:50 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// GLOBALS AND DEFINE SETTING
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A blank HTTP_HOST value is used to detect command-line execution.
|
|
|
|
* We update the $_SERVER variable to contain data consistent with the rest of the application.
|
|
|
|
*/
|
|
|
|
if(!isset($_SERVER['HTTP_HOST'])) {
|
|
|
|
// HTTP_HOST, REQUEST_PORT, SCRIPT_NAME, and PHP_SELF
|
|
|
|
if(isset($_FILE_TO_URL_MAPPING)) {
|
2010-04-13 05:24:48 +02:00
|
|
|
$fullPath = $testPath = realpath($_SERVER['SCRIPT_FILENAME']);
|
2010-12-21 05:35:21 +01:00
|
|
|
while($testPath && $testPath != '/' && !preg_match('/^[A-Z]:\\\\$/', $testPath)) {
|
2008-09-30 01:41:50 +02:00
|
|
|
if(isset($_FILE_TO_URL_MAPPING[$testPath])) {
|
2009-06-26 04:46:14 +02:00
|
|
|
$url = $_FILE_TO_URL_MAPPING[$testPath]
|
2010-12-21 05:35:21 +01:00
|
|
|
. str_replace(DIRECTORY_SEPARATOR, '/', substr($fullPath,strlen($testPath)));
|
2009-06-26 04:46:14 +02:00
|
|
|
|
2010-12-21 05:35:21 +01:00
|
|
|
$components = parse_url($url);
|
|
|
|
$_SERVER['HTTP_HOST'] = $components['host'];
|
|
|
|
if(!empty($components['port'])) $_SERVER['HTTP_HOST'] .= ':' . $components['port'];
|
|
|
|
$_SERVER['SCRIPT_NAME'] = $_SERVER['PHP_SELF'] = $components['path'];
|
|
|
|
if(!empty($components['port'])) $_SERVER['REQUEST_PORT'] = $components['port'];
|
|
|
|
break;
|
2008-09-30 01:41:50 +02:00
|
|
|
}
|
|
|
|
$testPath = dirname($testPath);
|
|
|
|
}
|
|
|
|
}
|
2009-06-26 04:46:14 +02:00
|
|
|
|
2008-09-30 01:41:50 +02:00
|
|
|
// Everything else
|
|
|
|
$serverDefaults = array(
|
|
|
|
'SERVER_PROTOCOL' => 'HTTP/1.1',
|
|
|
|
'HTTP_ACCEPT' => 'text/plain;q=0.5',
|
|
|
|
'HTTP_ACCEPT_LANGUAGE' => '*;q=0.5',
|
|
|
|
'HTTP_ACCEPT_ENCODING' => '',
|
|
|
|
'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1;q=0.5',
|
|
|
|
'SERVER_SIGNATURE' => 'Command-line PHP/' . phpversion(),
|
|
|
|
'SERVER_SOFTWARE' => 'PHP/' . phpversion(),
|
|
|
|
'SERVER_ADDR' => '127.0.0.1',
|
|
|
|
'REMOTE_ADDR' => '127.0.0.1',
|
|
|
|
'REQUEST_METHOD' => 'GET',
|
2008-11-09 23:40:08 +01:00
|
|
|
'HTTP_USER_AGENT' => 'CLI',
|
2008-09-30 01:41:50 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$_SERVER = array_merge($serverDefaults, $_SERVER);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If we have an HTTP_HOST value, then we're being called from the webserver and there are some things that
|
|
|
|
* need checking
|
|
|
|
*/
|
|
|
|
} else {
|
|
|
|
/**
|
|
|
|
* Fix magic quotes setting
|
|
|
|
*/
|
2009-06-16 13:47:23 +02:00
|
|
|
if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
|
2008-09-30 01:41:50 +02:00
|
|
|
if($_REQUEST) stripslashes_recursively($_REQUEST);
|
|
|
|
if($_GET) stripslashes_recursively($_GET);
|
|
|
|
if($_POST) stripslashes_recursively($_POST);
|
|
|
|
}
|
2010-04-12 04:42:51 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fix HTTP_HOST from reverse proxies
|
|
|
|
*/
|
|
|
|
if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
|
2012-04-13 07:28:20 +02:00
|
|
|
// Get the first host, in case there's multiple separated through commas
|
|
|
|
$_SERVER['HTTP_HOST'] = strtok($_SERVER['HTTP_X_FORWARDED_HOST'], ',');
|
2010-04-12 04:42:51 +02:00
|
|
|
}
|
2008-09-30 01:41:50 +02:00
|
|
|
}
|
|
|
|
|
2008-09-29 14:33:07 +02:00
|
|
|
/**
|
|
|
|
* Define system paths
|
|
|
|
*/
|
2010-04-13 01:15:04 +02:00
|
|
|
if(!defined('BASE_PATH')) {
|
2012-03-24 04:38:57 +01:00
|
|
|
// Assuming that this file is framework/core/Core.php we can then determine the base path
|
2012-04-11 00:29:43 +02:00
|
|
|
$candidateBasePath = rtrim(dirname(dirname(dirname(__FILE__))), DIRECTORY_SEPARATOR);
|
|
|
|
// We can't have an empty BASE_PATH. Making it / means that double-slashes occur in places but that's benign.
|
|
|
|
// This likely only happens on chrooted environemnts
|
|
|
|
if($candidateBasePath == '') $candidateBasePath = DIRECTORY_SEPARATOR;
|
|
|
|
define('BASE_PATH', $candidateBasePath);
|
2010-04-13 01:15:04 +02:00
|
|
|
}
|
|
|
|
if(!defined('BASE_URL')) {
|
2010-12-15 05:59:54 +01:00
|
|
|
// Determine the base URL by comparing SCRIPT_NAME to SCRIPT_FILENAME and getting common elements
|
|
|
|
$path = realpath($_SERVER['SCRIPT_FILENAME']);
|
|
|
|
if(substr($path, 0, strlen(BASE_PATH)) == BASE_PATH) {
|
|
|
|
$urlSegmentToRemove = substr($path, strlen(BASE_PATH));
|
|
|
|
if(substr($_SERVER['SCRIPT_NAME'], -strlen($urlSegmentToRemove)) == $urlSegmentToRemove) {
|
2010-04-13 01:15:04 +02:00
|
|
|
$baseURL = substr($_SERVER['SCRIPT_NAME'], 0, -strlen($urlSegmentToRemove));
|
|
|
|
define('BASE_URL', rtrim($baseURL, DIRECTORY_SEPARATOR));
|
2010-12-15 05:59:54 +01:00
|
|
|
}
|
2010-04-13 01:15:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// If that didn't work, failover to the old syntax. Hopefully this isn't necessary, and maybe
|
|
|
|
// if can be phased out?
|
|
|
|
if(!defined('BASE_URL')) {
|
2010-04-14 05:48:52 +02:00
|
|
|
$dir = (strpos($_SERVER['SCRIPT_NAME'], 'index.php') !== false)
|
2010-04-14 05:47:37 +02:00
|
|
|
? dirname($_SERVER['SCRIPT_NAME'])
|
|
|
|
: dirname(dirname($_SERVER['SCRIPT_NAME']));
|
|
|
|
define('BASE_URL', rtrim($dir, DIRECTORY_SEPARATOR));
|
2010-04-13 01:15:04 +02:00
|
|
|
}
|
|
|
|
}
|
2008-09-29 14:33:07 +02:00
|
|
|
define('MODULES_DIR', 'modules');
|
|
|
|
define('MODULES_PATH', BASE_PATH . '/' . MODULES_DIR);
|
|
|
|
define('THEMES_DIR', 'themes');
|
|
|
|
define('THEMES_PATH', BASE_PATH . '/' . THEMES_DIR);
|
2012-03-24 04:38:57 +01:00
|
|
|
// Relies on this being in a subdir of the framework.
|
|
|
|
// If it isn't, or is symlinked to a folder with a different name, you must define FRAMEWORK_DIR
|
|
|
|
if(!defined('FRAMEWORK_DIR')) {
|
|
|
|
define('FRAMEWORK_DIR', basename(dirname(dirname(__FILE__))));
|
|
|
|
}
|
|
|
|
define('FRAMEWORK_PATH', BASE_PATH . '/' . FRAMEWORK_DIR);
|
|
|
|
define('FRAMEWORK_ADMIN_DIR', FRAMEWORK_DIR . '/admin');
|
|
|
|
define('FRAMEWORK_ADMIN_PATH', BASE_PATH . '/' . FRAMEWORK_ADMIN_DIR);
|
|
|
|
|
|
|
|
// These are all deprecated. Use the FRAMEWORK_ versions instead.
|
|
|
|
define('SAPPHIRE_DIR', FRAMEWORK_DIR);
|
|
|
|
define('SAPPHIRE_PATH', FRAMEWORK_PATH);
|
|
|
|
define('SAPPHIRE_ADMIN_DIR', FRAMEWORK_ADMIN_DIR);
|
|
|
|
define('SAPPHIRE_ADMIN_PATH', FRAMEWORK_ADMIN_PATH);
|
|
|
|
|
|
|
|
define('THIRDPARTY_DIR', FRAMEWORK_DIR . '/thirdparty');
|
2009-11-26 06:08:08 +01:00
|
|
|
define('THIRDPARTY_PATH', BASE_PATH . '/' . THIRDPARTY_DIR);
|
2008-09-29 14:33:07 +02:00
|
|
|
define('ASSETS_DIR', 'assets');
|
|
|
|
define('ASSETS_PATH', BASE_PATH . '/' . ASSETS_DIR);
|
|
|
|
|
2012-09-19 06:10:33 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// INCLUDES
|
|
|
|
|
|
|
|
if(defined('CUSTOM_INCLUDE_PATH')) {
|
|
|
|
$includePath = CUSTOM_INCLUDE_PATH . PATH_SEPARATOR
|
|
|
|
. FRAMEWORK_PATH . PATH_SEPARATOR
|
|
|
|
. FRAMEWORK_PATH . '/parsers' . PATH_SEPARATOR
|
|
|
|
. THIRDPARTY_PATH . PATH_SEPARATOR
|
|
|
|
. get_include_path();
|
|
|
|
} else {
|
|
|
|
$includePath = FRAMEWORK_PATH . PATH_SEPARATOR
|
|
|
|
. FRAMEWORK_PATH . '/parsers' . PATH_SEPARATOR
|
|
|
|
. THIRDPARTY_PATH . PATH_SEPARATOR
|
|
|
|
. get_include_path();
|
|
|
|
}
|
|
|
|
|
|
|
|
set_include_path($includePath);
|
|
|
|
|
2008-09-29 01:03:28 +02:00
|
|
|
/**
|
|
|
|
* Define the temporary folder if it wasn't defined yet
|
|
|
|
*/
|
2012-09-19 06:10:33 +02:00
|
|
|
require_once 'core/TempPath.php';
|
|
|
|
|
2008-09-29 01:03:28 +02:00
|
|
|
if(!defined('TEMP_FOLDER')) {
|
2012-09-19 06:10:33 +02:00
|
|
|
define('TEMP_FOLDER', getTempFolder(BASE_PATH));
|
2008-09-29 01:03:28 +02:00
|
|
|
}
|
|
|
|
|
2008-09-29 14:33:07 +02:00
|
|
|
/**
|
|
|
|
* Priorities definition. These constants are used in calls to _t() as an optional argument
|
|
|
|
*/
|
|
|
|
define('PR_HIGH',100);
|
|
|
|
define('PR_MEDIUM',50);
|
|
|
|
define('PR_LOW',10);
|
|
|
|
|
2008-09-30 01:41:50 +02:00
|
|
|
/**
|
|
|
|
* Ensure we have enough memory
|
|
|
|
*/
|
2009-06-17 13:36:49 +02:00
|
|
|
increase_memory_limit_to('64M');
|
2008-09-30 01:41:50 +02:00
|
|
|
|
2012-02-19 21:18:14 +01:00
|
|
|
/**
|
|
|
|
* Ensure we don't run into xdebug's fairly conservative infinite recursion protection limit
|
|
|
|
*/
|
|
|
|
increase_xdebug_nesting_level_to(200);
|
|
|
|
|
2011-12-04 13:21:15 +01:00
|
|
|
/**
|
|
|
|
* Set default encoding
|
|
|
|
*/
|
2012-05-09 10:23:20 +02:00
|
|
|
mb_http_output('UTF-8');
|
|
|
|
mb_internal_encoding('UTF-8');
|
|
|
|
mb_regex_encoding('UTF-8');
|
2011-12-04 13:21:15 +01:00
|
|
|
|
2012-06-11 12:38:59 +02:00
|
|
|
/**
|
|
|
|
* Enable better garbage collection
|
|
|
|
*/
|
|
|
|
gc_enable();
|
|
|
|
|
2011-03-18 07:28:11 +01:00
|
|
|
// Include the files needed the initial manifest building, as well as any files
|
|
|
|
// that are needed for the boostrap process on every request.
|
|
|
|
require_once 'cache/Cache.php';
|
|
|
|
require_once 'core/Object.php';
|
|
|
|
require_once 'core/ClassInfo.php';
|
2012-02-11 03:08:39 +01:00
|
|
|
require_once 'view/TemplateGlobalProvider.php';
|
2011-03-30 22:56:21 +02:00
|
|
|
require_once 'control/Director.php';
|
2011-03-18 07:28:11 +01:00
|
|
|
require_once 'dev/Debug.php';
|
2012-04-13 03:23:26 +02:00
|
|
|
require_once 'dev/DebugView.php';
|
|
|
|
require_once 'dev/Backtrace.php';
|
|
|
|
require_once 'dev/ZendLog.php';
|
|
|
|
require_once 'dev/Log.php';
|
2011-03-18 07:28:11 +01:00
|
|
|
require_once 'filesystem/FileFinder.php';
|
2011-03-30 22:56:21 +02:00
|
|
|
require_once 'core/manifest/ClassLoader.php';
|
|
|
|
require_once 'core/manifest/ClassManifest.php';
|
|
|
|
require_once 'core/manifest/ManifestFileFinder.php';
|
|
|
|
require_once 'core/manifest/TemplateLoader.php';
|
|
|
|
require_once 'core/manifest/TemplateManifest.php';
|
|
|
|
require_once 'core/manifest/TokenisedRegularExpression.php';
|
2012-06-14 12:27:22 +02:00
|
|
|
require_once 'control/injector/Injector.php';
|
|
|
|
|
|
|
|
// Initialise the dependency injector as soon as possible, as it is
|
|
|
|
// subsequently used by some of the following code
|
|
|
|
$default_options = array('locator' => 'SilverStripeServiceConfigurationLocator');
|
|
|
|
Injector::inst($default_options);
|
2010-04-13 01:14:36 +02:00
|
|
|
|
2008-09-30 01:41:50 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// MANIFEST
|
|
|
|
|
2011-03-18 07:28:11 +01:00
|
|
|
// Regenerate the manifest if ?flush is set, or if the database is being built.
|
|
|
|
// The coupling is a hack, but it removes an annoying bug where new classes
|
|
|
|
// referenced in _config.php files can be referenced during the build process.
|
|
|
|
$flush = (isset($_GET['flush']) || isset($_REQUEST['url']) && (
|
|
|
|
$_REQUEST['url'] == 'dev/build' || $_REQUEST['url'] == BASE_URL . '/dev/build'
|
|
|
|
));
|
|
|
|
$manifest = new SS_ClassManifest(BASE_PATH, false, $flush);
|
|
|
|
|
|
|
|
$loader = SS_ClassLoader::instance();
|
|
|
|
$loader->registerAutoloader();
|
|
|
|
$loader->pushManifest($manifest);
|
2008-09-30 01:41:50 +02:00
|
|
|
|
2012-03-09 05:20:20 +01:00
|
|
|
// Now that the class manifest is up, load the configuration
|
|
|
|
$configManifest = new SS_ConfigManifest(BASE_PATH, false, $flush);
|
|
|
|
Config::inst()->pushConfigManifest($configManifest);
|
|
|
|
|
2011-03-24 11:30:57 +01:00
|
|
|
SS_TemplateLoader::instance()->pushManifest(new SS_TemplateManifest(
|
|
|
|
BASE_PATH, false, isset($_GET['flush'])
|
|
|
|
));
|
|
|
|
|
2012-04-12 02:01:15 +02:00
|
|
|
// If in live mode, ensure deprecation, strict and notices are not reported
|
|
|
|
if(Director::isLive()) {
|
|
|
|
error_reporting(E_ALL & ~(E_DEPRECATED | E_STRICT | E_NOTICE));
|
2008-10-08 05:35:28 +02:00
|
|
|
}
|
2012-04-12 02:01:15 +02:00
|
|
|
|
2008-09-30 01:41:50 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// POST-MANIFEST COMMANDS
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load error handlers
|
|
|
|
*/
|
|
|
|
Debug::loadErrorHandlers();
|
|
|
|
|
2012-05-09 14:26:29 +02:00
|
|
|
|
2008-09-30 01:41:50 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// HELPER FUNCTIONS
|
|
|
|
|
2012-04-16 02:24:23 +02:00
|
|
|
function getSysTempDir() {
|
|
|
|
Deprecation::notice(3.0, 'Please use PHP function get_sys_temp_dir() instead.');
|
|
|
|
return sys_get_temp_dir();
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2011-03-22 10:47:55 +01:00
|
|
|
* @deprecated 3.0 Please use {@link SS_ClassManifest::getItemPath()}.
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
function getClassFile($className) {
|
2011-10-29 01:02:11 +02:00
|
|
|
Deprecation::notice('3.0', 'Use SS_ClassManifest::getItemPath() instead.');
|
2011-03-22 10:47:55 +01:00
|
|
|
return SS_ClassLoader::instance()->getManifest()->getItemPath($className);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2009-03-31 21:32:19 +02:00
|
|
|
/**
|
|
|
|
* Creates a class instance by the "singleton" design pattern.
|
|
|
|
* It will always return the same instance for this class,
|
|
|
|
* which can be used for performance reasons and as a simple
|
|
|
|
* way to access instance methods which don't rely on instance
|
|
|
|
* data (e.g. the custom SilverStripe static handling).
|
|
|
|
*
|
|
|
|
* @param string $className
|
|
|
|
* @return Object
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
function singleton($className) {
|
2012-06-11 12:40:47 +02:00
|
|
|
if($className == "Config") user_error("Don't pass Config to singleton()", E_USER_ERROR);
|
2007-07-19 12:40:28 +02:00
|
|
|
if(!isset($className)) user_error("singleton() Called without a class", E_USER_ERROR);
|
2008-11-18 02:48:37 +01:00
|
|
|
if(!is_string($className)) user_error("singleton() passed bad class_name: " . var_export($className,true), E_USER_ERROR);
|
2012-06-11 12:40:47 +02:00
|
|
|
return Injector::inst()->get($className);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function project() {
|
|
|
|
global $project;
|
|
|
|
return $project;
|
|
|
|
}
|
|
|
|
|
|
|
|
function stripslashes_recursively(&$array) {
|
|
|
|
foreach($array as $k => $v) {
|
|
|
|
if(is_array($v)) stripslashes_recursively($array[$k]);
|
|
|
|
else $array[$k] = stripslashes($v);
|
|
|
|
}
|
|
|
|
}
|
2007-09-15 02:12:28 +02:00
|
|
|
|
|
|
|
/**
|
2008-10-17 17:40:59 +02:00
|
|
|
* @see i18n::_t()
|
2007-09-15 02:12:28 +02:00
|
|
|
*/
|
2012-05-01 22:13:50 +02:00
|
|
|
function _t($entity, $string = "", $context = "", $injection = "") {
|
|
|
|
return i18n::_t($entity, $string, $context, $injection);
|
2007-09-15 02:12:28 +02:00
|
|
|
}
|
2007-09-15 02:19:29 +02:00
|
|
|
|
2009-06-17 13:36:49 +02:00
|
|
|
/**
|
|
|
|
* Increase the memory limit to the given level if it's currently too low.
|
2011-08-30 12:53:06 +02:00
|
|
|
* Only increases up to the maximum defined in {@link set_increase_memory_limit_max()},
|
|
|
|
* and defaults to the 'memory_limit' setting in the PHP configuration.
|
|
|
|
*
|
2009-06-28 04:36:46 +02:00
|
|
|
* @param A memory limit string, such as "64M". If omitted, unlimited memory will be set.
|
2011-08-30 12:53:06 +02:00
|
|
|
* @return Boolean TRUE indicates a successful change, FALSE a denied change.
|
2009-06-17 13:36:49 +02:00
|
|
|
*/
|
2009-06-28 04:36:46 +02:00
|
|
|
function increase_memory_limit_to($memoryLimit = -1) {
|
|
|
|
$curLimit = ini_get('memory_limit');
|
|
|
|
|
|
|
|
// Can't go higher than infinite
|
2011-08-30 12:53:06 +02:00
|
|
|
if($curLimit == -1 ) return true;
|
|
|
|
|
|
|
|
// Check hard maximums
|
|
|
|
$max = get_increase_memory_limit_max();
|
2012-06-26 02:39:50 +02:00
|
|
|
|
|
|
|
if($max && $max != -1 && trANSLATE_MEMSTRING($memoryLimit) > translate_memstring($max)) return false;
|
2009-06-28 04:36:46 +02:00
|
|
|
|
2009-06-17 13:36:49 +02:00
|
|
|
// Increase the memory limit if it's too low
|
2009-06-28 04:36:46 +02:00
|
|
|
if($memoryLimit == -1 || translate_memstring($memoryLimit) > translate_memstring($curLimit)) {
|
2009-06-17 13:36:49 +02:00
|
|
|
ini_set('memory_limit', $memoryLimit);
|
2012-04-16 02:17:30 +02:00
|
|
|
}
|
2011-08-30 12:53:06 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$_increase_memory_limit_max = ini_get('memory_limit');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the maximum allowed value for {@link increase_memory_limit_to()}.
|
|
|
|
* The same result can also be achieved through 'suhosin.memory_limit'
|
|
|
|
* if PHP is running with the Suhosin system.
|
|
|
|
*
|
|
|
|
* @param Memory limit string
|
|
|
|
*/
|
|
|
|
function set_increase_memory_limit_max($memoryLimit) {
|
|
|
|
global $_increase_memory_limit_max;
|
|
|
|
$_increase_memory_limit_max = $memoryLimit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Memory limit string
|
|
|
|
*/
|
|
|
|
function get_increase_memory_limit_max() {
|
|
|
|
global $_increase_memory_limit_max;
|
|
|
|
return $_increase_memory_limit_max;
|
2009-06-17 13:36:49 +02:00
|
|
|
}
|
|
|
|
|
2012-02-19 21:18:14 +01:00
|
|
|
/**
|
|
|
|
* Increases the XDebug parameter max_nesting_level, which limits how deep recursion can go.
|
|
|
|
* Only does anything if (a) xdebug is installed and (b) the new limit is higher than the existing limit
|
|
|
|
*
|
|
|
|
* @param int $limit - The new limit to increase to
|
|
|
|
*/
|
|
|
|
function increase_xdebug_nesting_level_to($limit) {
|
|
|
|
if (function_exists('xdebug_enable')) {
|
|
|
|
$current = ini_get('xdebug.max_nesting_level');
|
|
|
|
if ((int)$current < $limit) ini_set('xdebug.max_nesting_level', $limit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-17 13:36:49 +02:00
|
|
|
/**
|
|
|
|
* Turn a memory string, such as 512M into an actual number of bytes.
|
2011-08-30 12:53:06 +02:00
|
|
|
*
|
2009-06-17 13:36:49 +02:00
|
|
|
* @param A memory limit string, such as "64M"
|
|
|
|
*/
|
|
|
|
function translate_memstring($memString) {
|
|
|
|
switch(strtolower(substr($memString, -1))) {
|
|
|
|
case "k": return round(substr($memString, 0, -1)*1024);
|
|
|
|
case "m": return round(substr($memString, 0, -1)*1024*1024);
|
|
|
|
case "g": return round(substr($memString, 0, -1)*1024*1024*1024);
|
|
|
|
default: return round($memString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-28 04:36:46 +02:00
|
|
|
/**
|
2011-08-30 12:53:06 +02:00
|
|
|
* Increase the time limit of this script. By default, the time will be unlimited.
|
|
|
|
* Only works if 'safe_mode' is off in the PHP configuration.
|
|
|
|
* Only values up to {@link get_increase_time_limit_max()} are allowed.
|
|
|
|
*
|
2009-06-28 04:36:46 +02:00
|
|
|
* @param $timeLimit The time limit in seconds. If omitted, no time limit will be set.
|
2011-08-30 12:53:06 +02:00
|
|
|
* @return Boolean TRUE indicates a successful change, FALSE a denied change.
|
2009-06-28 04:36:46 +02:00
|
|
|
*/
|
|
|
|
function increase_time_limit_to($timeLimit = null) {
|
2011-08-30 12:53:06 +02:00
|
|
|
$max = get_increase_time_limit_max();
|
|
|
|
if($max != -1 && $timeLimit > $max) return false;
|
|
|
|
|
2009-06-28 04:36:46 +02:00
|
|
|
if(!ini_get('safe_mode')) {
|
|
|
|
if(!$timeLimit) {
|
|
|
|
set_time_limit(0);
|
2011-08-30 12:53:06 +02:00
|
|
|
return true;
|
2009-06-28 04:36:46 +02:00
|
|
|
} else {
|
|
|
|
$currTimeLimit = ini_get('max_execution_time');
|
2011-08-30 12:53:06 +02:00
|
|
|
// Only increase if its smaller
|
2009-06-28 04:36:46 +02:00
|
|
|
if($currTimeLimit && $currTimeLimit < $timeLimit) {
|
|
|
|
set_time_limit($timeLimit);
|
2011-08-30 12:53:06 +02:00
|
|
|
}
|
|
|
|
return true;
|
2009-06-28 04:36:46 +02:00
|
|
|
}
|
2011-08-30 12:53:06 +02:00
|
|
|
} else {
|
|
|
|
return false;
|
2009-06-28 04:36:46 +02:00
|
|
|
}
|
|
|
|
}
|
2011-08-30 12:53:06 +02:00
|
|
|
|
|
|
|
$_increase_time_limit_max = -1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the maximum allowed value for {@link increase_timeLimit_to()};
|
|
|
|
*
|
|
|
|
* @param Int Limit in seconds
|
|
|
|
*/
|
|
|
|
function set_increase_time_limit_max($timeLimit) {
|
|
|
|
global $_increase_time_limit_max;
|
|
|
|
$_increase_time_limit_max = $timeLimit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Int Limit in seconds
|
|
|
|
*/
|
|
|
|
function get_increase_time_limit_max() {
|
|
|
|
global $_increase_time_limit_max;
|
|
|
|
return $_increase_time_limit_max;
|
|
|
|
}
|