webhappens/prismic
Composer 安装命令:
composer require webhappens/prismic
包简介
A Laravel package for using Prismic.io
关键字:
README 文档
README
A Laravel wrapper for Prismic.io
This package makes it super quick and easy to work with Prismic.io in Laravel.
- Object-oriented design
- Eloquent-style query interface
- Auto-magically render Slices and Fields as HTML
- Automatic link resolution
- Nested Document support
- Out-the-box caching and preview sessions
- Super-charged web hooks (Coming soon)
Documents
Each Custom Type within Prismic should have a corresponding Document model in your project. Document models make it easy for you to query your Prismic repository and organise your code around your content models.
Defining Document Models
To get started, let's create a Document model. All Document models extend the WebHappens\Prismic\Document class.
The most basic and fundamental property of a Document model is its type property. This property indicates which Prismic Custom Type the Document model corresponds to:
<?php namespace App; use WebHappens\Prismic\Document; class Article extends Document { /** * The 'API ID' of the Custom Type associated with the document model. * * @var string */ protected static $type = 'article'; }
Registering Document Models
Before Document models are available they must be registered in a Service Provider using the Prismic::documents() method. Typically this would happen in the register method of your App\Providers\AppServiceProvider class.
use App\Article; use WebHappens\Prismic\Prismic; public function register() { Prismic::documents([ Article::class, ]); }
Retrieving Documets
Once you have created a Document model and its associated content in Prismic, you are ready to start retrieving data from your repository.
All Documents
You may retrieve all Documents for a specific type using the all method. They will be returned inside a Laravel Collection object:
// Retrieve all Article Documents $articles = Article::all();
Chunking Results
If you need to process a lot of Documents, use the chunk command. The chunk method will retrieve a "chunk" of Document models, feeding them to a given Closure for processing. This will conserve memory when working with large result sets:
// Process each Article in chunks of 100 Article::chunk(100, function ($articles) { foreach ($articles as $article) { // } });
Please note that the largest chunk size is 100 due to a limit on the Prismic API.
Single Documents
In addition to retrieving all Documents for a given type, you may also retrieve single records by passing the Document ID into the find method. Instead of returning a Laravel Collection, this method returns a single Document instance:
// Retrive the Article with an ID of WAjgAygABN3B0a-a $article = Article::find('WAjgAygABN3B0a-a');
Single Type Documents
If you have created a Single Type Document, a Homepage, for example, you may use the single method to retrieve the Document model instance, without having to pass a Document ID:
// Retrieve a Single Type Document $homepage = Homepage::single();
webhappens/prismic 适用场景与选型建议
webhappens/prismic 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.43k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2020 年 03 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Prismic」 「webhappens」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 webhappens/prismic 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 webhappens/prismic 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 webhappens/prismic 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP API Client for Prismic.io
Mezzio integration for Prismic. Let’s call it ”Primo“…
CLI tooling for developing Prismic content models
Easily traverse nested object structures without worrying about recursion.
Add a simple fluid interface for getters, setters, accessors and mutators to any PHP class.
Make method calls conditional by simply appending If or Unless when you call them.
统计信息
- 总下载量: 1.43k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-03-18