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)
* Require Grav v1.7
* 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
## mm/dd/2019

View File

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

View File

@@ -1145,8 +1145,7 @@ class Admin
if (function_exists('phpinfo')) {
ob_start();
phpinfo();
$pinfo = ob_get_contents();
ob_end_clean();
$pinfo = ob_get_clean();
$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\Plugin;
use Grav\Common\Theme;
use Grav\Framework\Psr7\Response;
use RocketTheme\Toolbox\Event\Event;
use RocketTheme\Toolbox\File\File;
@@ -208,24 +209,22 @@ class AdminBaseController
/**
* Sends JSON response and terminates the call.
*
* @param array $response
* @param array $json
* @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.
http_response_code($code);
header('Content-Type: application/json');
header('Cache-Control: no-cache, no-store, must-revalidate');
$response = new Response(
$code,
[
'Content-Type' => 'application/json',
'Cache-Control' => 'no-cache, no-store, must-revalidate'
],
json_encode($json)
);
echo json_encode($response);
exit();
$this->grav->exit($response);
}
/**

View File

@@ -22,6 +22,7 @@ use Grav\Common\Security;
use Grav\Common\User\Interfaces\UserCollectionInterface;
use Grav\Common\User\User;
use Grav\Common\Utils;
use Grav\Framework\Psr7\Response;
use Grav\Plugin\Login\TwoFactorAuth\TwoFactorAuth;
use Grav\Common\Yaml;
use PicoFeed\Parser\MalformedXmlException;
@@ -876,7 +877,9 @@ class AdminController extends AdminBaseController
*/
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);
if (0 !== strpos($file, $backups_root_dir)) {
header('HTTP/1.1 401 Unauthorized');
exit();
$response = new Response(401);
$this->grav->exit($response);
}
Utils::download($file, true);