link1515/http-utils-php5
最新稳定版本:1.0.5
Composer 安装命令:
composer require link1515/http-utils-php5
包简介
For users working with PHP 5.x environments, this package provides a convenient solution. It provides encapsulated utilities for handling requests and responses.
关键字:
README 文档
README
For users working with PHP 5.x environments, this package provides a convenient solution. It provides encapsulated utilities for handling requests and responses.
Feature
- Easy to use
- Compatible with PHP 5.x
- The request body of the PUT and PATCH method can be resolved (including multipart/form-data)
Installation
composer require link1515/http-utils-php5
Usage
Request
| Return type | Method |
|---|---|
| string | getIp() |
| string | getHost() |
| string | getMethod() |
| array | getHeaders(?string $dotNotation = null) |
| array|string | getCookies(?string $dotNotation = null) |
| array|string | getQueryString(?string $dotNotation = null) |
| array|string|null | getBody(?string $dotNotation = null) |
| array|null | getFiles(?string $dotNotation = null) |
| array | toArray() |
<?php require_once __DIR__ . '/../vendor/autoload.php'; use Link1515\HttpUtilsPhp5\Request; // get the request instance $request = Request::getInstance(); // get property $ip = $request->getIp(); $method = $request->getMethod(); // get property of the array format // ex: https://example.com?name=Lynk&job=developer $queryString = $request->getQueryString(); // ['name' => 'Lynk', 'job' => 'developer'] // You can specify a key to get a value $name = $request->getQueryString('name'); // Lynk // You can even use dot notation to get nested values // ex: request body: { user: { order: { id: 123 }}} $orderId = $request->getBody('user.order.id'); // 123
Configure ipHeaderFilterChain
// You can configure the ipHeaderFilterChain by yourself. Headers earlier in the array are adopted first. Request::setIpHeaderFilterChain([ 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'REMOTE_ADDR' ]);
Response
- Response::setHeader(string $name, string $value, bool $replace = true)
- Response::setHeaders(array $headers, bool $replace = true)
- Response::status(int $code)
- Response::redierct(string $url, int $statusCode = 301)
- Response::json(array $data, int $statusCode = 200)
- Response::send(string $data, int $statusCode = 200)
<?php require_once __DIR__ . '/../vendor/autoload.php'; use Link1515\HttpUtilsPhp5\Response; use Link1515\HttpUtilsPhp5\Constant\Status; Response::json(['message' => 'not found'], Status::NOT_FOUND);
Constant
This package also provides some common constant.
- Link1515\HttpUtilsPhp5\Constant\Status
- Link1515\HttpUtilsPhp5\Constant\Method
- Link1515\HttpUtilsPhp5\Constant\ContentType
统计信息
- 总下载量: 21
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-03-20