netglue / prismic-client
PHP API Client for Prismic.io
Installs: 94 009
Dependents: 2
Suggesters: 0
Security: 0
Stars: 7
Watchers: 5
Forks: 1
Open Issues: 5
Requires
- php: ~8.1 || ~8.2 || ~8.3 || ~8.4
- ext-json: *
- laminas/laminas-escaper: ^2.9
- php-http/discovery: ^1.18.0
- psr/cache: ^1.0.0 || ^2.0.0 || ^3.0.0
- psr/http-client: ^1.0
- psr/http-client-implementation: *
- psr/http-factory: ^1.0
- psr/http-message: ^1.0 || ^2.0
Requires (Dev)
- ext-curl: *
- doctrine/coding-standard: ^12.0
- laminas/laminas-diactoros: ^3.5.0
- php-http/cache-plugin: ^2.0.1
- php-http/curl-client: ^2.3.3
- php-http/mock-client: ^1.6.1
- phpunit/phpunit: ^10.5.38
- psalm/plugin-phpunit: ^0.19.0
- roave/security-advisories: dev-latest
- symfony/cache: ^6.4.13 || ^7.0
- vimeo/psalm: ^5.26.1
Conflicts
- php-http/httplug: <2.4.1
- php-http/promise: <1.3.1
- 2.0.x-dev
- 1.13.x-dev
- 1.12.x-dev
- 1.12.0
- 1.11.x-dev
- 1.11.0
- 1.10.x-dev
- 1.10.0
- 1.9.x-dev
- 1.9.0
- 1.8.x-dev
- 1.8.1
- 1.8.0
- 1.7.x-dev
- 1.7.0
- 1.6.x-dev
- 1.6.0
- 1.5.x-dev
- 1.5.0
- 1.4.x-dev
- 1.4.0
- 1.3.x-dev
- 1.3.0
- 1.2.x-dev
- 1.2.5
- 1.2.4
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.x-dev
- 1.1.1
- 1.1.0
- 1.1.0-RC1
- 1.0.0
- 0.8.0
- 0.7.0
- 0.6.1
- 0.6.0
- 0.5.0
- 0.4.4
- 0.4.3
- 0.4.2
- 0.4.1
- 0.4.0
- 0.3.7
- 0.3.6
- 0.3.5
- 0.3.4
- 0.3.3
- 0.3.2
- 0.3.1
- 0.3.0
- 0.2.0
- 0.1.0
- 0.1.0-beta
- dev-renovate/lock-file-maintenance
- dev-merge-1.12.0-into-next-major
- dev-renovate/codecov-codecov-action-5.x
- dev-bookmarks-and-collections-removal
- dev-renovate/phpunit-phpunit-11.x
This package is auto-updated.
Last update: 2024-12-14 01:16:08 UTC
README
This is an unofficial PHP client for the Prismic.io headless CMS. In order to keep things simple, this library only supports version 2 of the api, so you'll have to make sure to specify your repository url in the format https://my-repo.prismic.io/api/v2
There is practically zero backwards compatibility with other prismic clients so this is in no way a drop-in replacement. That said, you should find that much of it remains similar.
Features
- Uses a PSR-18 HTTP client for communicating with the API, so there is no dependency on a particular client implementation. The library depends on you either manually providing an HTTP client or falls back on HTTPlug Discovery to figure out an already available client.
- Optional caching. You can choose to cache using an HTTP client that can cache responses for you like this little beauty, or provide a PSR cache pool to the named constructor.
- Helpful methods in the primary interface to retrieve next/previous paginated result sets or merge all paginated results to a single result set.
- Predictable and consistent exceptions to help you recover gracefully from error conditions.
- Iterable and filterable collections to represent Slices, groups and RichText making it trivial to locate particular types of content.
- Completely separate and replaceable HTML serialisation. In fact, the content objects do not have
atHtml()
orasText()
methods at all. There is a shipped HTML serializer which is invokable, but you might not want to use it all, instead preferring to work with your documents in your view layer directly. - Easily implement your own result set and your own document types, replacing the default shipped implementations. Got a 'Case Study' type? Hydrate your documents to
YourModel\CaseStudy
objects so that you can build a robust content model to use in your views and elsewhere. - Much less nullability… All collections guarantee a return type of
Prismic\Fragment
which you can more easily test for a specific type or for its emptiness.
Limitations
- Only supports V2 of the api as previously mentioned
- No support for experiments (A/B Tests) because this feature is out-of-order at Prismic itself, it didn't make sense to implement a feature that can't be used (Sad face) - that said, if A/B tests ever become a reality again in the future, it'll be top of the pile.
- No caching out-of-the-box (Also see "Features")
Installation
Install with composer: composer require netglue/prismic-client
You will also require a PSR-18 HTTP client implementation, of which there are many, for example:
To use the curl adapter from php-http
, issue a composer require php-http/curl-client
Documentation
Docs are a work in progress and are hosted in a public prismic repository (obviously!)
You can view the docs by cloning the library, cd to the source and issue a composer install
followed by a composer serve
. This will start up PHP's built-in server on http://127.0.0.1:8080 showing the docs.
Samples & Examples
Take a look around in the ./samples
directory; that's where you’ll find the document explorer used for rendering the documentation and examples for setting up hydrating result sets, link resolver implementations and other stuff.
It's worth mentioning that the document explorer also supports previews meaning you can add http://127.0.0.1/preview
as a preview target in your Prismic repository and preview live changes.
Tests
Once you have the library cloned and dependencies installed, you can run the unit tests. Smoke tests will be skipped by default, but you can run them against your own content repositories by either writing a configuration file in test/config/config.php
(You'll find an example in there too) or by setting a couple of environment variables in order to run smoke tests against a single repo:
export PRISMIC_REPO="https://my-repo.prismic.io/api/v2" export PRISMIC_TOKEN="Some access token or not" vendor/bin/phpunit
Other Clients
The official kit can be found at prismicio/php-kit.
Another, abandoned fork of the official kit can be found at netglue/prismic-php-kit. The reason for abandoning the fork there was the desire to start from a clean slate and make use of the recent PSRs for HTTP factories and clients, completely separate the HTML serialisation process from the content model and provide more flexible ways of hydrating your content model to objects in your domain (Or not as the case may be!).