chrispecoraro/php-sanity
Composer 安装命令:
composer require chrispecoraro/php-sanity
包简介
A collection of utilities for use with Sanity.io
README 文档
README
PHP Sanity is a PHP class providing convience utility functions for performing mutations to https://Sanity.io schemas. This requires the sanity-php client. https://github.com/sanity-io/sanity-php
Usage:
// instantiation:
$sanity = new Sanity('1a2b3c4d', 'production', 'skY70CML0Ovm3GfPqQKeLtBNnS....', '2019-01-29');`
create() is useful for creating a single record from an array or object:
$arr = ['Tim', 'Jones']; $sanity->create("employee", $arr, ["firstName","lastName"]);
create() also works with an object:
$sanity->create("employee", (object)$arr,["firstName","lastName"]);
createFromString() creates a single document given a delimited string.
$sanity->createFromString("employee",'Ralph|Peters',["firstName","lastName"],'|');
batchCreate() is useful for importing from an array of arrays or objects
$docs = [ ['Bob', 'Jones'], ['Ron', 'Philips'] ]; $sanity->batchCreate("employee", $docs, ["firstName","lastName"]); $sanity->batchCreate("employee", (object)$docs, ["firstName","lastName"]);
batchCreateFromFile() is useful for importing from a delimited file
// example file: // records.csv: // Bob|Jones // Ron|Philips $sanity->batchCreateFromFile("employee", "./records.csv", ["firstName","lastName"], "|");
copy() copies the document source field to the target field's value.
// This is useful for back filling fields
$sanity->copy('employee','telephone','cellular');
attach() attaches (using a reference) a document (via id) to a document.
$sanity->attach(fieldName: 'group', relatedFieldId: '1991fe09-b54c-4e35-9d32-15413863c3b6', documentId: 'fb5b618b-47e4-40c7-964b-2e479cb33');
attachImage() works with the Document ID as a parameter
$sanity->attachImage('/home/bob/Documents/Bob-Photo.jpeg', documentId: 'fb5b618b-47e4-40c7-964b-2e479cb33');
attachImage() also works with a documentId set as a class property
$sanity->setDocumentId("fb5b618b-47e4-40c7-964b-29cb33c4"); $sanity->attachImage("/home/bob/Documents/avatar.jpg");
attachImage() also works with an image URL
$sanity->setDocumentId("fb5b618b-47e4-40c7-964b-279cb33c4"); $sanity->attachImage("https://picsum.photos/400/300");
all() is a shortcut equivalent a fetch using GROQ
//$results = $sanity->fetch('*[_type=="menuItem"]');
$results = $sanity->all("employee");
set() sets a single field in a document to a given value.
$sanity->set("lastName","Jones","fb5b618b-47e4-40c7-964b-2e479cb3c4");
deleteAll() deletes ALL documents of a given schema type.
IMPORTANT: be careful and make a back up (export the dataset first).
$sanity->deleteAll('employee');
deleteById() deletes a single documents given its id.
IMPORTANT: be careful and make a back up (export the dataset first).
$sanity->deleteById('fb5b618b-47e4-40c7-964b-2e479cb33c');
统计信息
- 总下载量: 159
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2022-12-30