承接 charm/interop 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

charm/interop

Composer 安装命令:

composer require charm/interop

包简介

A set of traits for classes that expect to have various common services injeted.

README 文档

README

Whenever you write a library that needs to be interoperable with PSR, these traits provide a simple way for your users to inject the expected implementations.

ExampleMiddleware

<?php
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;

/**
 * This example middleware logs messages using a PSR-3 Log implementation,
 * and returns new responses using a PSR-17 Http Factory implementation.
 */
class SomeMiddleware implements MiddlewareInterface {

    /**
     * We'll be logging the requests, so we need a `$this->logger()` method.
     */
    use Charm\Interop\InjectedLogger;

    /**
     * We want to create a response object but we don't want to roll our own
     */
    use Charm\Interop\InjectedResponseFactory;

    /**
     * Response objects contain streams
     */
    use Charm\Interop\InjectedStreamFactory;

    public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface {

        // Log the request
        $this->logger()->info("{method} {requestTarget}", [
            'method' => $request->getMethod(),
            'requestTarget' => $request->getRequestTarget(),
        ]);

        if (mt_rand(0,1)) {
            // Create the response body
            $body = $this->streamFactory()->createStream("Sorry. I don't feel like serving you this page right now!");

            // Create the response
            $response = $this->responseFactory()->createResponse(200, ['Content-Type' => 'text/plain'], $body);

            return $response;
        }

        // We're not hijacking this request, so pass to the `$next` request handler
        return $next->handle($request);
    }

}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-08-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固