1. Go to this page and download the library: Download ctw/ctw-http 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/ */
ctw / ctw-http example snippets
use Ctw\Http\HttpStatus;
$httpStatus = new HttpStatus(HttpStatus::STATUS_NOT_FOUND);
dump($httpStatus->get());
^ Ctw\Http\Entity\HttpStatus^ {#2
+statusCode: 404
+name: "Not Found"
+phrase: "The requested resource could not be found but may be available again in the future."
+exception: "Ctw\Http\HttpException\NotFoundException"
+url: "https://httpstatuses.com/404"
}
use Ctw\Http\HttpException;
throw new HttpException\NotFoundException();
PHP Fatal error: Uncaught Ctw\Http\HttpException\NotFoundException:
404 Not Found in /path/demo-usage.php:20
Stack trace:
#0 {main}
thrown in /path/demo-usage.php on line 20
use Ctw\Http\HttpException;
throw new HttpException\NotFoundException('Custom 404 error message');
PHP Fatal error: Uncaught Ctw\Http\HttpException\NotFoundException:
Custom 404 error message in /path/demo-usage.php:21
Stack trace:
#0 {main}
thrown in /path/demo-usage.php on line 21
use Ctw\Http\HttpException;
try {
throw new HttpException\NotFoundException();
} catch (HttpException\HttpExceptionInterface $e) {
dump($e->getStatusCode());
dump($e->getMessage());
}
use Ctw\Http\HttpException\HttpExceptionInterface;
use Ctw\Http\HttpException\AbstractException;
use Ctw\Http\HttpException\AbstractClientErrorException;
use Ctw\Http\HttpException\AbstractServerErrorException;
HttpExceptionInterface
└── AbstractException
├── AbstractClientErrorException
│ └── *Exception
└── AbstractServerErrorException
└── *Exception