somecoding / wp-api-wrapper
这是一个为大多数WordPress博客提供的API的包装器。旨在方便地爬取WordPress页面。
0.0.3
2019-02-19 09:25 UTC
Requires
- php: ^7.2
- ext-json: ^1
- guzzlehttp/guzzle: ^6.3
- psr/http-client: ^1.0
- psr/http-message: ^1.0
- psr/simple-cache: ^1.0
- zendframework/zend-config: ^3.2
- zendframework/zend-hydrator: ^3.0
- zendframework/zend-servicemanager: ^3.4
Requires (Dev)
- phpunit/phpunit: >=7.0
- squizlabs/php_codesniffer: ^3.0
Suggests
- ext-redis: For caching
- predis/predis: ^1.1
- symfony/cache: ^4.2
This package is auto-updated.
Last update: 2024-09-26 17:51:58 UTC
README
WordPress API包装器
这是一个为大多数WordPress博客提供的API的包装器。旨在方便地爬取WordPress页面。
如何安装
由于该项目目前不稳定,您需要指定此项目的版本进行安装。
简单操作:在您的项目中执行 "composer require somecoding/wp-api-wrapper:0.0.x",其中 x 是最新版本号。
默认可用服务
一些默认服务可用于包装WordPress API数据的常见情况
- 用户(UserService)
- 分类(CategoriesService)
- 媒体(MediaService)
- 文章(PostService)
- 搜索(SearchService)
这些服务需要创建一个API服务。此API服务需要使用GuzzleHTTP客户端、WordPress站点的Base URL、Hydrator接口以及可选的PSR简单缓存接口进行初始化。
<?php namespace Somecoding\WordpressApiWrapper; use GuzzleHttp\Client; use Somecoding\WordpressApiWrapper\Model\Post; use Somecoding\WordpressApiWrapper\Service\ApiService; use Somecoding\WordpressApiWrapper\Service\Main\PostService; use Symfony\Component\Cache\Simple\RedisCache; use Zend\Config\Config; use Zend\Hydrator\ClassMethodsHydrator; require_once __DIR__. '/../vendor/autoload.php'; $redis = new \Redis(); $config = new Config(require_once __DIR__ . '/../config/wordpressApiWrapper.global.php'); $wpApiWrapperConfig = $config->wordpressApiWrapper; $cacheInterface = new RedisCache($redis); $guzzleClient = new Client(); $hydrator = new ClassMethodsHydrator(); $api = new ApiService($guzzleClient, $hydrator, $wpApiWrapperConfig, 'https://example.com', $cacheInterface); $categoriesService = new CategoriesService($api); $mediaService = new MediaService($api); $pageService = new PageService($api); $postService = new PostService($api); $searchService = new SearchService($api); $userService = new UserService($api); $availableRoutes = $api->getAllRoutes();