Sylius: Dependency conflicts with SyliusResourceBundle

Created on 8 Dec 2016  路  18Comments  路  Source: Sylius/Sylius

Hi everyone,

I'm trying to create a Symfony 3.2 project from scratch (not e-commerce) with SyliusResourceBundle in order to have CRUD support out of the box for my entities.
I didn't manage to install the bundle because of composer conflicts:

$ composer require sylius/resource-bundle
Using version ^0.19.0 for sylius/resource-bundle
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for sylius/resource-bundle ^0.19.0 -> satisfiable by sylius/resource-bundle[v0.19.0].
    - Conclusion: remove symfony/symfony 3.2.x-dev
    - Conclusion: don't install symfony/symfony 3.2.x-dev
    - sylius/resource-bundle v0.19.0 requires symfony/validator ^2.8 -> satisfiable by symfony/validator[2.8.x-dev, v2.8.0, v2.8.0-BETA1, v2.8.1, v2.8.10, v2.8.11, v2.8.12, v2.8.13, v2.8.14, v2.8.2, v2.8.3, v2.8.4, v2.8.5, v2.8.6, v2.8.7, v2.8.8, v2.8.9].
    - don't install symfony/validator 2.8.x-dev|don't install symfony/symfony 3.2.x-dev
    - don't install symfony/validator v2.8.0|don't install symfony/symfony 3.2.x-dev
    - don't install symfony/validator v2.8.0-BETA1|don't install symfony/symfony 3.2.x-dev
    - don't install symfony/validator v2.8.1|don't install symfony/symfony 3.2.x-dev
    - don't install symfony/validator v2.8.10|don't install symfony/symfony 3.2.x-dev
    - don't install symfony/validator v2.8.11|don't install symfony/symfony 3.2.x-dev
    - don't install symfony/validator v2.8.12|don't install symfony/symfony 3.2.x-dev
    - don't install symfony/validator v2.8.13|don't install symfony/symfony 3.2.x-dev
    - don't install symfony/validator v2.8.14|don't install symfony/symfony 3.2.x-dev
    - don't install symfony/validator v2.8.2|don't install symfony/symfony 3.2.x-dev
    - don't install symfony/validator v2.8.3|don't install symfony/symfony 3.2.x-dev
    - don't install symfony/validator v2.8.4|don't install symfony/symfony 3.2.x-dev
    - don't install symfony/validator v2.8.5|don't install symfony/symfony 3.2.x-dev
    - don't install symfony/validator v2.8.6|don't install symfony/symfony 3.2.x-dev
    - don't install symfony/validator v2.8.7|don't install symfony/symfony 3.2.x-dev
    - don't install symfony/validator v2.8.8|don't install symfony/symfony 3.2.x-dev
    - don't install symfony/validator v2.8.9|don't install symfony/symfony 3.2.x-dev
    - Installation request for symfony/symfony (locked at 3.2.x-dev, required as 3.2.*) -> satisfiable by symfony/symfony[3.2.x-dev].


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

Then I updated my composer.json to set minimum-stability to dev and tried this:

$ composer require sylius/resource-bundle dev-master
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for sylius/resource-bundle dev-master -> satisfiable by sylius/resource-bundle[dev-master].
    - Conclusion: remove sensio/framework-extra-bundle v3.0.16
    - Conclusion: don't install sensio/framework-extra-bundle v3.0.16
    - sylius/resource-bundle dev-master requires friendsofsymfony/rest-bundle ^1.8 -> satisfiable by friendsofsymfony/rest-bundle[1.8.0, 1.8.0-BETA1, 1.8.0-BETA2, 1.8.x-dev].
    - friendsofsymfony/rest-bundle 1.8.0 conflicts with sensio/framework-extra-bundle[v3.0.16].
    - friendsofsymfony/rest-bundle 1.8.0-BETA1 conflicts with sensio/framework-extra-bundle[v3.0.16].
    - friendsofsymfony/rest-bundle 1.8.0-BETA2 conflicts with sensio/framework-extra-bundle[v3.0.16].
    - friendsofsymfony/rest-bundle 1.8.x-dev conflicts with sensio/framework-extra-bundle[v3.0.16].
    - Installation request for sensio/framework-extra-bundle (locked at v3.0.16, required as ^3.0.2) -> satisfiable by sensio/framework-extra-bundle[v3.0.16].


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

