irfantoor/http 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

irfantoor/http

Composer 安装命令:

composer require irfantoor/http

包简介

Psr Compliant HTTP suite for Hackers

README 文档

README

Irfan's Http package is a hacker's Http suite which implements psr/http-factory, psr/http-message and fig/http-message-util eliminating the validations part, so that you can audit your web apps or sites against vulnerabilities or can write small API's or testing utilities.

You can forget about the constraints of validations, while trying some innovative values for the Http Requests or Responses etc.

Quick install.

Use composer to include it in your package.

$ composer require irfantoor/http

Note: this package comes pre installed with the latest releases of Irfan's Engine (irfantoor/engine). Since there is a psr compliance at implementation of funtions, though not strictly adhering to the guide lines of validating the parameters etc., you can always use IrfanTOOR\Http in any of your packages requiring Psr compliant Http components, with the flexibilty of testing or enhancing the protocol for your home grown Http clients, IoT devices for example.

Examples

Here is an example code (you can find it in the examples folder):

<?php

# use php -S localhost:8000 examples/hello.php

require dirname(__DIR__) . "/vendor/autoload.php";

use IrfanTOOR\Http\ServerRequest;
use IrfanTOOR\Http\Response;

# Server request we have received
$request  = new ServerRequest();

# create a response to send
$response = new Response();
$response = $response
    ->withHeader("Content-Type", "application/json")
    ->withHeader("Engine", "Engine One v1.0")
;

# our simple router
$path = ltrim(rtrim($request->getUri()->getPath(), '/'), '/');
$args = $path === "" ? [] : explode('/', $path);
$action = $args[0] ?? "home";

# lets route
switch($action) {
    case "home":
        $response->getBody()->write(json_encode("I'm home"));
        break;

    case "hello":
        $name = ucfirst($args[1] ?? "world");
        $response->getBody()->write(json_encode("Hello " . $name . "!"));
        break;

    default:
        $response = $response
            ->withStatus(0, "the status quo")
            ->withProtocolVersion("2.0")
            ->withHeader("lib(rary)", "IrfanTOOR\Http 0.1")
        ;
        $response->getBody()->write(json_encode([
            "status" => 404,
            "error" => "nothing found here!",
        ]));
        break;
}

# thats all folks!
$response->send();

统计信息

  • 总下载量: 48
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 4
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-02-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固