public function __construct() { if (is_int($code = http_response_code())) { $this->code = $code; } header_register_callback((new \ReflectionMethod('Nette\\Http\\Helpers::removeDuplicateCookies'))->getClosure()); // requires closure due PHP bug #66375 }
public function __construct() { if (PHP_VERSION_ID >= 50400) { if (is_int(http_response_code())) { $this->code = http_response_code(); } header_register_callback($this->removeDuplicateCookies); } }
public function __construct($namespace_ = self::DEFAULT_NAMESPACE, $message_ = null, $code_ = self::DEFAULT_ERROR_CODE, $cause_ = null, $logEnabled_ = true) { if (null === $message_ && isset(self::$m_mapHttpErrorCodes[$code_])) { $message_ = self::$m_mapHttpErrorCodes[$code_]; } parent::__construct($namespace_, $message_, $cause_, $logEnabled_); $this->code = $code_; header_register_callback(function () { header($this->message, true, $this->code); }); }
public function testHeaderRegisterCallback() { if (!function_exists('header_register_callback')) { return true; } $callback = function () use(&$called) { $called = 1; }; header_register_callback($callback); $values = Manager::values(); $this->assertSame($callback, $values['header']['callback']); }
public function __construct() { if (PHP_VERSION_ID >= 50400) { if (is_int($code = http_response_code())) { $this->code = $code; } } if (PHP_VERSION_ID >= 50401) { // PHP bug #61106 header_register_callback($this->removeDuplicateCookies); // requires closure due PHP bug #66375 } }
public function __construct() { if (PHP_VERSION_ID >= 50400) { if (is_int($code = http_response_code())) { $this->code = $code; } } if (PHP_VERSION_ID >= 50401) { // PHP bug #61106 $rm = new \ReflectionMethod('Nette\\Http\\Helpers::removeDuplicateCookies'); header_register_callback($rm->getClosure()); // requires closure due PHP bug #66375 } }
// Apply $wgSharedDB table aliases for the local LB (all non-foreign DB connections) MediaWikiServices::getInstance()->getDBLoadBalancer()->setTableAliases(array_fill_keys($wgSharedTables, ['dbname' => $wgSharedDB, 'schema' => $wgSharedSchema, 'prefix' => $wgSharedPrefix])); } // Define a constant that indicates that the bootstrapping of the service locator // is complete. define('MW_SERVICE_BOOTSTRAP_COMPLETE', 1); // Install a header callback to prevent caching of responses with cookies (T127993) if (!$wgCommandLineMode) { header_register_callback(function () { $headers = []; foreach (headers_list() as $header) { list($name, $value) = explode(':', $header, 2); $headers[strtolower(trim($name))][] = trim($value); } if (isset($headers['set-cookie'])) { $cacheControl = isset($headers['cache-control']) ? implode(', ', $headers['cache-control']) : ''; if (!preg_match('/(?:^|,)\\s*(?:private|no-cache|no-store)\\s*(?:$|,)/i', $cacheControl)) { header('Expires: Thu, 01 Jan 1970 00:00:00 GMT'); header('Cache-Control: private, max-age=0, s-maxage=0'); MediaWiki\Logger\LoggerFactory::getInstance('cache-cookies')->warning('Cookies set on {url} with Cache-Control "{cache-control}"', ['url' => WebRequest::getGlobalRequestURL(), 'cookies' => $headers['set-cookie'], 'cache-control' => $cacheControl ?: '<not set>']); } } }); } MWExceptionHandler::installHandler(); require_once "{$IP}/includes/compat/normal/UtfNormalUtil.php"; $ps_validation = Profiler::instance()->scopedProfileIn($fname . '-validation'); // T48998: Bail out early if $wgArticlePath is non-absolute foreach (['wgArticlePath', 'wgVariantArticlePath'] as $varName) { if (${$varName} && !preg_match('/^(https?:\\/\\/|\\/)/', ${$varName})) { throw new FatalError("If you use a relative URL for \${$varName}, it must start " . 'with a slash (<code>/</code>).<br><br>See ' . "<a href=\"https://www.mediawiki.org/wiki/Manual:\${$varName}\">" . "https://www.mediawiki.org/wiki/Manual:\${$varName}</a>.");
/** * Mark this session as dirty. * * This method will register a callback to save the session right before any output is sent to the browser. */ public function markDirty() { if ($this->isTransient()) { return; } $this->dirty = true; if (!function_exists('header_register_callback')) { // PHP version < 5.4, can't register the callback return; } if ($this->callback_registered) { // we already have a shutdown callback registered for this object, no need to add another one return; } $this->callback_registered = header_register_callback(array($this, 'save')); }
public function start() { $this->fireEvent('AppStartup'); // Register callback allowing addons to modify response headers before PHP sends them. header_register_callback(function () { $this->fireEvent('SendHeaders'); }); }
$key = strtr($key, '_', ' '); $key = strtolower($key); $key = ucwords($key); $key = strtr($key, ' ', '-'); log(sprintf('%s: %s', $key, $value)); $requestHeaders[$key] = $value; } } header_register_callback(function () use(&$params) { log('- - - - - - - - - - - - - - - - - - - - - - - - -'); $status = sprintf('HTTP/1.1 %u %s', $params['code'], get_status_string($params['code'])); header($status, true); log($status); if (is_array($params['headers'])) { foreach ($params['headers'] as $header) { header($header); } } foreach (headers_list() as $header) { log($header); } log("\n" . $params['body']); }); if ($params['verbose'] == 1) { $postRaw = $_SERVER['REQUEST_METHOD'] === 'POST' ? file_get_contents("php://input") : ''; $putRaw = $_SERVER['REQUEST_METHOD'] === 'PUT' ? file_get_contents("php://input") : ''; $deleteRaw = $_SERVER['REQUEST_METHOD'] === 'DELETE' ? file_get_contents("php://input") : ''; parse_str($putRaw, $put); parse_str($deleteRaw, $delete); $params['body'] = json_encode(['requestHeaders' => $requestHeaders, 'body' => $params['body'], 'get' => $_GET, 'post_raw' => $postRaw, 'post' => $_POST, 'put_raw' => $putRaw, 'put' => $put, 'delete_raw' => $deleteRaw, 'delete' => $delete]); }
public static function callback(callable $callback) { return header_register_callback($callback); }
<?php class Foo { function bar() { } } header_register_callback([new Foo(), 'bar']); header_register_callback([new Foo(), 'baz']);