-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.php
More file actions
31 lines (22 loc) · 743 Bytes
/
Copy pathbasic.php
File metadata and controls
31 lines (22 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
/**
* Minimal setup: install the boundary once, at the entry point of any
* script that answers JSON, before any business logic runs.
*
* Run it: php examples/basic.php
*/
declare(strict_types=1);
require __DIR__ . '/../vendor/autoload.php';
use CleatSquad\ErrorBoundary\ErrorBoundary;
ErrorBoundary::install();
header('Content-Type: application/json');
// Anything below this line is covered: an uncaught exception or a PHP
// fatal now answers with the boundary's JSON envelope instead of an HTML
// error page.
function handleRequest(): array
{
// Simulate a bug: a method call on a null value deep in application code.
$user = null;
return ['name' => $user->getName()];
}
echo json_encode(handleRequest());