Search code examples
phpsymfonycomposer-phpsymfony4fosrestbundle

Rest-bundle of Symfony 4 requires config in 4.3 version, while Symfony 4 uses 5.0


Following this tutorial I tried to configure REST API on fresh new Symfony 4 install.

The first step in the tutorial is doing:

composer create-project symfony/skeleton rest_api_project

Followed by

composer require friendsofsymfony/rest-bundle

However, when I try to install friendsofsymfony/rest-bundle, I get:

Your requirements could not be resolved to an installable set of packages. Problem 1 - Installation request for friendsofsymfony/rest-bundle ^2.6 -> satisfiable by friendsofsymfony/rest-bundle[2.6.0]. - friendsofsymfony/rest-bundle 2.6.0 requires symfony/config ^3.4|^4.3 -> no matching package found.

So basically that this bundle requires symfony/config ^3.4|^4.3 while Symfony 4 uses 5.0.

How to make it work? And how this tutorial meant for Symfony 4 could even work when the friendsofsymfony/rest-bundle does not support config in 5.0 version?


Solution

  • The tutorial you are using includes this as a starting point:

    composer create-project \
        symfony/skeleton rest_api_project
    

    Without a version constraint, this points to the latest version of the Symfony Skeleton. Namely, version 5.

    Problem is, the FOS Rest Bundle has not been updated with Symfony 5 compatibility yet.

    So you need to create the project and target version 4.

    composer create-project\
        symfony/skeleton rest_api_project "4.*"
    

    With this the versions of your dependencies are going to match.

    And how this tutorial meant for Symfony 4 could even work when the friendsofsymfony/rest-bundle does not support config in 5.0 version?

    The tutorial is meant for Symfony 4, but you were installing Symfony 5.