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');
chrispecoraro/php-sanity 适用场景与选型建议
chrispecoraro/php-sanity 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 159 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 12 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 chrispecoraro/php-sanity 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 chrispecoraro/php-sanity 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 159
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2022-12-30