mirror of
https://github.com/processwire/processwire.git
synced 2025-08-12 17:54:44 +02:00
Update TemplateFile class with a clearAll() static method and update ProcessPageView to use it when a 404 is thrown. This ensures that a 404 thrown after some output has already been sent can't get interpreted as a non-404 by the client
This commit is contained in:
@@ -140,6 +140,14 @@ class TemplateFile extends WireData {
|
|||||||
*/
|
*/
|
||||||
static protected $globals = array();
|
static protected $globals = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Output buffer starting level, set by first TemplateFile instance that gets created
|
||||||
|
*
|
||||||
|
* @var null|int
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static protected $obStartLevel = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct the template file
|
* Construct the template file
|
||||||
*
|
*
|
||||||
@@ -147,6 +155,7 @@ class TemplateFile extends WireData {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function __construct($filename = '') {
|
public function __construct($filename = '') {
|
||||||
|
if(self::$obStartLevel === null) self::$obStartLevel = ob_get_level();
|
||||||
if($filename) $this->setFilename($filename);
|
if($filename) $this->setFilename($filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -561,6 +570,24 @@ class TemplateFile extends WireData {
|
|||||||
return self::$renderStack;
|
return self::$renderStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear out all pending output buffers
|
||||||
|
*
|
||||||
|
* @since 3.0.175
|
||||||
|
* @return int Number of output buffers cleaned
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static function clearAll() {
|
||||||
|
$n = 0;
|
||||||
|
if(self::$obStartLevel !== null) {
|
||||||
|
while(ob_get_level() > self::$obStartLevel) {
|
||||||
|
ob_end_clean();
|
||||||
|
$n++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $n;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The string value of a TemplateFile is its PHP template filename OR its class name if no filename is set
|
* The string value of a TemplateFile is its PHP template filename OR its class name if no filename is set
|
||||||
*
|
*
|
||||||
|
@@ -227,6 +227,7 @@ class ProcessPageView extends Process {
|
|||||||
|
|
||||||
} catch(Wire404Exception $e) {
|
} catch(Wire404Exception $e) {
|
||||||
// 404 exception
|
// 404 exception
|
||||||
|
TemplateFile::clearAll();
|
||||||
return $this->renderNoPage(array(
|
return $this->renderNoPage(array(
|
||||||
'reason404' => '404 thrown during page render',
|
'reason404' => '404 thrown during page render',
|
||||||
'exception404' => $e,
|
'exception404' => $e,
|
||||||
|
Reference in New Issue
Block a user