I even tried to downgrade to Symfony 3.1 then Symfony 3.0 (fresh installs each time), but I still have composer issues.
What is your advice?

Thank you in advance,
Ben

Documentation Potential Bug

Most helpful comment

Hi there again,

Now that I succeeded in installing SyliusResourceBundle with Symfony 3.2, I'm following the tutorial in the documentation, but it still doesn't work out of the box:
http://docs.sylius.org/en/latest/bundles/SyliusResourceBundle/configuration.html

Translator issue

I have registered the /books endpoint as an api resource:

# app/config/config.yml 
sylius_resource:
    resources:
        app.book:
            classes:
                model: AppBundle\Entity\Book

# app/config/router.yml
app_book:
    resource: |
        alias: app.book
    type: sylius.resource_api

Now when I call GET http://localhost:8000/books, an exception is raised:

Type error: Argument 2 passed to Sylius\Bundle\ResourceBundle\Controller\FlashHelper::__construct() must be an instance of Symfony\Component\Translation\TranslatorBagInterface, instance of Symfony\Component\Translation\IdentityTranslator given

Indeed, with a fresh Symfony install, the following line in config.yml is commented by default:

# app/config/config.yml
framework:
    #translator:      { fallbacks: ["%locale%"] }

As a result, the translator service maps to Symfony\Component\Translation\IdentityTranslator class, which does not translate anything, and is not _instanceof_ Symfony\Component\Translation\TranslatorBagInterface .

Uncommenting that line maps the translator service to Symfony\Component\Translation\DataCollectorTranslator which solves the problem.

I don't know if this is a bug, or if enabling the translation component is mandatory for the bundle to work. In that case, you should mention this in the doc.

Content-negociation issue

Then, when calling GET http://localhost:8000/books with an Accept: application/json header, the following exception is raised:

Unable to find template "/index.html.twig"

Since I requested a JSON response, why looking for a template? In fact, FOSRestBundle needs to be configured, I didn't figure that out at the first glance. Maybe mentionning this in the doc would help newbies like me :)

First resource creation issue

Now that I have a JSON response on the index, I'd like to create my first book, as told in the tutorial.

curl -i -X POST -H "Content-Type: application/json" -d '{"title": "Lord of The Rings", "author": "J. R. R. Tolkien", "description": "Amazing!"}' http://localhost:8000/books/

Here's the result:

Class "form" is not configured for resource "app.book".

Do I need to create a form for my Book example? I thought form generation was automatic since the bundle has an option to use a "custom" form.

Sorry for bothering you, I'm not even certain this is the right place to ask for help, but I noticed you put big efforts in the documentation to make things easy and the DX perfect, so I'd like to contribute to that ;)

Thanks,
Ben

All 18 comments

Try using ^1.0@beta in your composer.json. Or composer require -s beta sylius/resource-bundle.

@TheMadeleine We should use stability beta in all bundle documentations. Can you do a quick fix please?

@pjedrzejewski I'm on it.

UPDATE: Done ;D

Hi Pawel,

Unfortunately this did not the trick.

$ composer require -s beta sylius/resource-bundle

  [Symfony\Component\Console\Exception\RuntimeException]
  The "-s" option does not exist.


require [--dev] [--prefer-source] [--prefer-dist] [--no-progress] [--no-update] [--no-scripts] [--update-no-dev] [--update-with-dependencies] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--] [<packages>]...

