Use $grav->exit() instead of exit()

This commit is contained in:
Matias Griese
2019-06-03 13:17:16 +03:00
parent ed41aabe85
commit f4d5ccf731
5 changed files with 25 additions and 21 deletions

View File

@@ -4,7 +4,7 @@
1. [](#new) 1. [](#new)
* Require Grav v1.7 * Require Grav v1.7
* Use PSR-4 for plugin classes * Use PSR-4 for plugin classes
* Added support for Twig 2.11 * Added support for Twig 2.11 (compatible with Twig 1.40+)
# v1.9.5 # v1.9.5
## mm/dd/2019 ## mm/dd/2019

View File

@@ -17,6 +17,7 @@ use Grav\Common\Session;
use Grav\Common\Uri; use Grav\Common\Uri;
use Grav\Common\User\Interfaces\UserCollectionInterface; use Grav\Common\User\Interfaces\UserCollectionInterface;
use Grav\Common\Utils; use Grav\Common\Utils;
use Grav\Framework\Psr7\Response;
use Grav\Framework\Session\Exceptions\SessionException; use Grav\Framework\Session\Exceptions\SessionException;
use Grav\Plugin\Admin\Admin; use Grav\Plugin\Admin\Admin;
use Grav\Plugin\Admin\Popularity; use Grav\Plugin\Admin\Popularity;
@@ -437,8 +438,9 @@ class AdminPlugin extends Plugin
$this->initializeController($task, $post); $this->initializeController($task, $post);
} elseif ($this->template === 'logs' && $this->route) { } elseif ($this->template === 'logs' && $this->route) {
// Display RAW error message. // Display RAW error message.
echo $this->admin->logEntry(); $response = new Response(200, [], $this->admin->logEntry());
exit();
$this->grav->exit($response);
} }
$self = $this; $self = $this;

View File

@@ -1145,8 +1145,7 @@ class Admin
if (function_exists('phpinfo')) { if (function_exists('phpinfo')) {
ob_start(); ob_start();
phpinfo(); phpinfo();
$pinfo = ob_get_contents(); $pinfo = ob_get_clean();
ob_end_clean();
$pinfo = preg_replace('%^.*<body>(.*)</body>.*$%ms', '$1', $pinfo); $pinfo = preg_replace('%^.*<body>(.*)</body>.*$%ms', '$1', $pinfo);

View File

@@ -14,6 +14,7 @@ use Grav\Common\User\Interfaces\UserInterface;
use Grav\Common\Utils; use Grav\Common\Utils;
use Grav\Common\Plugin; use Grav\Common\Plugin;
use Grav\Common\Theme; use Grav\Common\Theme;
use Grav\Framework\Psr7\Response;
use RocketTheme\Toolbox\Event\Event; use RocketTheme\Toolbox\Event\Event;
use RocketTheme\Toolbox\File\File; use RocketTheme\Toolbox\File\File;
@@ -208,24 +209,22 @@ class AdminBaseController
/** /**
* Sends JSON response and terminates the call. * Sends JSON response and terminates the call.
* *
* @param array $response * @param array $json
* @param int $code * @param int $code
* @return bool
*/ */
protected function sendJsonResponse(array $response, $code = 200) protected function sendJsonResponse(array $json, $code = 200): void
{ {
// Make sure nothing extra gets written to the response.
while (ob_get_level()) {
ob_end_clean();
}
// JSON response. // JSON response.
http_response_code($code); $response = new Response(
header('Content-Type: application/json'); $code,
header('Cache-Control: no-cache, no-store, must-revalidate'); [
'Content-Type' => 'application/json',
'Cache-Control' => 'no-cache, no-store, must-revalidate'
],
json_encode($json)
);
echo json_encode($response); $this->grav->exit($response);
exit();
} }
/** /**

View File

@@ -22,6 +22,7 @@ use Grav\Common\Security;
use Grav\Common\User\Interfaces\UserCollectionInterface; use Grav\Common\User\Interfaces\UserCollectionInterface;
use Grav\Common\User\User; use Grav\Common\User\User;
use Grav\Common\Utils; use Grav\Common\Utils;
use Grav\Framework\Psr7\Response;
use Grav\Plugin\Login\TwoFactorAuth\TwoFactorAuth; use Grav\Plugin\Login\TwoFactorAuth\TwoFactorAuth;
use Grav\Common\Yaml; use Grav\Common\Yaml;
use PicoFeed\Parser\MalformedXmlException; use PicoFeed\Parser\MalformedXmlException;
@@ -876,7 +877,9 @@ class AdminController extends AdminBaseController
*/ */
protected function taskKeepAlive() protected function taskKeepAlive()
{ {
exit(); $response = new Response(200);
$this->grav->exit($response);
} }
/** /**
@@ -1310,8 +1313,9 @@ class AdminController extends AdminBaseController
$backups_root_dir = $this->grav['locator']->findResource('backup://', true); $backups_root_dir = $this->grav['locator']->findResource('backup://', true);
if (0 !== strpos($file, $backups_root_dir)) { if (0 !== strpos($file, $backups_root_dir)) {
header('HTTP/1.1 401 Unauthorized'); $response = new Response(401);
exit();
$this->grav->exit($response);
} }
Utils::download($file, true); Utils::download($file, true);