hoku-lib/httpstatuscoderesolver

HttpStatusCodeResolver 是一个用于获取HTTP状态码信息的库。

v1.0.0 2018-11-15 14:20 UTC

This package is auto-updated.

Last update: 2024-09-16 03:31:23 UTC


README

HttpStatusCodeResolver 是一个用于获取HTTP状态码信息的库。

安装

推荐通过 Composer 安装 HttpStatusCodeResolver。

composer require hoku-lib/httpstatuscoderesolver

使用方法

获取消息。

<?php
require_once 'vendor/autoload.php';

$statusCodeInfo = \HttpStatusCodeResolver\HttpStatusCode::resolve(400);
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Demo</title>
</head>
<body>
    <?php if ($statusCodeInfo) : ?>
        <div><?=$statusCodeInfo[0]?></div>
        <div><?=$statusCodeInfo[1]?></div>
    <?php else : ?>
        <div>I do not know!</div>
    <?php endif; ?>
</body>
</html>

输出头信息。

<?php
require_once 'vendor/autoload.php';

\HttpStatusCodeResolver\HttpHeader::http_response_code(403);
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Demo</title>
</head>
<body>
    <h1>Forbidden!!!!</h1>
</body>
</html>

原始状态码(使用 http_response_code() 时。)

<?php
require_once 'vendor/autoload.php';

http_response_code(987);
// -> HTTP/1.1 500 Internal Server Error
// Oh my God!!!!
// PHP converts the status code to 500...
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Demo</title>
</head>
<body>
    <div>Oh no...</div>
</body>
</html>

原始状态码(使用 HttpHeader::http_response_code() 时。)

<?php
require_once 'vendor/autoload.php';

\HttpStatusCodeResolver\HttpHeader::http_response_code(987, 'MyOriginalCode');
// -> HTTP/1.1 987 MyOriginalCode
// Yay! Happy!
->
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Demo</title>
</head>
<body>
    <div>Yay!!!!</div>
</body>
</html>

许可证

HttpStatusCodeResolver 在 MIT 许可证下发布。有关详细信息,请参阅 LICENSE 文件。