(After checking Composer's documentation, the -s option only exists on create-project command)

$ composer require sylius/resource-bundle ^1.0@beta
./composer.json has been updated
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for sylius/resource-bundle ^1.0@beta -> satisfiable by sylius/resource-bundle[v1.0.0-beta.1].
    - sylius/resource-bundle v1.0.0-beta.1 requires sylius/resource ^1.0 -> satisfiable by sylius/resource[1.0.x-dev, v1.0.0-alpha.1, v1.0.0-alpha.2, v1.0.0-beta.1] but these conflict with your requirements or minimum-stability.

Installation failed, reverting ./composer.json to its original content.
// Looks like I need to install sylius/resource 1.0 beta first

$ composer require sylius/resource ^1.0@beta
./composer.json has been updated
  - Installing pagerfanta/pagerfanta (v1.0.4)
    Loading from cache

  - Installing winzou/state-machine (0.3.2)
    Loading from cache

  - Installing sylius/resource (v1.0.0-beta.1)
    Loading from cache
Writing lock file
Generating autoload files

// Clearing cache etc...

$ composer require sylius/resource-bundle ^1.0@beta
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - friendsofsymfony/rest-bundle 1.8.0 conflicts with sensio/framework-extra-bundle[v3.0.16].
    - friendsofsymfony/rest-bundle 1.8.0 conflicts with sensio/framework-extra-bundle[v3.0.16].
    - friendsofsymfony/rest-bundle 1.8.0 conflicts with sensio/framework-extra-bundle[v3.0.16].
    - sylius/resource-bundle v1.0.0-beta.1 requires friendsofsymfony/rest-bundle ^1.8 -> satisfiable by friendsofsymfony/rest-bundle[1.8.0].
    - Installation request for sylius/resource-bundle ^1.0@beta -> satisfiable by sylius/resource-bundle[v1.0.0-beta.1].
    - Installation request for sensio/framework-extra-bundle (locked at v3.0.16, required as ^3.0.2) -> satisfiable by sensio/framework-extra-bundle[v3.0.16].


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

>_<

Well, I've checked it:

Clean installation of symfony

composer create-project symfony/framework-standard-edition test3 "3.2.*"

And then this in composer.json.

"minimum-stability": "beta",
    "require": {
        "php": ">=5.5.9",
        "symfony/symfony": "3.2.*",
        "doctrine/orm": "^2.5",
        "doctrine/doctrine-bundle": "^1.6",
        "doctrine/doctrine-cache-bundle": "^1.2",
        "symfony/swiftmailer-bundle": "^2.3",
        "symfony/monolog-bundle": "^3.0",
        "symfony/polyfill-apcu": "^1.0",
        "sensio/distribution-bundle": "^5.0",
        "sensio/framework-extra-bundle": "^3.0.2",
        "incenteev/composer-parameter-handler": "^2.0",
        "sylius/resource-bundle": "^1.0@beta"
    },
    "require-dev": {
        "sensio/generator-bundle": "^3.0",
        "symfony/phpunit-bridge": "^3.0"
    },

Works for me perfectly well.

Check the sensio/framework-extra-bundle maybe?

Hi TheMadeleine,

It indeed worked with composer create-project then composer update.
I previously used the Symfony's installer then called composer require.

Theorically (well, as far as I know), the result should be identical... strange.

Thanks for your help and have a nice day :)
Ben

Hi there again,

Now that I succeeded in installing SyliusResourceBundle with Symfony 3.2, I'm following the tutorial in the documentation, but it still doesn't work out of the box:
http://docs.sylius.org/en/latest/bundles/SyliusResourceBundle/configuration.html

Translator issue

I have registered the /books endpoint as an api resource:

# app/config/config.yml 
sylius_resource:
    resources:
        app.book:
            classes:
                model: AppBundle\Entity\Book

# app/config/router.yml
app_book:
    resource: |
        alias: app.book
    type: sylius.resource_api

Now when I call GET http://localhost:8000/books, an exception is raised:

Type error: Argument 2 passed to Sylius\Bundle\ResourceBundle\Controller\FlashHelper::__construct() must be an instance of Symfony\Component\Translation\TranslatorBagInterface, instance of Symfony\Component\Translation\IdentityTranslator given

Indeed, with a fresh Symfony install, the following line in config.yml is commented by default:

# app/config/config.yml
framework:
    #translator:      { fallbacks: ["%locale%"] }

As a result, the translator service maps to Symfony\Component\Translation\IdentityTranslator class, which does not translate anything, and is not _instanceof_ Symfony\Component\Translation\TranslatorBagInterface .

Uncommenting that line maps the translator service to Symfony\Component\Translation\DataCollectorTranslator which solves the problem.

I don't know if this is a bug, or if enabling the translation component is mandatory for the bundle to work. In that case, you should mention this in the doc.

