定制 hiddeco/laravel-http-adapter 二次开发

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

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

hiddeco/laravel-http-adapter

最新稳定版本:v0.1

Composer 安装命令:

composer require hiddeco/laravel-http-adapter

包简介

Issue HTTP requests through the most popular HTTP clients with Laravel. Build upon the Ivory HTTP Adapter.

README 文档

README

Build Status Scrutinizer Code Quality MIT license StyleCI SensioLabsInsight

Laravel HTTP Adapter is officialy deprecated. Use phphttp/laravel based upon httplug instead.

Laravel HTTP Adapter is an Ivory HTTP Adapter bridge, which integrates the ability of using multiple adapters with their own configuration through one API.

Installation

To use this package without running into trouble you will need PHP 5.5+ or HHVM 3.6+, and Composer.

  1. Get the latest version of Laravel HTTP Adapter, add the following line to your composer.json file "hiddeco/laravel-http-adapter": "0.1"

    The package supports the following adapters, you will need to install the ones you want to use.

    • "ext-curl": "*"
    • "ext-http": "*"
    • "guzzle/guzzle": "^3.9.4@dev"
    • "guzzlehttp/guzzle": "^4.1.4|^5.0"
    • "kriswallsmith/buzz": "^0.13"
    • "nategood/httpful": "^0.2.17"
    • "zendframework/zendframework1": "^1.12.9"
    • "zendframework/zend-http": "^2.3.4"
  2. Run composer update or composer install

  3. Register the Laravel HTTP Adapter service provider in config/app.php by adding 'HiddeCo\HttpAdapter\HttpAdapterServiceProvider' to the providers key

  4. Add the HttpAdapter facade to the aliases key: 'HttpAdapter' => 'HiddeCo\HttpAdapter\Facades\HttpAdapter'

Configuration

To manage your HTTP adapters run the php artisan vendor:publish command, this will create the config/httpadapter.php file where you can modify and manage your adapter connections.

The following configuration options are available:

Global Configuration

The Global Configuration (global) overrules all the other configurations set for your HTTP adapters. It accepts the same parameters as an HTTP adapter connection does.

Default Connection Name

The adapter connection name set here (default) is the default connection used for all requests. However, you may use as many connections as you need using the manager class. The default setting is 'main'.

HTTP Adapter Connections

This is the place to configure your HTTP adapter connections (connections). A default configuration with possible options is already present and there is no limit to the amount of connections.

The following adapters are available: buzz, cake, curl, file_get_contents, fopen, guzzle, guzzle_http, httpful, react, socket, zend1 and zend2.

Usage

HTTP Adapter Manager

The HttpAdapterManager is where the magic happens. Bounded to the ioc container as httpadapter and accessible by using the Facade\HttpAdapter facade. It uses parts of the Laravel Manager package to manage the HTTP adapter connections. For more information about the Manager you should check out the respective docs.

It is worth noting the connection returned will always be an instance of \Ivory\HttpAdapter\HttpAdapterInterface. You can find more information about this instance and its methods in the Ivory HTTP Adapter docs.

HTTP Adapter Facade

The HTTP Adapter facade will pass static method calls to the httpadapter object in the ioc container, which as stated before is the HttpAdapterManager class.

Examples

The usage of this package is fairly simple. The main connection is preconfigured and uses the file_get_contents HTTP adapter, no other configuration options are set for this connection by default.

Using the Facade

use HiddeCo\HttpAdapter\Facades\HttpAdapter;

$request = HttpAdapter::get('http://awesome.com');
$body = $request->getBody();
// and you're done

Using the HTTP Adapter Manager

The HTTPAdapterManager returns an instance of \Ivory\HttpAdapter\HttpAdapterInterface and will behave like it. If you want to call a specific connection, you can use the connection method:

use HiddeCo\HttpAdapter\Facades\HttpAdapter;

$request = HttpAdapter::connection('alternative')->get('http://awesome.com');

Changing the default connection and further explanations:

use HiddeCo\HttpAdapter\Facades\HttpAdapter;

HttpAdapter::connection('main')->get('http://awesome.com');
HttpAdapter::get('http://awesome.com');
HttpAdapter::connection()->get('http://awesome.com');
// are all the same because 

HttpAdapter::getDefaultConnection();
// returns 'main' as set in the configuration file

HttpAdapter::setDefaultConnection('alternative');
// the 'alternative' connection is now the default connection

Dependency Injection

Prefer the use of a dependency injection over facades? You can easily inject the manager:

use HiddeCo\HttpAdapter\HttpAdapterManager;

class Foo
{
	protected $httpadapter;
	
	public function __construct(HttpAdapterManager $httpadapter)
	{
		$this->httpadapter;
	}
	
	public function bar()
	{
		$this->httpadapter->get('http://awesome.com');
	}
}

Events

If you set the eventable key in the general or local HTTP adapter configuration to true the \Ivory\HttpAdapter\EventDispatcherHttpAdapter will be used to make your HTTP adapter connection. This way it's possible to listen to events that are dispatched using the Laravel dispatcher. All available events can be found in the Ivory HTTP docs.

use Ivory\HttpAdapter\Event\Events;
use Ivory\HttpAdapter\Event\PostSendEvent;

Event::listen(Events::POST_SEND, function (PostSendEvent $event) {
	Log::info("A request was made");
});

It is also possible to register the event listener using the EventServiceProvider.

License

Laravel HTTP Adapter is licensed under the MIT License (MIT).

hiddeco/laravel-http-adapter 适用场景与选型建议

hiddeco/laravel-http-adapter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 22 次下载、GitHub Stars 达 2, 最近一次更新时间为 2015 年 07 月 31 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「framework」 「http」 「adapter」 「laravel」 「ivory」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 hiddeco/laravel-http-adapter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 hiddeco/laravel-http-adapter 我们能提供哪些服务?
定制开发 / 二次开发

基于 hiddeco/laravel-http-adapter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-07-31