承接 pronamic/wp-http 相关项目开发

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

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

pronamic/wp-http

最新稳定版本:v1.2.4

Composer 安装命令:

composer require pronamic/wp-http

包简介

WordPress HTTP library.

README 文档

README

WordPress HTTP library.

Usage

$response = Http::request( $url, $args );

$data = $response->json();

Testing

Faking Responses

$url = 'https://www.pronamic.nl/wp-json/wp/v2/types/post';

Http::fake( $url, __DIR__ . '/../http/pronamic-nl-wp-json-types-post.http' );

$response = \wp_remote_get( $url );

// or

$response = Http::get( $url );

PHPUnit

<?php

namespace YourNamespace;

use Pronamic\WordPress\Http\Factory;

class YourTest extends \WP_UnitTestCase {
	/**
	 * Setup.
	 */
	public function setUp() {
		parent::setUp();

		$this->factory = new Factory();
	}

	/**
	 * Test request.
	 */
	public function test_request() {
		$this->factory->fake( 'http://example.com/', __DIR__ . '/../http/example-com.http' );

		$result = \wp_remote_get( 'http://example.com/' );

		// asserts
	}
}

CR LF

To store fake HTTP responses in *.http files and Git, keep the following in mind:

HTTP/1.1 defines the sequence CR LF as the end-of-line marker for all protocol elements

https://tools.ietf.org/html/rfc2616#section-2.2

.gitattributes

*.http text eol=crlf

You can use a tool like unix2dos to convert the line endings to CR LF:

unix2dos *.http

If the line endings are not correct this can result in the following error:

Undefined offset: 2

wordpress/wp-includes/class-http.php:732
src/Factory.php:97
wordpress/wp-includes/class-wp-hook.php:292
wordpress/wp-includes/plugin.php:212
wordpress/wp-includes/class-http.php:257
wordpress/wp-includes/class-http.php:626
wordpress/wp-includes/http.php:162
src/Facades/Http.php:71

Inspiration

Pronamic - Work with us

统计信息

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

GitHub 信息

  • Stars: 6
  • Watchers: 4
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2021-03-09