Download the PHP package netglue/expressive-prismic without Composer

On this page you can find all versions of the php package netglue/expressive-prismic. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package expressive-prismic

Zend Expressive / Prismic.io CMS Module

Build Status Test Coverage

Introduction

This module/library's purpose is to ease development of content driven websites using prismic.io's content API as a backend service.

If you haven't heard of Prismic before, you can find out about it here.

Requirements

This module is only suitable for Zend Expressive ^3.0 and PHP ^7.1

Furthermore, it uses a fork of the official Prismic.io php library which you can see here: netglue/prismic-php-kit. This fork is quite different to the official kit and I recommend looking through the docs/code to make yourself aware of the differences if you are already familiar with the official lib.

Install

Install with composer ala composer require netglue/expressive-prismic

This should also ask you if you want to inject the config provider too.

Tests

$ composer install
$ vendor/bin/phpunit

Basic Configuration

This library exposes the Prismic API instance in your container as Prismic\Api. At the very least, you'll need to configure your credentials thus:

Defining Routes

In order to allow you to specify properties of a document to look out for during routing, you must map the route parameter names you want to use to the prismic document/api equivalent. The defaults are:

So, assuming the above, to define a route to a bookmarked document, you would configure something like this:

Normally, to save yourself some effort, you'd have a template that's capable of rendering perhaps any page of a given type such as a 'case-study' type. Let's say you want the url /case-studies/{case-study-uid}, then you'd define a route like this (If you are using FastRoute):

Cache Busting Webhook

You will see in Factory\PipelineAndRoutesDelegator that two routes are wired in by default, one of these is the webhook to bust the cache. In order to use it, you should provide a shared secret that Prismic.io sends in it's webhook payload to a local configuration file or Config Provider like this:

You would also need to enter this secret into the relevant place in your Prismic repository settings.

By default the secret is null, which means that the secret will not be validated even if it's sent by Prismic. If you decide not to setup a secret, I strongly recommend that you configure an obscure URL otherwise anyone will be able to POST to your webhook endpoint and bust the cache on demand, slowing down your site.

By default the url of the webhook will be /prismicio-cache-webhook. You should change this to something sufficiently random in the following way:

If the webhook url is hit with a POST request and valid JSON payload, the pre-configured middleware will empty the cache attached to the Prismic API instance.

The webhook route points to a middleware pipe named ExpressivePrismic\Middleware\WebhookPipe so if you want to modify the pipeline to do other things, or replace it entirely, just alias that pipe to different factory or implement a delegator factory for the pipe.

Link Resolver

The Link Resolver is a concept introduced by Prismic to turn documents, or document link fragments into local urls and there's a concrete implementation in this package at ExpressivePrismic\LinkResolver.

Using the same setup for routing parameters, it tries to use the Expressive URL helper to generate local URLs. It's setup in the container as Prismic\LinkResolver as well as ExpressivePrismic\LinkResolver and throughout the package it's retrieved by the name of Prismic\LinkResolver so it's easy to replace with your own concrete implementation if you need one.

Previews

There's another route that's auto-wired like the cache busting webhook for initiating previews. All you have to do is add the URL in the settings on your Prismic repository and clicks on the preview button in the writing room will put the site in preview mode. You can see how this is configured in Factory\PipelineAndRoutesDelegator - the URL is /prismic-preview by default, but you can change the url by setting the following configuration value:

In 4.2.0, the middleware responsible for initiating a preview session was altered to catch an exception that is thrown when the preview token has expired and subsequently return a simple html response with a descriptive error. Previously, in this situation, an uncaught exception would have occurred.

View Helpers

URL Helper $this->prismicUrl()

This view helper will generate a local URL using the link resolver. It's __invoke() method accepts

Fragment Helper $this->fragment()

This view helper operates on the current resolved document and provides an easy way of rendering simple fragments to views. It does not require the fully qualified fragment name, ie. documentType.fragmentName and instead you can pass it just 'fragmentName'.

$this->fragment()->get('title'); will return the fragment object.

$this->fragment()->asText('title'); will return the text value of the fragment.

$this->fragment()->asHtml('title'); will return the HTML value of the fragment.

CMS Managed Error Pages for Production

Error handling is wired in by default… If you are using the Whoops error handler in development, you'll need to disable development mode composer development-disable to experience custom errors and 404's

404 Errors

In the event of a 404, by default, Expressive will execute the \Zend\Expressive\Handler\NotFoundHandler. This module provides a pipeline in \ExpressivePrismic\Middleware\NotFoundPipe that initialises previews and experiments, locates a bookmarked error document in the Prismic API and renders that document to a template.

To take advantage of pretty CMS managed 404's, first you will have to specify in your configuration the bookmark name for the error document in your repository and the template name to render like this:

Note that in development mode, 404's experienced after a route has matched, i.e. the Prismic Document can't be found, will cause a DocumentNotFound exception, thereby delegating to the Whoops error handler.

Exceptions

Presenting a pretty error page during errors and exceptions are handled in much the same way as 404's. Again, you'll need to configure a bookmark and a template name used to render the content.

The fallback (i.e. when the error document cannot be retrieved from the api) for exception situations is a simple plain text message stating that an error occurred. This fallback is not currently configurable to be anything more fancy than that.


All versions of expressive-prismic with dependencies

PHP Build Version
Package Version
Requires php Version >=7.3
ext-json Version *
dflydev/fig-cookies Version ^1.0|^2.0
laminas/laminas-diactoros Version ^1.7.1 || ^2.0
laminas/laminas-zendframework-bridge Version ^1.2
netglue/prismic-php-kit Version ^4.2
zendframework/zend-expressive Version ^3.0.1
zendframework/zend-expressive-helpers Version ^5.0
zendframework/zend-expressive-zendviewrenderer Version ^2.0
zendframework/zend-http Version ^2.8
zendframework/zend-paginator Version ^2.8
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package netglue/expressive-prismic contains the following files

Loading the files please wait ....