PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.2.2
Kirki – Freeform Page Builder, Website Builder & Customizer v6.2.2
6.2.3 6.2.2 6.2.1 6.2.0 6.1.1 6.1.0 6.0.14 6.0.13 6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.19 4.0.20 4.0.21 4.0.22 4.0.23 4.0.24 4.1 4.2.0 5.0.0 5.1.0 5.1.1 5.2.0 5.2.1 5.2.2 5.2.3 6.0.0 trunk 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.1.0 3.1.1 3.1.2
kirki / libraries / framework / SiteExceptionHandler.php
kirki / libraries / framework Last commit date
Collections 1 month ago Concerns 1 month ago Console 2 weeks ago Constants 5 days ago Contracts 5 days ago Database 5 days ago Discovery 5 days ago Exceptions 2 weeks ago Filesystem 2 weeks ago Http 5 days ago Managers 5 days ago Middlewares 1 month ago Polyfill 1 month ago Routing 2 weeks ago Supports 2 weeks ago Validation 1 week ago View 2 weeks ago Wordpress 5 days ago ApiExceptionHandler.php 1 month ago Application.php 5 days ago Container.php 1 month ago CoreServiceProvider.php 2 weeks ago DTO.php 1 month ago Facade.php 1 month ago Listener.php 1 month ago Resource.php 2 weeks ago Route.php 2 weeks ago Sanitizer.php 2 weeks ago ServiceProvider.php 1 month ago SiteExceptionHandler.php 2 weeks ago helpers.php 2 weeks ago
SiteExceptionHandler.php
66 lines
1 <?php
2
3 /**
4 * Translates thrown exceptions into WordPress-native site route error responses.
5 * Maps authorization, not-found, and validation failures to HTTP status pages.
6 *
7 * @package Framework
8 * @since 1.0.0
9 */
10 namespace Kirki\Framework;
11
12 \defined('ABSPATH') || exit;
13 use Kirki\Framework\Exceptions\AuthorizationException;
14 use Kirki\Framework\Exceptions\ModelNotFoundException;
15 use Kirki\Framework\Exceptions\ValidationException;
16 use Kirki\Framework\Http\Response;
17 use Exception;
18 class SiteExceptionHandler
19 {
20 /**
21 * Handle an exception for a site route request.
22 *
23 * @param Exception $exception The exception to handle.
24 *
25 * @return void
26 *
27 * @since 1.0.0
28 */
29 public static function handle(Exception $exception)
30 {
31 if ($exception instanceof AuthorizationException) {
32 static::fail(Response::FORBIDDEN, $exception->getMessage() ?: 'Forbidden');
33 }
34 if ($exception instanceof ModelNotFoundException) {
35 static::fail(Response::NOT_FOUND, $exception->getMessage() ?: 'Not Found');
36 }
37 if ($exception instanceof ValidationException) {
38 static::fail(Response::UNPROCESSABLE_ENTITY, $exception->getMessage() ?: 'Validation failed');
39 }
40 $status = (int) $exception->getCode();
41 if ($status < 100 || $status > 599) {
42 $status = Response::INTERNAL_SERVER_ERROR;
43 }
44 if (\function_exists('error_log')) {
45 \error_log($exception->getMessage());
46 }
47 static::fail($status, $exception->getMessage() ?: 'Internal Server Error');
48 }
49 /**
50 * Stop the request with a WordPress error page at the given HTTP status.
51 *
52 * @param int $status HTTP status code.
53 * @param string $message Error message.
54 *
55 * @return void
56 *
57 * @since 1.0.0
58 */
59 protected static function fail(int $status, string $message)
60 {
61 status_header($status);
62 nocache_headers();
63 wp_die(esc_html($message), esc_html($message), ['response' => $status]);
64 }
65 }
66