Code Monkey home page Code Monkey logo

contentfulbundle's Introduction

ContentfulBundle

Packagist PHP from Packagist CircleCI Packagist

Symfony Bundle for the Contentful Delivery SDK. This bundle requires PHP 7.2 or higher or PHP 8.0 or higher, and Symfony 3.4 or higher. It also requires Twig to be installed.

Setup

Add this package to your application by using Composer and executing the following command:

composer require contentful/contentful-bundle

Add ContentfulBundle to your application

// config/bundles.php
return [
    // ...
    Contentful\ContentfulBundle\ContentfulBundle::class => ['dev' => true],
    // ...
];

Configuration example

The simplest configuration includes just the space ID and token. Add these settings to either app/config.yml (Symfony 3) or create config/packages/contentful.yaml (Symfony 4):

contentful:
    delivery:
        main:
            space: cfexampleapi
            token: b4c0n73n7fu1

You can also configure multiple clients and enable the preview mode:

contentful:
    delivery:
        main:
            default: true
            space: cfexampleapi
            token: b4c0n73n7fu1
        preview:
            space: cfexampleapi
            token: b4c0n73n7fu1
            api: preview

Documentation

Getting Started Tutorial

What is Contentful?

Contentful provides a content infrastructure for digital teams to power content in websites, apps, and devices. Unlike a CMS, Contentful was built to integrate with the modern software stack. It offers a central hub for structured content, powerful management and delivery APIs, and a customizable web app that enable developers and content creators to ship digital products faster.

License

Copyright (c) 2015-2023 Contentful GmbH. Code released under the MIT license. See LICENSE for further details.

contentfulbundle's People

Contributors

asuri0n avatar cf-allstar[bot] avatar dborsatto avatar fantus avatar ilukac avatar jjolton-contentful avatar kobelobster avatar kwivix avatar lenybernard avatar mariobodemann avatar matthew-contentful avatar mmenozzi avatar pgrigoruta avatar realityking avatar sebb767 avatar svenluijten avatar tomaszhanc avatar whitelisab avatar yadakhov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

contentfulbundle's Issues

Update recipe for V4

Hello,

I've upgraded contenful to v4 and I see that the recipe is still from contrib repository.

Could you "upgrade" it ? Or i have to do something on my side ?

WARNING contentful/contentful-bundle (>=4.0): From github.com/symfony/recipes-contrib:master The recipe for this package comes from the "contrib" repository, which is open to community contributions. Review the recipe at https://github.com/symfony/recipes-contrib/tree/master/contentful/contentful-bundle/4.0

Cannot install with Symfony 6.0.7 (issue with PHP8 and psr/cache 3)

Hello !

I've just tried to install the bundle on a fresh Symfony 6.0.7 install with PHP 8.0.18 (I had to downgrade from PHP 8.1.4 to PHP8.0.18) and it's not working.
Here is the error message on install :

➜  symfony-ux git:(feature/contentful-integration) ✗ composer require contentful/contentful-bundle
Info from https://repo.packagist.org: #StandWithUkraine
Using version ^7.1 for contentful/contentful-bundle
./composer.json has been updated
Running composer update contentful/contentful-bundle
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - cache/void-adapter 1.0.0 requires php ^5.6 || ^7.0 -> your php version (8.0.18) does not satisfy that requirement.
    - cache/void-adapter 1.1.0 requires psr/cache ^1.0 -> found psr/cache[1.0.0, 1.0.1] but the package is fixed to 3.0.0 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
    - contentful/contentful[6.1.0, ..., 6.2.0] require psr/cache ^1.0 -> found psr/cache[1.0.0, 1.0.1] but the package is fixed to 3.0.0 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
    - cache/void-adapter 1.2.0 requires psr/cache ^1.0 || ^2.0 -> found psr/cache[1.0.0, 1.0.1, 2.0.0] but the package is fixed to 3.0.0 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
    - contentful/contentful[6.0.0, ..., 6.0.5] require php ^7.2 -> your php version (8.0.18) does not satisfy that requirement.
    - contentful/contentful 6.4.0 requires psr/cache ^1.0|^2.0 -> found psr/cache[1.0.0, 1.0.1, 2.0.0] but the package is fixed to 3.0.0 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
    - contentful/contentful-bundle 7.1.0 requires contentful/contentful ^6.0 -> satisfiable by contentful/contentful[6.0.0, ..., 6.4.0].
    - contentful/contentful 6.3.0 requires cache/void-adapter ^1.0 -> satisfiable by cache/void-adapter[1.0.0, 1.1.0, 1.2.0].
    - Root composer.json requires contentful/contentful-bundle ^7.1 -> satisfiable by contentful/contentful-bundle[7.1.0].

Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.
You can also try re-running composer require with an explicit version constraint, e.g. "composer require contentful/contentful-bundle:*" to figure out if any version is installable, or "composer require contentful/contentful-bundle:^2.1" if you know which you need.