Content-negociation issue

Then, when calling GET http://localhost:8000/books with an Accept: application/json header, the following exception is raised:

Unable to find template "/index.html.twig"

Since I requested a JSON response, why looking for a template? In fact, FOSRestBundle needs to be configured, I didn't figure that out at the first glance. Maybe mentionning this in the doc would help newbies like me :)

First resource creation issue

Now that I have a JSON response on the index, I'd like to create my first book, as told in the tutorial.

curl -i -X POST -H "Content-Type: application/json" -d '{"title": "Lord of The Rings", "author": "J. R. R. Tolkien", "description": "Amazing!"}' http://localhost:8000/books/

Here's the result:

Class "form" is not configured for resource "app.book".

Do I need to create a form for my Book example? I thought form generation was automatic since the bundle has an option to use a "custom" form.

Sorry for bothering you, I'm not even certain this is the right place to ask for help, but I noticed you put big efforts in the documentation to make things easy and the DX perfect, so I'd like to contribute to that ;)

Thanks,
Ben

I'm also currently working with the Sylius ResourceBundle and running into a problem similar to one of @bpolaszek's. I configured my resource exactly to the documentation's spec on configuring your first resource, but get the error

Class "form" is not configured for resource "app.book".

That particular node is looking for just a scalar classname, as well, rather than an object, as the reference for resource configuration indicates. (If you pass it an array for form, it throws an error that it's looking for a scalar.)

@baublet Yes, that is the case since the recent Symfony 3 upgrade. form should be a class now, like in https://github.com/Sylius/Sylius/pull/6878/files#diff-476eba1ccbee1d4df669cd3452bdd165R20

Right, so I made my own form class and configured it as per the documentation on 5.1 Custom Resource Form and it seems that Sylius then passes no arguments to the custom form's constructor. Yet, the form needs at least one argument passed in.

Type error: Too few arguments to function Sylius\Bundle\ResourceBundle\Form\TypeAbstractResourceType::__construct(), 0 passed in /var/www/sylius/vendor/symfony/symfony/src/Symfony/Component/Form/FormRegistry.php on line 85 and at least 1 expected

Was there a recent undocumented change in creating resource forms?

Looks like it's missing the service definition. Check out the ProductBundle for an example, the AbstractResourceType (here) requires a dataClass and validationGroups as arguments. Does this help?

@venyii, that works! Excellent. I'm going through and trying to update the documentation as I find deficiencies and ambiguities, so this should help a bunch. I hope this also helped @bpolaszek with his issue?

Hi there,

Hm, not really. Actually I want to use this bundle in a new project to avoid creating controllers, views, forms, API endpoints, ... for my resources, unless I explicitely need a custom logic.

I think this is the base idea behind that Bundle, so I shouldn't need to create a custom form class... if there's nothing "custom" out there.

And, indeed when I tried to do so, I ran into the same issue (DI wiring failed).

I'm using Symfony 3.2.

Thanks!
Ben

Actually I don't understand why this doesn't work!

I cloned a fesh dev-master of sylius/sylius-standard which relies (of course) on SyliusResourceBundle and runs perfectly well on Symfony 3.2.1.

I could easily log on the API and POST a new /api/channels resource, for example.
I didn't figure out why this works within the Sylius distribution and not when picking components apart.

@bpolaszek Sorry, we will bring back the form generation as soon as possible. For now you will need to define the form manually. :(

I'm also facing issues when trying to create an extra model following this example (http://docs.sylius.org/en/latest/cookbook/custom-model.html). All works, only the form seems not listed when using the debug:container command.

I get the same error when trying to open the /new URL: Class "form" is not configured for resource "app.supplier".

I'm using a fresh Sylius standard installation, on Symfony 3.2.1.

@lchrusciel is on it right now! :)

Added in #7185.

Oh, you. <3

Was this page helpful?
0 / 5 - 0 ratings

Related issues

loic425 picture loic425  路  3Comments

inssein picture inssein  路  3Comments

crbelaus picture crbelaus  路  3Comments

stefandoorn picture stefandoorn  路  3Comments

mikemix picture mikemix  路  3Comments