kozakevic / strapi-wrapper
Strapi 无头 CMS 的包装器
2.0.1
2024-02-12 21:40 UTC
Requires
- php: >=8.1
- guzzlehttp/guzzle: ^7.5
Requires (Dev)
- phpunit/phpunit: ^9
- symfony/var-dumper: ^6.1
Suggests
- guzzlehttp/guzzle: use it as HTTP client
README
⚙️ 安装
composer require kazakevic/strapi-wrapper
⚙️ 使用
- 设置客户端
- 您可以使用实现
Psr\Http\Client\ClientInterface
的任何 HTTP 客户端
- 您可以使用实现
$httpClient = new Client(); //Guzzle http client, but can be any suitable $strapiClient = new StrapiClient( $httpClient, 'token', 'https://:1338' );
- getItems
$response = $strapiClient->getItems( 'item-identifier', new PageFilter(100), new SortFilter('id', SortOrder::DESC) );
- getItemById
$jsonData = $strapiClient->getItemById('seo-pages', 534546)
- getItemsBy
$response = $strapiClient->getItemsBy( 'item-identifier', 'fieldName', 'fieldValue', new PageFilter(100), new SortFilter('id', SortOrder::DESC) );
- createItem
$jsonData = $strapiClient->createItem('topics', [ 'data' => [ 'Title' => 'Test Title', 'Slug' => 'test-slug', 'seoTitle' => 'test title', 'seoDescription' => 'test description', 'tags' => [1, 2, 2], 'videoCount' => 10 ] ]);
- updateItem
$jsonData = $strapiClient->updateItem('topics', 1, [ 'data' => [ 'Title' => 'Test Title', 'Slug' => 'test-slug', 'seoTitle' => 'test title', 'seoDescription' => 'test description', 'tags' => [1, 2, 2], 'videoCount' => 10 ] ]);
⚙️ 测试
./vendor/bin/phpunit tests