night-commit/php-http
Composer 安装命令:
composer require night-commit/php-http
包简介
php library to handle http requests and responses
README 文档
README
PHP-HTTP is a lightweight PHP package to simplify working with requests, responses, cookies, sessions and file uploads
Installation
composer require night-commit/php-http
Usage Example
working with Requests:
<?php use NightCommit\PHP\Http\Request; $request = new Request(); // Returns the raw request JSON post data $request->content(); // Returns the decoded request JSON data as an array $request->data(); // Returns a specific GET parameter, or the default value if not set $request->get("name", "default value"); // Returns a specific POST parameter, or the default value if not set $request->post("name", "default value"); // Check if a specific key exists in GET or POST $request->exists("name", $data); // Check if a specific key exists and is not empty in GET or POST $request->filled("name", $data); // get request headers $request->headers(); // get specific header and returns null if not found $request->headers('Authorization'); // get bearer token $request->bearer(); // Server-related helpers $request->root(); // Document root $request->server_name(); // Server name $request->server_port(); // Server port (e.g., 8000) $request->host(); // Host (e.g., 127.0.0.1) $request->uri(); // Request URI $request->query(); // Query string
working with File Uploads:
<?php use NightCommit\PHP\Http\Request; $request = new Request; /** * return an array of the uploaded file data */ $request->files(); /** * return the specified file */ $file = $request->file('picture-name'); // file name $file->name(); // file tmp name $file->tmp(); // file size in bytes $file->size(); // file extension $file->extension(); /** * check if file is uploaded or not */ $file->uploaded(); /** * stores the file in the specified path */ $file->strore('somewhere/in/the/system', 'optional-name');
working with Responses:
<?php use NightCommit\PHP\Http\Response; /** * You can specify the status code directly or use predefined constants: * * Response::OK = 200; * Response::CREATED = 201; * Response::ACCEPTED = 202; * * Response::MOVED = 301; * Response::FOUND = 302; * * Response::BAD_REQUEST = 400; * Response::UNAUTHORIZED = 401; * Response::PAYMENT_REQUIRED = 402; * Response::FORBIDDEN = 403; * Response::NOT_FOUND = 404; * Response::METHOD_NOT_ALLOWED = 405; * Response::NOT_ACCEPTABLE = 406; * Response::REQUEST_TIMEOUT = 408; * Response::CONFLICT = 409; * Response::GONE = 410; * Response::MANY_REQUESTS = 429; * * Response::SERVER_ERROR = 500; * Response::NOT_IMPLEMENTED = 501; * Response::BAD_GATEWAY = 502; * Response::SERVICE_UNAVAILABLE = 503; * Response::GATEWAY_TIMEOUT = 504; */ // Sends a response with JSON data and a status code (default 200) Response::send($data = "", $status, $headers); // Sends a response with an array as JSON and sets Content-Type: application/json Response::json($data = [], $status, $headers);
working with Cookies:
<?php use NightCommit\PHP\Http\Cookie; // set a cookie Cookie::set('cookie-name', 'value', Cookie::minutes(10)); // get a cookie Cookie::get('cookie-name'); // delete a cookie Cookie::forget('cookie-name'); // Cookie helper methods Cookie::seconds($count); Cookie::minutes($count); Cookie::hours($count); Cookie::days($count); Cookie::months($count); Cookie::year($count);
working with Sessions:
<?php use NightCommit\PHP\Http\Session; /** * You can instantiate the Session class * or use the session method in the Request class */ $session = new Seession; // or $request = new Request; $session = $request->sesssion(); // start session if not already started $session->start(); // destroy the session $session->destroy(); // set session variable $session->set('name', 'john doe or whatever'); // get session variable $session->get('name'); // get all session variables $session->all(); // session id $session->id(); // regenerate session id $session->regenerate_id(); // session name $session->name(); // session status $session->status(); // delete session variable $session->forget('name'); // delete all session variables but not the session itself $session->flush();
License
This package is licensed under the MIT License.
night-commit/php-http 适用场景与选型建议
night-commit/php-http 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 09 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 night-commit/php-http 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 night-commit/php-http 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2025-09-17