承接 gioppy/statamic-rest-client 相关项目开发

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

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

gioppy/statamic-rest-client

最新稳定版本:v1.1.1

Composer 安装命令:

composer require gioppy/statamic-rest-client

包简介

A simple PHP client for Statamic REST Api

README 文档

README

This package provide a simple client for Statamic REST API.

It was created primarily for use on SSG php systems, such as Jigsaw, but can be used in any context.

Installation

composer require gioppy/statamic-rest-client

The package needs at least php 8.1, and depend on guzzlehttp/guzzle and illuminate/collections.

How to use

After installed, you can create new client with a classic new operator

new StatamicRestClient(...)

or with a static method

StatamicRestClient::make(...)

You can pass two values: the host of your Statamic installation (e.g: https://www.my-statmic.com) and optionally the API endpoint path (default is api but you can customize on Statamic API config).

Filters

You can filter the api using ->where() method in two possible ways. You can filter single value

StatamicRestClient::make(...)
  ->where('featured', true)

or using a condition

StatamicRestClient::make(...)
  ->where('title', 'awesome', 'contains')

Sorting

You can sort the response using ->sort() method, passing an array of fields:

StatamicRestClient::make(...)
  ->sort(['one', '-two', 'three'])

Selecting fields

You can specify what fields should be included on response using ->fields() method, passing an array of fields:

StatamicRestClient::make(...)
  ->fields(['id', 'title', 'content'])

Pagination

You can paginate the response using ->paginate() method, passing the number of items you want and, optionally, the number of page:

StatamicRestClient::make(...)
  ->paginate(5, 2)

Entries / Entry

Get all entries of collection:

StatamicRestClient::make(...)
  ->entries('collection')

Get an entry from a collection:

StatamicRestClient::make(...)
  ->entry('collection', 'id')

Collection Tree

TODO

Navigation Tree

StatamicRestClient::make(...)
  ->navigation('navigation_name')

Taxonomy Terms / Taxonomy Term

Get all terms of taxonomy:

StatamicRestClient::make(...)
  ->terms('taxonomy_name')

Get a single term from taxonomy:

StatamicRestClient::make(...)
  ->term('taxonomy_name', 'taxonomy_slug')

Globals / Global

Get all globals:

StatamicRestClient::make(...)
  ->globals()

Get single global:

StatamicRestClient::make(...)
  ->global('handle')

Assets / Asset

Get all assets of one container:

StatamicRestClient::make(...)
  ->assets('container')

Get single asset:

StatamicRestClient::make(...)
  ->asset('container', 'path')

Get single asset by its id:

StatamicRestClient::make(...)
  ->assetById('id')

The id of an asset is formatted by Statamic as container::path.

Getting response

You can get all response as array, including links and other nodes with ->all() method

StatamicRestClient::make(...)
  ->entries('collection')
  ->all()

or you can get only data node with ->data() method

StatamicRestClient::make(...)
  ->entries('collection')
  ->data()

If you need to have data as collection you can us ->toCollection() method

StatamicRestClient::make(...)
  ->entries('collection')
  ->toCollection()

Integration with Statamic Glide Rest

Statami Glide Rest is a small addon for Statamic that expose glide manipulation presets on a REST API endpoint. You can get an asset response with a glide presets with the class StatamicGlideRest:

StatamicGlideRest::make($host)
  ->presets(['small', 'medium'])
  ->glide('container::path')
  ->data()

TODO

  • Entries
  • Entry
  • Collection Tree
  • Navigation Tree
  • Taxonomy Terms
  • Taxonomy Term
  • Assets
  • Asset
  • Globals
  • Global
  • Test
  • Integration with Statamic Glide Rest
  • Laravel integration

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-11-20