PHP code example of atournayre / exception-handler
1. Go to this page and download the library: Download atournayre/exception-handler library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
atournayre / exception-handler example snippets
// Example for a NotFound (404)
#[NotFound]
class OrderNotFound extends Exception
{
public function __construct(OrderId $id)
{
parent::__construct(
sprintf('The order "%s" could not be found.', (string) $id)
);
}
}
// Example for a UnprocessableEntity (422)
#[UnprocessableEntity]
class OrderAlreadyShipped extends Exception { ... }
// Example for a Forbidden (403)
#[Forbidden]
class CustomerMismatch extends Exception { ... }