balpom/downloader 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

balpom/downloader

最新稳定版本:v0.8.0

Composer 安装命令:

composer require balpom/downloader

包简介

Downloads the contents of the specified URI through a simple interface.

README 文档

README

Simple interface for content downloading on the specified URI and it's trivial realisation.

This downloader will be useful for websites parsing, working with the REST API and other work with WEB resources via the HTTP protocol. This version of the package contains an interface implementation based on PSR-18. It is planned to make an implementation that works through Selenium WebDriver.

Requirements

  • PHP >= 8.0.3

Installation

Using composer (recommended)

composer require balpom/downloader

Usage sample

This downloader requires objects that implement the ResponseFactoryInterface, StreamFactoryInterface and UriFactoryInterface interfaces which defined in the PSR-17 specification. An excellent library that implements all these interfaces at once (all-in-one) is Nyholm/psr7 - will use it.

This downloader also requires an HTTP client that implements the ClientInterface which defined in the PSR-18 specification. For example, will use phpwebclient/webclient.

Installing third-party packages

composer require nyholm/psr7
composer require webclient/webclient

Downloader creation

$factory = new \Nyholm\Psr7\Factory\Psr17Factory();
$client = new \Webclient\Http\Webclient($factory, $factory);
// Psr18Factories(RequestFactoryInterface $request, StreamFactoryInterface $stream, UriFactoryInterface $uri)
$factory = new \Balpom\Downloader\Factory\Psr18Factories($factory, $factory, $factory);
$downloader = new \Balpom\Downloader\Psr18Downloader($client, $factory);

Download URI

For test purpose will make request to site https://ipmy.ru.

$downloader = $downloader->get('http://ipmy.ru/ip');
echo $downloader->code(); echo PHP_EOL; // Must be 200.
echo $downloader->content(); echo PHP_EOL; // Must be your IP.

Extended sample you may find in "tests/psr18test.php" file - just run it:

php tests/psr18test.php

License

MIT License See LICENSE.MD

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-04-13