定制 bulldog/http-factory 二次开发

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

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

bulldog/http-factory

Composer 安装命令:

composer require bulldog/http-factory

包简介

A PSR-17 compliant HTTP Factory

README 文档

README

Build Status

This library aims to provide a simple implementation of PSR-17 (HTTP Factories). It current supports Guzzle/Psr7 and Zend Diactoros. Installation and usage examples are below, but if you have any questions or issues, please create an issue.

Installation

composer require bulldog/http-factory

Usage

You can use the FactoryBuilder class to create the HTTP Factory of your choice, or you can instantiate them directly. Currently your choices are guzzle and zend. Each factory implements HttpFactoryInterface. Since this library uses PSR-17 all of the individual factories returned will implement their corresponding PSR-17 interface. For more detailed usage, please see the tests folder.

FactoryBuilder

<?php

require 'vendor/autoload.php';

use Bulldog\HttpFactory\FactoryBuilder;
$zendFactory = FactoryBuilder::get('zend');

RequestFactory

Since we can use guzzle or zend, I'll show both examples here, but only one in the rest of the examples. But you should know you can use them interchangeably.

Zend

<?php

require 'vendor/autoload.php';

use Bulldog\HttpFactory\FactoryBuilder;
$factory = FactoryBuilder::get('zend');
$requestFactory = $factory->requestFactory();
$r = $requestFactory->createRequest('GET', 'http://localhost');

Guzzle

You'll notice the only difference between the example above and the one below is we specify guzzle as the parameter to the get method.

<?php

require 'vendor/autoload.php';

use Bulldog\HttpFactory\FactoryBuilder;
$factory = FactoryBuilder::get('guzzle');
$requestFactory = $factory->requestFactory();
$r = $requestFactory->createRequest('GET', 'http://localhost');

Without FactoryBuilder

You don't have to use FactoryBuilder to get an HTTP Factory. See below.

<?php

require 'vendor/autoload.php';

use Bulldog\HttpFactory\GuzzleHttpFactory;
$factory = new GuzzleHttpFactory();
$requestFactory = $factory->requestFactory();
$r = $requestFactory->createRequest('GET', 'http://localhost');

ResponseFactory

In the rest of the examples, I'll only show one example using zend with the FactoryBuilder.

<?php

require 'vendor/autoload.php';

use Bulldog\HttpFactory\FactoryBuilder;
$factory = FactoryBuilder::get('zend');
$responseFactory = $factory->responseFactory();
$r = $responseFactory->createResponse(200, 'OK');

ServerRequestFactory

<?php

require 'vendor/autoload.php';

use Bulldog\HttpFactory\FactoryBuilder;
$factory = FactoryBuilder::get('zend');
$reqFactory = $factory->serverRequestFactory();
$params = ['name' => 'value'];
$r = $reqFactory->createServerRequest('GET', '/', $params);

StreamFactory

<?php

require 'vendor/autoload.php';

use Bulldog\HttpFactory\FactoryBuilder;
$httpFactory = FactoryBuilder::get('zend');
$factory = $httpFactory->streamFactory();
$params = ['name' => 'value'];
$r = $factory->createStream('php://memory');

UploadedFileFactory

<?php

require 'vendor/autoload.php';

use Bulldog\HttpFactory\FactoryBuilder;
$httpFactory = FactoryBuilder::get('zend');

$streamFactory = $httpFactory->streamFactory();
$resource = $streamFactory->createStream('php://temp');

$factory = $httpFactory->uploadedFileFactory();
$params = ['name' => 'value'];
$r = $factory->createUploadedFile(
    $resource,
    1,
    \UPLOAD_ERR_OK,
    'filename.txt',
    'txt'
);

UriFactory

<?php

require 'vendor/autoload.php';

use Bulldog\HttpFactory\FactoryBuilder;
$httpFactory = FactoryBuilder::get('zend');
$factory = $httpFactory->uriFactory();
$r = $factory->createUri('/');

Links

统计信息

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

GitHub 信息

  • Stars: 2
  • Watchers: 3
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-08-01

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固