定制 ellipse/handlers-container 二次开发

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

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

ellipse/handlers-container

Composer 安装命令:

composer require ellipse/handlers-container

包简介

Psr-15 request handler proxying a Psr-11 container entry

README 文档

README

This package provides a Psr-15 request handler proxying a Psr-11 container entry.

Require php >= 7.0

Installation composer require ellipse/handlers-container

Run tests ./vendor/bin/kahlan

Using container entries as request handlers

The class Ellipse\Handlers\ContainerRequestHandler takes an implementation of Psr\Container\ContainerInterface and a container id as parameters. Its ->handle() method retrieve a request handler from the container using this id and proxy its ->handle() method.

It can be useful in situations the container entry should be resolved at the time the request is handled.

An Ellipse\Handlers\Exceptions\ContainedRequestHandlerTypeException is thrown when the value retrieved from the container is not an object implementing Psr\Http\Server\RequestHandlerInterface.

<?php

namespace App;

use SomePsr11Container;

use Ellipse\Handlers\ContainerRequestHandler;

// Get some Psr-11 container.
$container = new SomePsr11Container;

// Add a request handler in the container.
$container->set('some.request.handler', function () {

    return new SomeRequestHandler;

});

// Create a container request handler with the Psr-11 container and the entry id.
$handler = new ContainerRequestHandler($container, 'some.request.handler');

// The handler ->handle() method retrieve the request handler from the container and proxy it.
$response = $handler->handle($request);

Example using auto wiring

It can be cumbersome to register every request handler classes in the container. Here is how to auto wire request handler instances using the Ellipse\Container\ReflectionContainer class from the ellipse/container-reflection package.

<?php

namespace App;

use Psr\Http\Server\RequestHandlerInterface;

use SomePsr11Container;

use Ellipse\Container\ReflectionContainer;
use Ellipse\Handlers\ContainerRequestHandler;

// Get some Psr-11 container.
$container = new SomePsr11Container;

// Decorate the container with a reflection container.
// Specify the request handler implementations can be auto wired.
$reflection = new ReflectionContainer($container, [
    RequestHandlerInterface::class,
]);

// Create a container request handler with the reflection container and a request handler class name.
$handler = new ContainerRequestHandler($reflection, SomeRequestHandler::class);

// An instance of SomeRequestHandler is built and its ->handle() method is proxied.
$response = $handler->handle($request);

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-03-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固