anax/response
Composer 安装命令:
composer require anax/response
包简介
Anax Response module, to create a HTTP response.
README 文档
README
Anax Response module to send HTTP responses.
The module is used to send a HTTP response from the Anax framework, including status code, headers, and body.
Table of content
- Class, interface, trait
- Exceptions
- Configuration file
- DI service
- General usage within the Anax framework
- Access as framework service
- Create, init and use an object
Class, interface, trait
The following classes, interfaces and traits exists.
| Class, interface, trait | Description |
|---|---|
Anax\Response\Response |
Wrapper class for response details and related. |
Anax\Response\ResponseUtility |
Extends the Request class to be injectable with $id to enable easy to use redirect methods. |
Exceptions
Module specific exceptions are thrown through Anax\Response\Exception.
Configuration file
There is no configuration file for this module.
DI service
The module is created as a framework service within $di. You can see the details in the configuration file config/di/response.php.
It can look like this.
/** * Configuration file for DI container. */ return [ // Services to add to the container. "services" => [ "response" => [ "shared" => true, //"callback" => "\Anax\Response\Response", "callback" => function () { $obj = new \Anax\Response\ResponseUtility(); $obj->setDI($this); return $obj; } ], ], ];
- The object is created as a shared resource.
- DI is injected into the module, when using ResponseUtility.
The service is lazy loaded and not created until it is used.
General usage within the Anax framework
The response service is a mandatory service within the Anax framework and it is the first service used when handling a request to the framework.
Here is the general flow for receiving a request, mapping it to a route and returning a response. This is found in the frontcontroller htdocs/index.php of an Anax installation.
// Leave to router to match incoming request to routes $response = $di->get("router")->handle( $di->get("request")->getRoute(), $di->get("request")->getMethod() ); // Send the HTTP response with headers and body $di->get("response")->send($response);
The request is used to get the request method and the route path, these are used by the router service to find a callback for the route. Each callback can then return a response which is sent through the response service.
Access as framework service
You can access the module as a framework service.
# $app style $app->response->redirectSelf(); # $di style, two alternatives $di->get("response")->redirectSelf(); $response = $di->get("response"); $response->redirectSelf();
Create, init and use an object
This is how the object can be created. This is usually done within the framework as a sevice in $di.
# Create an object response = new \Anax\Response\Response(); # Send a response response->send("Some response"); response->sendJson(["key" => "Some value"]); response->redirect($absoluteUrl);
The added benefit of using ResponseUtility is that this class is injected with DI and makes it easier to use the redirect methods for urls within the framework.
# Create an object response = new \Anax\Response\ResponseUtility(); # Do a redirect response->redirect("game/init"); response->redirectSelf();
License
This software carries a MIT license. See LICENSE.txt for details.
.
..: Copyright (c) 2013 - 2019 Mikael Roos, mos@dbwebb.se
anax/response 适用场景与选型建议
anax/response 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20.04k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 03 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「mvc」 「boilerplate」 「micro」 「education」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 anax/response 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 anax/response 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 anax/response 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
Kinikit - PHP Application development framework MVC component
PHP class to extend when building a WordPress plugin allowing you to follow smart plugin setup standards.
Anax htmlform module.
Laravel 5.7 Boilerplate based on Bootstrap 4 and Tabler for Backend.
WordPress Plugin Framework
统计信息
- 总下载量: 20.04k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 37
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-03-07