Skip to content

Commit a15444a

Browse files
author
epriestley
committedJun 5, 2015
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
1 parent e5b9237 commit a15444a

File tree

3 files changed

+15
-44
lines changed

3 files changed

+15
-44
lines changed
 

‎src/__phutil_library_map__.php

-1
Original file line numberDiff line numberDiff line change
@@ -3903,7 +3903,6 @@
39033903
'DivinerLiveBook' => array(
39043904
'DivinerDAO',
39053905
'PhabricatorPolicyInterface',
3906-
'PhabricatorProjectInterface',
39073906
'PhabricatorDestructibleInterface',
39083907
),
39093908
'DivinerLivePublisher' => 'DivinerPublisher',

‎src/aphront/configuration/AphrontApplicationConfiguration.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public static function runHTTPRequest(AphrontHTTPSink $sink) {
8080
// This is the earliest we can get away with this, we need env config first.
8181
PhabricatorAccessLog::init();
8282
$access_log = PhabricatorAccessLog::getLog();
83-
PhabricatorStartup::setGlobal('log.access', $access_log);
83+
PhabricatorStartup::setAccessLog($access_log);
8484
$access_log->setData(
8585
array(
8686
'R' => AphrontRequest::getHTTPHeader('Referer', '-'),

‎support/PhabricatorStartup.php

+14-42
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ final class PhabricatorStartup {
3939

4040
private static $startTime;
4141
private static $debugTimeLimit;
42-
private static $globals = array();
42+
private static $accessLog;
4343
private static $capturingOutput;
4444
private static $rawInput;
4545
private static $oldMemoryLimit;
@@ -72,26 +72,11 @@ public static function getMicrosecondsSinceStart() {
7272
/**
7373
* @task info
7474
*/
75-
public static function setGlobal($key, $value) {
76-
self::validateGlobal($key);
77-
78-
self::$globals[$key] = $value;
75+
public static function setAccessLog($access_log) {
76+
self::$accessLog = $access_log;
7977
}
8078

8179

82-
/**
83-
* @task info
84-
*/
85-
public static function getGlobal($key, $default = null) {
86-
self::validateGlobal($key);
87-
88-
if (!array_key_exists($key, self::$globals)) {
89-
return $default;
90-
}
91-
92-
return self::$globals[$key];
93-
}
94-
9580
/**
9681
* @task info
9782
*/
@@ -108,7 +93,7 @@ public static function getRawInput() {
10893
*/
10994
public static function didStartup() {
11095
self::$startTime = microtime(true);
111-
self::$globals = array();
96+
self::$accessLog = null;
11297

11398
static $registered;
11499
if (!$registered) {
@@ -348,8 +333,7 @@ public static function didFatal($message, $log_message = null) {
348333
}
349334

350335
self::endOutputCapture();
351-
$access_log = self::getGlobal('log.access');
352-
336+
$access_log = self::$accessLog;
353337
if ($access_log) {
354338
// We may end up here before the access log is initialized, e.g. from
355339
// verifyPHP().
@@ -402,19 +386,22 @@ public static function getOldMemoryLimit() {
402386
*/
403387
private static function normalizeInput() {
404388
// Replace superglobals with unfiltered versions, disrespect php.ini (we
405-
// filter ourselves)
406-
$filter = array(INPUT_GET, INPUT_POST,
407-
INPUT_SERVER, INPUT_ENV, INPUT_COOKIE,
389+
// filter ourselves).
390+
391+
// NOTE: We don't filter INPUT_SERVER because we don't want to overwrite
392+
// changes made in "preamble.php".
393+
$filter = array(
394+
INPUT_GET,
395+
INPUT_POST,
396+
INPUT_ENV,
397+
INPUT_COOKIE,
408398
);
409399
foreach ($filter as $type) {
410400
$filtered = filter_input_array($type, FILTER_UNSAFE_RAW);
411401
if (!is_array($filtered)) {
412402
continue;
413403
}
414404
switch ($type) {
415-
case INPUT_SERVER:
416-
$_SERVER = array_merge($_SERVER, $filtered);
417-
break;
418405
case INPUT_GET:
419406
$_GET = array_merge($_GET, $filtered);
420407
break;
@@ -551,21 +538,6 @@ private static function verifyRewriteRules() {
551538
}
552539

553540

554-
/**
555-
* @task validation
556-
*/
557-
private static function validateGlobal($key) {
558-
static $globals = array(
559-
'log.access' => true,
560-
'csrf.salt' => true,
561-
);
562-
563-
if (empty($globals[$key])) {
564-
throw new Exception("Access to unknown startup global '{$key}'!");
565-
}
566-
}
567-
568-
569541
/**
570542
* Detect if this request has had its POST data stripped by exceeding the
571543
* 'post_max_size' PHP configuration limit.

0 commit comments

Comments
 (0)
Failed to load comments.