1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-25 16:22:43 +01:00

Remove PhabricatorStartup::getGlobal/setGlobal mechanism

Summary:
Ref T8424. Fixes T7114. This was envisioned as a per-request cache for reusing interpreters, but isn't a good fit for that in modern Phabricator.

In particular, it isn't loaded by the daemons, but they have equal need for per-request caching.

Since I finally need such a cache for Spaces, throw the old stuff away before I built a more modern cache.

Also resolves T7114 by dropping filtering on $_SERVER. I'm pretty sure this is the simplest fix, see D12977 for a bit more discussion.

Test Plan: Called `didFatal()` from somewhere in normal code and verified it was able to use the access log.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T7114, T8424

Differential Revision: https://secure.phabricator.com/D13152
This commit is contained in:
epriestley 2015-06-04 17:26:52 -07:00
parent e5b923743a
commit a15444aa79
3 changed files with 15 additions and 44 deletions

View file

@ -3903,7 +3903,6 @@ phutil_register_library_map(array(
'DivinerLiveBook' => array( 'DivinerLiveBook' => array(
'DivinerDAO', 'DivinerDAO',
'PhabricatorPolicyInterface', 'PhabricatorPolicyInterface',
'PhabricatorProjectInterface',
'PhabricatorDestructibleInterface', 'PhabricatorDestructibleInterface',
), ),
'DivinerLivePublisher' => 'DivinerPublisher', 'DivinerLivePublisher' => 'DivinerPublisher',

View file

@ -80,7 +80,7 @@ abstract class AphrontApplicationConfiguration {
// This is the earliest we can get away with this, we need env config first. // This is the earliest we can get away with this, we need env config first.
PhabricatorAccessLog::init(); PhabricatorAccessLog::init();
$access_log = PhabricatorAccessLog::getLog(); $access_log = PhabricatorAccessLog::getLog();
PhabricatorStartup::setGlobal('log.access', $access_log); PhabricatorStartup::setAccessLog($access_log);
$access_log->setData( $access_log->setData(
array( array(
'R' => AphrontRequest::getHTTPHeader('Referer', '-'), 'R' => AphrontRequest::getHTTPHeader('Referer', '-'),

View file

@ -39,7 +39,7 @@ final class PhabricatorStartup {
private static $startTime; private static $startTime;
private static $debugTimeLimit; private static $debugTimeLimit;
private static $globals = array(); private static $accessLog;
private static $capturingOutput; private static $capturingOutput;
private static $rawInput; private static $rawInput;
private static $oldMemoryLimit; private static $oldMemoryLimit;
@ -72,26 +72,11 @@ final class PhabricatorStartup {
/** /**
* @task info * @task info
*/ */
public static function setGlobal($key, $value) { public static function setAccessLog($access_log) {
self::validateGlobal($key); self::$accessLog = $access_log;
self::$globals[$key] = $value;
} }
/**
* @task info
*/
public static function getGlobal($key, $default = null) {
self::validateGlobal($key);
if (!array_key_exists($key, self::$globals)) {
return $default;
}
return self::$globals[$key];
}
/** /**
* @task info * @task info
*/ */
@ -108,7 +93,7 @@ final class PhabricatorStartup {
*/ */
public static function didStartup() { public static function didStartup() {
self::$startTime = microtime(true); self::$startTime = microtime(true);
self::$globals = array(); self::$accessLog = null;
static $registered; static $registered;
if (!$registered) { if (!$registered) {
@ -348,8 +333,7 @@ final class PhabricatorStartup {
} }
self::endOutputCapture(); self::endOutputCapture();
$access_log = self::getGlobal('log.access'); $access_log = self::$accessLog;
if ($access_log) { if ($access_log) {
// We may end up here before the access log is initialized, e.g. from // We may end up here before the access log is initialized, e.g. from
// verifyPHP(). // verifyPHP().
@ -402,9 +386,15 @@ final class PhabricatorStartup {
*/ */
private static function normalizeInput() { private static function normalizeInput() {
// Replace superglobals with unfiltered versions, disrespect php.ini (we // Replace superglobals with unfiltered versions, disrespect php.ini (we
// filter ourselves) // filter ourselves).
$filter = array(INPUT_GET, INPUT_POST,
INPUT_SERVER, INPUT_ENV, INPUT_COOKIE, // NOTE: We don't filter INPUT_SERVER because we don't want to overwrite
// changes made in "preamble.php".
$filter = array(
INPUT_GET,
INPUT_POST,
INPUT_ENV,
INPUT_COOKIE,
); );
foreach ($filter as $type) { foreach ($filter as $type) {
$filtered = filter_input_array($type, FILTER_UNSAFE_RAW); $filtered = filter_input_array($type, FILTER_UNSAFE_RAW);
@ -412,9 +402,6 @@ final class PhabricatorStartup {
continue; continue;
} }
switch ($type) { switch ($type) {
case INPUT_SERVER:
$_SERVER = array_merge($_SERVER, $filtered);
break;
case INPUT_GET: case INPUT_GET:
$_GET = array_merge($_GET, $filtered); $_GET = array_merge($_GET, $filtered);
break; break;
@ -551,21 +538,6 @@ final class PhabricatorStartup {
} }
/**
* @task validation
*/
private static function validateGlobal($key) {
static $globals = array(
'log.access' => true,
'csrf.salt' => true,
);
if (empty($globals[$key])) {
throw new Exception("Access to unknown startup global '{$key}'!");
}
}
/** /**
* Detect if this request has had its POST data stripped by exceeding the * Detect if this request has had its POST data stripped by exceeding the
* 'post_max_size' PHP configuration limit. * 'post_max_size' PHP configuration limit.