Download the PHP package digiaonline/lumen-contentful-sync without Composer
On this page you can find all versions of the php package digiaonline/lumen-contentful-sync. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download digiaonline/lumen-contentful-sync
More information about digiaonline/lumen-contentful-sync
Files in digiaonline/lumen-contentful-sync
Package lumen-contentful-sync
Short Description A framework for synchronizing content from Contentful to a Lumen API
License MIT
Informations about the package lumen-contentful-sync
lumen-contentful-sync
Introduction
This library provides a powerful abstraction on top of digiaonline/lumen-contentful with the goal of making it easier to synchronize content from Contentful to your application.
Features
- console commands for synchronizing entries and assets
- a controller for handling webhooks
- a middleware for transparently authenticating webhook requests
- a middleware for proper New Relic transaction name instrumentation for webhook requests
- asynchronous processing support by using jobs
Requirements
- PHP >= 7.1
Installation
-
Start by adding the library as a dependency to your application:
-
Copy
config/contentfulSync.php
to your configuration directory. There is only one mandatory configuration key -content_types
. This array should contain a list of all the content model IDs you have in your Contentful space, e.g.: -
Extend
Digia\Lumen\ContentfulSync\Services\AbstractContentfulSyncService
and implement the necessary methods. This is where the logic for how to handle entries and assets will live. See the next section for more details. -
Extend
Digia\Lumen\ContentfulSync\Providers\AbstractContentfulSyncServiceProvider
and implement theregisterContentfulSyncServiceBindings
method. A typical implementation would look like this: -
Register the service provider you just implemented:
-
Register the console commands in your kernel:
-
If you intend to use webhooks you will have to configure a route to the controller. In this example we will use both the New Relic and the webhook authentication middlewares, but both are optional:
- If you use the webhook authentication middleware you can configure the username and password to expect by adding
these to your
.env
file:
If you need more complicated logic you will have to create your own middleware.
Implementing the service
Since all applications are different it is up to you to define how to handle your entries and assets.
The unimplemented methods give you the asset/entry in question as JSON. You will most likely want to use the SDK to convert these blobs to actual objects:
Usage
Console commands
To synchronize all assets and all configured content types, run the following two commands:
To synchronize all entries for a specific content type (article
in this case), run:
To synchronize new entries only, run:
You can add -v
or -vv
or -vvv
to both commands to get more detailed output and a progress bar, e.g.:
New Relic middleware
If you use New Relic to monitor your application you will probably notice that all Contentful webhooks are lumped together as a single transacation (since they all use the same URL/route).
However, if you apply the
Digia\Lumen\ContentfulSync\Http\Middleware\NewRelicMiddleware
middleware to your route, transactions will be named
topic@contentType
, e.g. ContentManagement.Entry.publish@article
. This allows you to single in on particularly slow
webhooks.
Asynchronous processing
In your service provider implementation you can specify an instance of Illuminate\Contracts\Queue\Queue
to inject
into the service. Unless you've configured a different queue specifically your application will be using the
SyncQueue
implementation to simulate a completely synchronous queue.
By specifying a different queue instance you can offload all the work the service does to queue workers.
License
MIT
All versions of lumen-contentful-sync with dependencies
jalle19/laravel-lost-interfaces Version ^1.2
laravel/lumen-framework Version ^5.4|^6.0
nordsoftware/lumen-contentful Version ^4.2
nordsoftware/lumen-newrelic Version ^2.0
digiaonline/json-helpers Version ^1.0