moddix/serpapi
最新稳定版本:1.0.0
Composer 安装命令:
composer require moddix/serpapi
包简介
SerpApi PHP client library
README 文档
README
A flexible PHP client for interacting with the SerpApi search API. Supports Google and Bing search engines, with extensible options and robust error handling.
Requirements
- PHP 8.2 or higher
- PSR-18 compatible HTTP client (e.g., Symfony HttpClient)
- PSR-17 compatible request factory (e.g., Nyholm/psr7)
Features
- Easy integration with SerpApi for Google and Bing search
- Strongly-typed search options (DTOs) for each engine
- Extensible architecture for adding new search engines
- Comprehensive exception handling (API, network, validation, server errors)
- PSR-18 HTTP client and PSR-17 request factory support
Installation
Install via Composer:
composer require moddix/serpapi
Usage Example
use Moddix\SerpApi\GoogleSearchClient; use Moddix\SerpApi\Dto\GoogleSearchOptions; use Moddix\SerpApi\Dto\SerpApiOptions; use Nyholm\Psr7\Factory\Psr17Factory; use Symfony\Component\HttpClient\Psr18Client; $apiKey = 'your_serpapi_key'; $httpClient = new Psr18Client(); $requestFactory = new Psr17Factory(); $googleOptions = new GoogleSearchOptions(gl: 'us', hl: 'en'); $serpApiOptions = new SerpApiOptions(no_cache: true); $client = new GoogleSearchClient( $apiKey, $httpClient, $requestFactory, $googleOptions, $serpApiOptions ); try { $results = $client->search('pizza'); print_r($results); } catch (\Moddix\SerpApi\Exception\ApiException $e) { // Handle API error } catch (\Moddix\SerpApi\Exception\NetworkException $e) { // Handle network error }
Project Structure
src/— Main source codeDto/— Data Transfer Objects for search optionsEnum/— Enumerations for search parametersException/— Custom exception classes
tests/— PHPUnit tests
Running Tests
Run all tests using PHPUnit:
./vendor/bin/phpunit tests
License
MIT License.
统计信息
- 总下载量: 26
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-12