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




return [
    'content_types' => [
        'article',
        'person',
        'video',
    ],
    // ...
];

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));
    });
}

$app->register(\Your\ServiceProvider::class);

protected $commands = [
    // ...
    SyncAssetsCommand::class,
    SyncContentsCommand::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
}
bash
php artisan contentful:assets:sync
php artisan contentful:contents:sync
bash
php artisan contentful:contents:sync article
bash
php artisan contentful:contents:sync article --ignoreExisting
bash
$ php artisan contentful:contents:sync article --ignoreExisting -vvv
Synchronizing content of type "article"...
 300/300 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100% 3 secs/3 secs 32.0 MiB

Done, synchronized 300 entries