PHP code example of bestit / contentful-bundle

1. Go to this page and download the library: Download bestit/contentful-bundle 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/ */

    

bestit / contentful-bundle example snippets



// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new BestIt\ContentfulBundle\BestItContentfulBundle(),
        );

        // ...
    }

    // ...
}



/** @var \BestIt\ContentfulBundle\Service\Delivery\ClientDecorator $clientDecorator */
$clientDecorator = $this->getClient();

$contentType = 'example-type';
$limit = 5;
$where = ['fields.example-slug' => 'example-com'];

if (is_scalar($where)) {
    $entry = $clientDecorator->getEntry($id = $where);
} else {
    $entries = $clientDecorator->getEntries(
        function (\Contentful\Delivery\Query $query) use ($contentType, $limit, $where) {
            $query->setContentType($contentType);

            if ($limit) {
                $query->setLimit($limit);
            }

            array_walk($where, function ($value, $key) use ($query) {
                $query->where($key, $value);
            });

            return $query;
        },
        $cacheId = sha1(__METHOD__ . ':' . $contentType . ':' . serialize($where))
    );
}