Installation failed, reverting ./composer.json and ./composer.lock to their original content.

Is it an error that you have on your side ? I saw that PHP8 support was updated (#52) ... but I can't make it work.
Thanks for your help.

Best regards.

Caching requests?

Is there a preferred way to setup caching of requests with Contentful and Symfony, so that one won't hit the API usage limit so quickly?

Null fields on cached entries

Hi.

I am trying to cache all of my contents so I enabled both the runtime and content option first request has no problems all of the contents are generated by my factories.

The problem is the second request, I am caching entry ID(s) which I called before but when I tried to retrieve with $contentful->getEntry($id) all of the fields are null! But I guess the entry must exist with its own fields in the Contentful`s own cache pool am I wrong?

This problem occurs when I enabled both of the cache and runtime options enabled.

Add support for Symfony 4

Hi,

Do you plan to add support for Symfony 4?

Thanks in advance.

Best regards,
Erland Glad Solstrand

Breaks Symfony-Deployment in ScriptHandler::clearCache after following config example

        $clients = [];
        foreach ($config['clients'] as $name => $client) {
            $clients[$name] = [
                'service' => sprintf('contentful.delivery.%s_client', $name),
                'api' => $client['preview'] ? 'PREVIEW' : 'DELIVERY',
                'space' => $client['space']
            ];
            $this->loadDeliveryClient($name, $client, $container);
            $this->loadDeliveryCacheWarmer($name, $client, $container);
        }
        $container->setParameter('contentful.clients', $clients);

Every client tries to fill the cache with its content types. But do we want to fill the cache with the preview client in the prod mode if one follows your configuration example?

contentful:
  delivery:
    default_client: exampleapi
    clients:
      exampleapi:
        space: cfexampleapi
        token: b4c0n73n7fu1
      exapleapi_preview:
        space: cfexampleapi
        token: b4c0n73n7fu1
        preview: true

How to set defaultLocale on the client?

The PHP SDK has support for setting the locale for the entire client instead of just an entry (which annoyingly doesn't set it for an entries linkes entries) , how would you do this in contentful without using default_locale in the config. I need it to be set dynamically based on a URL param.

        $client = $this->get('contentful.delivery');
        $entry = $client->getEntry('yadadada');
        $entry->setLocale('de-DE');

Symfony 6 support

Could you please add support for Symfony 6? It has just been released and this package and contentful/contentful-management are the only packages that are holding us back from updating to Symfony 6.

Thanks!

Support for Symfony 2.8 (LTS)

Hey folks,

I was just browsing your code and wondering what kept you from supporting SF2.8 ? On a glance, I could not find anything that would not work in SF2.8.

Cheers!

Jan

Add support to SF4

Hello,

I am developing an application that should be integrated with Contentful and would like to know when Symfony 4 support will be available.
I'm seriously considering making a fork from this library but I have concerns about changing settings and so on.

Thanks

Warning: count(): Parameter must be an array or an object that implements Countable

Hey there,

I get the following errors when I enter any console commands in symfony 5.
In DebugCommand.php line 55:
Warning: count (): Parameters must be an array or an object that implements Countable

after debug I was able to determine that this is due to the contentful package.
In DebugCommand.php in line 55, "count" is used to check whether the entry of the "client-name" argument should be a mandatory field or an optional field. Php 7.4 doesn't like that :)
This happens if the contentful client is not initialized !!

    # vendor\contentful\contentful-bundle\src\Command\Delivery\DebugCommand.php::__construct (line 55)
        $this->addArgument(
            'client-name',
            \count($this->clients) > 1 ? InputArgument::REQUIRED : InputArgument::OPTIONAL,
            'The name of the client to use'
        );

Would be great if you could improve that. A solution could look like this:

        $this->addArgument(
            'client-name',
            !is_null($this->clients) && \count($this->clients) > 1 ? InputArgument::REQUIRED : InputArgument::OPTIONAL,
            'The name of the client to use'
        );

Thanks in advance
greetings

Env:
php 7.4.10
symfony 5.2
contentful/contentful-bundle 6.1.0

Get asset url in Twig from getEntries

Hello,

In ContentFul, I'v got a simple "Post" contentType wiith some fields : Title, content, cover (Media Image).

I use delivery API

My controller :


	public function index() {

		$query  = (new Query)->setInclude(10)->setContentType($type)->setLimit(10)->orderBy("fields.publishedAt", true);

		$entries = $this->client->getEntries($query);

		return $this->render("web/home.html.twig", [
            		"entries" => $entries,
        	]);
	 }

Twig template :

<div class="container">
	{% for entry in entries.items %}
		<div>{{ entry.title }}</div>
		<div>{{ entry.cover.getFile().getUrl() %}
	{% endfor %}
</div>

Error : "Impossible to invoke a method ("getFile") on an array."

I tried several codes but I can never find the url of the linked media.

Can someone help me.

Thanks a lot.
RodMar

No PHP8 support

Package doesn't support PHP8 so can't be used with PHP8 projects

CacheWarmer and CacheClearer are not compatible with Symfony 3 and Syfmony 4

This is due to Contentful\ContentfulBundle\Cache\Delivery\CacheWarmer::warmUp Contentful\ContentfulBundle\Cache\Delivery\CacheClearer::clear using string typehints for arguments, thus causing fatal errors, while said methods in Symfony 3.4 and 4.4 miss the typehint.

Removing typehints would be enough, since you can remove parameter typehints in extending classes (contravariance), but you cannot add them if parent doesn't have them.

https://3v4l.org/Xl2Oc

I haven't tested all parts of the bundle, so there may be more instances of issues like this.

Model generator from content-type

Hi,

Do you thing a model generator could be useful ?
Imagine, you have an Event in your contentful space and you would like to be able to have a form to allow users to submit events from your website:

space event model preview

and in Symfony, you run the following command:

bin/console generate:contentful:model --content-type event

Let the magic operate and...

<?php
namespace AppBundle\Model;

use Symfony\Component\Validator\Constraints as Assert;

class Event
{
    /**
     * @var string
     */
    private $title;
    /**
     * @var \DateTime
     */
    private $date;
    /**
     * @var float
     */
    private $latitude;
    /**
     * @var float
     */
    private $longitude;
    /**
     * @var string
     */
    private $description;
    /**
     * @var array
     */
    private $tags = [];
    /**
     * @var string
     * @Assert\Url()
     */
    private $link;

    /**
     * @return string
     */
    public function getTitle(): ?string
    {
        return $this->title;
    }

    /**
     * @param string $title
     * @return Event
     */
    public function setTitle(string $title): Event
    {
        $this->title = $title;
        return $this;
    }

    /**
     * @return \DateTime
     */
    public function getDate(): ?\DateTime
    {
        return $this->date;
    }

    /**
     * @param \DateTime $date
     * @return Event
     */
    public function setDate(\DateTime $date): Event
    {
        $this->date = $date;
        return $this;
    }

    /**
     * @return string
     */
    public function getDescription(): ?string
    {
        return $this->description;
    }

    /**
     * @param string $description
     * @return Event
     */
    public function setDescription(string $description): Event
    {
        $this->description = $description;
        return $this;
    }

    /**
     * @return array
     */
    public function getTags(): ?array
    {
        return $this->tags;
    }

    /**
     * @param array $tags
     * @return Event
     */
    public function setTags(array $tags): Event
    {
        $this->tags = $tags;
        return $this;
    }

    /**
     * @return string
     */
    public function getLink(): ?string
    {
        return $this->link;
    }

    /**
     * @param string $link
     * @return Event
     */
    public function setLink(string $link): Event
    {
        $this->link = $link;
        return $this;
    }

    /**
     * @param string $latitude
     * @return Event
     */
    public function setLatitude(string $latitude): Event
    {
        $this->latitude = $latitude;
        return $this;
    }

    /**
     * @return float
     */
    public function getLatitude(): ?float
    {
        return $this->latitude;
    }

    /**
     * @param float $longitude
     * @return Event
     */
    public function setLongitude(float $longitude): Event
    {
        $this->longitude = $longitude;
        return $this;
    }

    /**
     * @return float
     */
    public function getLongitude(): ?float
    {
        return $this->longitude;
    }
}

and

<?php
namespace AppBundle\Domain\Transformer;

use AppBundle\Domain\Model\Event;
use Contentful\Management\Resource\Entry;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\HttpFoundation\RequestStack;

class EventToEntryTransformer implements DataTransformerInterface
{
    /**
     * @var RequestStack
     */
    private $requestStack;

    /**
     * EventToEntryTransformer constructor.
     * @param RequestStack $requestStack
     */
    public function __construct(RequestStack $requestStack)
    {
        $this->requestStack = $requestStack;
    }

    /**
     * @param Event $event
     * @return Entry
     */
    public function transform($event)
    {
        $locale = $this->requestStack->getCurrentRequest()->getLocale();
        $entry = new Entry('event');
        $entry->setField('title', $locale, $event->getTitle());
        $entry->setField('date', $locale, $event->getDate()->format('c'));
        $entry->setField('location', $locale, [
            "lat" => $event->getLatitude(),
            "lon" => $event->getLongitude()
        ]);
        $entry->setField('description', $locale, $event->getDescription());
        $entry->setField('tags', $locale, $event->getTags());
        $entry->setField('link', $locale, $event->getLink());
        $entry->setField('slug', $locale, uniqid('event_', true));

        return $entry;
    }

    /**
     * @param Entry $entry
     * @return Event
     */
    public function reverseTransform($entry)
    {
        $locale = $this->requestStack->getCurrentRequest()->getLocale();
        $event = new Event();
        $event->setTitle($entry->getField('title'), $locale);
        $event->setDate($entry->getField('date'), $locale);
        $event->setLatitude($entry->getField('location')->getField('latitude'), $locale);
        $event->setLongitude($entry->getField('location')->getField('longitude'), $locale);
        $event->setDescription($entry->getField('description'), $locale);
        $event->setTags($entry->getField('tags'), $locale);
        $event->setLink($entry->getField('link'), $locale);

        return $event;
    }
}

[Insight] Deprecated class usage found - in …/ContentfulExtension.php, line 103

in DependencyInjection/ContentfulExtension.php, line 103

The Symfony\Component\DependencyInjection\DefinitionDecorator class has been deprecated in Symfony 3.3. Use the Symfony\Component\DependencyInjection\ChildDefinition class instead.

            ])
            ->addTag('kernel.cache_warmer')
        ;

        $container
            ->setDefinition(sprintf('contentful.delivery.%s_client.cache_clearer', $name), new DefinitionDecorator('contentful.delivery.cache_clearer'))
            ->setArguments([
                $client['space'],
                'contentful'
            ])
            ->addTag('kernel.cache_clearer')

Posted from SensioLabsInsight

Unable to add the ContentfulBundle to my project

Command: composer require contentful/contentful-bundle
PHP version: 7.2.14
Symfony version: 4.2.2

I get this error in my console:

Using version ^4.0 for contentful/contentful-bundle
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Restricting packages listed in "symfony/symfony" to "4.2.*"
Package operations: 14 installs, 0 updates, 0 removals
  - Installing jean85/pretty-package-versions (1.2) Loading from cache
  - Installing psr/http-message (1.0.1) Loading from cache
  - Installing ralouphie/getallheaders (2.0.5) Loading from cache
  - Installing guzzlehttp/psr7 (1.5.2) Loading from cache
  - Installing guzzlehttp/promises (v1.3.1) Loading from cache
  - Installing guzzlehttp/guzzle (6.3.3) Loading from cache
  - Installing contentful/core (2.2.5) Loading from cache
  - Installing contentful/rich-text (1.2.0) Loading from cache
  - Installing cache/tag-interop (1.0.0) Loading from cache
  - Installing cache/adapter-common (1.1.0) Loading from cache
  - Installing cache/hierarchical-cache (1.0.0) Loading from cache
  - Installing cache/void-adapter (1.0.0) Loading from cache
  - Installing contentful/contentful (4.1.1) Loading from cache
  - Installing contentful/contentful-bundle (4.0.0) Loading from cache
Writing lock file
Generating autoload files
ocramius/package-versions:  Generating version class...
ocramius/package-versions: ...done generating version class
Symfony operations: 1 recipe (b3f842960e25e3a6ea163ad10009dcfa)
  - Configuring contentful/contentful-bundle (>=3.0): From github.com/symfony/recipes-contrib:master
Executing script cache:clear [KO]
 [KO]
Script cache:clear returned with error code 255
!!
!!  Fatal error: Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Argument 2 passed to Contentful\ContentfulBundle\DependencyInjection\ContentfulExtension::Contentful\ContentfulBundle\DependencyInjection\{closure}() must be of the type array, string given in C:\xampp\htdocs\contentful\vendor\contentful\contentful-bundle\src\DependencyInjection\ContentfulExtension.php:138
!!  Stack trace:
!!  #0 [internal function]: Contentful\ContentfulBundle\DependencyInjection\ContentfulExtension->Contentful\ContentfulBundle\DependencyInjection\{closure}(0, 'env_4f79913c98a...')
!!  #1 C:\xampp\htdocs\contentful\vendor\contentful\contentful-bundle\src\DependencyInjection\ContentfulExtension.php(140): array_reduce(Array, Object(Closure), 0)
!!  #2 C:\xampp\htdocs\contentful\vendor\contentful\contentful-bundle\src\DependencyInjection\ContentfulExtension.php(46): Contentful\ContentfulBundle\DependencyInjection\ContentfulExtension->registerDeliveryClient(Object(Symfony\Component\DependencyInjection\Compiler\MergeExtensionConfigurationContainerBu in C:\xampp\htdocs\contentful\vendor\contentful\contentful-bundle\src\DependencyInjection\ContentfulExtension.php on line 138
!!  PHP Fatal error:  Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Argument 2 passed to Contentful\ContentfulBundle\DependencyInjection\ContentfulExtension::Contentful\ContentfulBundle\DependencyInjection\{closure}() must be of the type array, string given in C:\xampp\htdocs\contentful\vendor\contentful\contentful-bundle\src\DependencyInjection\ContentfulExtension.php:138
!!  Stack trace:
!!  #0 [internal function]: Contentful\ContentfulBundle\DependencyInjection\ContentfulExtension->Contentful\ContentfulBundle\DependencyInjection\{closure}(0, 'env_4f79913c98a...')
!!  #1 C:\xampp\htdocs\contentful\vendor\contentful\contentful-bundle\src\DependencyInjection\ContentfulExtension.php(140): array_reduce(Array, Object(Closure), 0)
!!  #2 C:\xampp\htdocs\contentful\vendor\contentful\contentful-bundle\src\DependencyInjection\ContentfulExtension.php(46): Contentful\ContentfulBundle\DependencyInjection\ContentfulExtension->registerDeliveryClient(Object(Symfony\Component\DependencyInjection\Compiler\MergeExtensionConfigurationContainerBu in C:\xampp\htdocs\contentful\vendor\contentful\contentful-bundle\src\DependencyInjection\ContentfulExtension.php on line 138
!!

Installation failed, reverting ./composer.json to its original content.

What can I do to get it working?

unit test failed. DebugCommandTest::testOutput

$ phpunit
PHPUnit 7.5.8 by Sebastian Bergmann and contributors.

Error:         No code coverage driver is available

..F......................                                         25 / 25 (100%)

Time: 4.65 seconds, Memory: 12.00 MB

There was 1 failure:

1) Contentful\Tests\ContentfulBundle\Unit\Command\Delivery\DebugCommandTest::testOutput
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
  ------------------------ ------- -------- --------- -------------
   ID                       Name    Fields   Entries   Description
  ------------------------ ------- -------- --------- -------------
-  dog                      Dog     3        2         Bark!
+  cat                      Cat     8        3         Meow.
   1t9IbcfdCk6m04uISSsaIK   City    2        4
   human                    Human   4        1
-  cat                      Cat     8        3         Meow.
+  dog                      Dog     3        2         Bark!
  ------------------------ ------- -------- --------- -------------

  // https://app.contentful.com/spaces/cfexampleapi/environments/master/content_types

 '

/home/vagrant/code/ContentfulBundle/tests/Unit/Command/Delivery/DebugCommandTest.php:39

FAILURES!
Tests: 25, Assertions: 122, Failures: 1.

Profiler details not working (Runtime error)

Library version: 7.2.0
Symfony version: 6.3.3
PHP version: 8.2.7
Symfony enviroment: dev

Hello everybody,

I just found my way back to Symfony and did a Spike to integrate the ContentfulBundle (and later, using Contentful in an iOS app). Worked great so far, but I am not able to use the profiler as it should be.

The list of the contentful panel works as intended, but clicking on „Details“ of a request will result in the following error:

An exception has been thrown during the rendering of a template ("The controller for URI "/_fragment" is not callable: Controller "contentful.profiler_controller:detailsAction" does neither exist as service nor as class.").

The profiler itself is working, the service contentful.profiler_controller is registered (verified using ./bin/console debug:container), the method detailsAction exists. Would investigate further, but now I have to move away from the computer… 😉

Best regards from Germany and Happy Weekend! 👋

Deprecation warnings in PHP 8.1

  1. Method "Symfony\Component\Console\Command\Command::execute()" might add "int" as a native return type declaration in the future. Do the same in child class "Contentful\ContentfulBundle\Command\Delivery\InfoCommand" now to avoid errors or add an explicit @return annotation to suppress this message.
  2. Method "Symfony\Component\Console\Command\Command::execute()" might add "int" as a native return type declaration in the future. Do the same in child class "Contentful\ContentfulBundle\Command\Delivery\DebugCommand" now to avoid errors or add an explicit @return annotation to suppress this message.
  3. Method "Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface::warmUp()" might add "array" as a native return type declaration in the future. Do the same in implementation "Contentful\ContentfulBundle\Cache\Delivery\CacheWarmer" now to avoid errors or add an explicit @return annotation to suppress this message.

Make prod environment work without depending on profiler

On development my app runs without no problem but when I go to production environment, if I don't enable the profiler on config.yml I get the following error message:

The service "contentful.profiler_controller" has a dependency on a non-existent service "profiler"

It would be nice to make it work on production without depending on the profiler.

Strategy for preview implementation

Hello everybody,

I'm back with another question which is much more about getting your advices and best practices for preview setup.

Let'say that I setup a website called www.mysite.com with Contentful and I want to add the preview feature.

What I have in mind is that I want to setup a simple preview passing a query string parameter like ?preview=1 to switch to preview mode. For example, on the homepage https://www.mysite.com/ will switch to preview mode when I add https://www.mysite.com/?preview=1

First question, is it a good idea ?

Now, going deeper in it, I created a service called "Contentful" where I inject the client thanks to dependency injection:

<?php

namespace App\Service;

use Contentful\Delivery\Client\ClientInterface;
use Contentful\Delivery\Query;
use Contentful\Delivery\Resource\Entry;

class Contentful
{


    private ClientInterface $client;

    public function __construct(ClientInterface $client)
    {
        $this->client = $client;
    }
...

Now, I'm a little bit stuck about the way to switch to preview API with my client injected like that.
What I have in mind is :

  • Intercept all the request to my website
  • Check if the query string preview=1 exists
  • Create a factory to inject the client saying to use preview API instead of main API when the query string is there

Is it a good strategy or am I overcomplicating things ?
What is yours ? ( using a subdomain ? )

Thanks for your feedback.

Best.

Typehint causing build error in Symfony 3.4 - 4.4

public function collect(Request $request, Response $response, \Throwable $exception = \null)

In Symfony v3.4 we get a PHP compile error because the ClientDataCollector declaration does not match the Symfony DataCollector it extends. The collect method typehints the $exception variable to be \Exception rather than \Throwable.

In this case, the typehint should be removed in order to be compatible with supported versions of this bundle.

The "Symfony\Component\Console\Command\Command::$defaultName" property is considered final.

  1. The "Symfony\Component\Console\Command\Command::$defaultName" property is considered final. You should not override it in "Contentful\ContentfulBundle\Command\Delivery\InfoCommand".
  2. The "Symfony\Component\Console\Command\Command::$defaultName" property is considered final. You should not override it in "Contentful\ContentfulBundle\Command\Delivery\DebugCommand".

Resources:

What about a contentful/contentful-management and a client service definition ?

Hi,

This bundle is cool (and thank you for that ❤️ ) for read actions but as soon as we need to add create/update actions, then we have to do things manually.

Would you like a PR from me with the declaration of the management client ?

composer require contentful/contentful-management:@dev

Something like this:

#parameters.yml
parameters:
    contentful_management_token: token

#app/config/services.yml
services:
    Contentful\Management\Client:
        arguments:
            $token: '%contentful_management_token%'
            $currentSpaceId: '%contentful_space%'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.