定制 weew/http-app 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

weew/http-app

Composer 安装命令:

composer require weew/http-app

包简介

Http version of the weew/app package.

README 文档

README

Build Status Code Quality Test Coverage Version Licence

Table of contents

Installation

composer require weew/http-app

Introduction

This is a very minimalistic wrapper for a http application.

Usage

The whole app lifecycle is event based. To successfully handle http requests you must handle the HandleHttpRequestEvent and provide a valid response that implements the IHttpResponse interface.

Below is a very basic example of how you might implement this.

$app = new HttpApp();
$app->getEventer()
    ->subscribe(HandleHttpRequestEvent::class, function(HandleHttpRequestEvent $event) {
        $request = $event->getRequest();

        // handle request (do some routing, call a controller, etc.)
        // provide a response that implements the IHttpResponse interface
        $event->setResponse($response);
    });

There is already an existing implementation for this, see weew/http-app-request-handler.

Environment awareness

Sometimes you might want, for example during tests, to send a request to the same front controller but in a different environment. Symfony does this using different front controllers: app.php and app_dev.php. This approach will however alter the url and might not be suitable in some situations. Beside creating different front controllers you can also specify an environment using the x-env: dev header or a query param ?env=dev or a somewhere inside your url /env=dev/some/url. If an environment setting can be detected either via headers or url query or url part, the corresponding data (x-env header, env query param, env value inside the url) will be automatically removed. This feature is disabled by default and you can enable it by setting debug to true.

$app->setDebug(true);
$request = new HttpRequest();

$request->getHeaders()->set('x-env', 'stage');
// or
$request->getUrl()->getQuery()->set('env', 'stage');
// or
$request->getUrl()->setPath('/env=stage/some/url');

// app will run in the "stage" environment
$app->handle($request);

You must not use this in production! This is why it is disabled by default. Only enable this feature for your dev environment.

Extensions

There are several extensions available:

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-07-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固