PHP code example of digiaonline / lumen-contentful-sync
1. Go to this page and download the library: Download digiaonline/lumen-contentful-sync library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
digiaonline / lumen-contentful-sync example snippets
protected function registerContentfulSyncServiceBindings(Application $app)
{
// ContentfulSyncService is the concrete implementation we made in step 3
$app->singleton(ContentfulSyncServiceContract::class, function (Application $app) {
return new ContentfulSyncService($app->make(Queue::class));
});
}
// The route URL is arbitrary, just make sure it matches what you have configured in Contentful
$app->post('/contentful/handleIncomingWebhook', [
'middleware' => [
\Digia\Lumen\ContentfulSync\Http\Middleware\WebhookAuthenticationMiddleware::class,
\Digia\Lumen\ContentfulSync\Http\Middleware\NewRelicMiddleware::class,
],
'uses' => 'Digia\Lumen\ContentfulSync\Http\Controllers\ContentfulSyncController@handleIncomingWebhook',
]);
/**
* @inheritdoc
*/
public function handleEntryPublished(string $contentType, string $entryJson, bool $ignoreExisting): void
{
// We're assuming here that you have injected an instance of ContentfulServiceContract
$entry = $this->contentfulService->getClient()->reviveJson($entryJson);
// You can now do e.g. $entry->getTitle(); etc. depending on your content model
}