Symfony (4.2) installing "API- Platfrom" for using Web-Services
JerDox
Posted on June 21, 2022
I have a Symfony (4.2) project and need to setup/communicate with a web-service.
So after a short search I found that there is a package for Symfony which should makes handling of web-services easy.
It's called "API Platform".
On Symfonycast I found a video of how to install the API-Platform Symfonycast
Sounds easy, so let's do it by easily run the command
composer require api:1.2.0
to install api-platfrom via composer
... and it fails with the message:
require.api is invalid, it should have a vendor name, a forward slash, and a package name. The vendor and package name can be words separated by -, . or _. The complete name should match "^[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9](([_.]?|-{0,2})[a-z0-9]+)*$".
For me it seems that it did not find the api recipe. So on the github page of the Symfony/flex Bundle I found the List of existing recipes RecipeList and in it there was no "api" recipe only a "api-platform/core" recipe. So I tryed that with:
composer require api-platform/core
... and it fails again this time with another error message:
Your requirements could not be resolved to an installable set of packages.
Problem 1
- symfony/flex is locked to version v1.6.2 and an update of this package was not requested.
- symfony/flex v1.6.2 requires composer-plugin-api ^1.0 -> found composer-plugin-api[2.3.0] but it does not match the constraint.
Problem 2
- api-platform/core[v2.6.0, ..., v2.6.6] require symfony/http-foundation ^4.4 || ^5.1 -> found symfony/http-foundation[v4.4.0, ..., v4.4.42, v5.1.0, ..., v5.4.9] but the package is fixed to v4.2.12 (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.
- api-platform/core[v2.6.7, ..., v2.6.8] require symfony/http-foundation ^4.4 || ^5.1 || ^6.0 -> found symfony/http-foundation[v4.4.0, ..., v4.4.42, v5.1.0, ..., v5.4.9, v6.0.0, ..., v6.1.1] but the package is fixed to v4.2.12 (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.
- Root composer.json requires api-platform/core ^2.6 -> satisfiable by api-platform/core[v2.6.0, ..., v2.6.8].
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 api-platform/core:*" to figure out if any version is installable, or "composer require api-platform/core:^2.1" if you know which you need.
...as the message said in the last sentence, I try it with:
composer require api-platform/core:*
...also not working. Message:
Your requirements could not be resolved to an installable set of packages.
Problem 1
- symfony/flex is locked to version v1.6.2 and an update of this package was not requested.
- symfony/flex v1.6.2 requires composer-plugin-api ^1.0 -> found composer-plugin-api[2.3.0] but it does not match the constraint.
Next I try it with the option "--with-all-dependencies" which was also recommended in the error message before. So I run:
composer require api-platform/core:* --with-all-dependencies
... it ends up with the same error message as before.
I take a look back to the Symfonycast tutorial. On the page it the possibility to see the composer.json which was used in the tutorial. I see that the symfony version was the same as my "4.2" the api-platform/core was of version "^2.1". So I tried the command with the version "^2.1":
composer require api-platform/core:^2.1 --with-all-dependencies
... nope, not working, error message:
Your requirements could not be resolved to an installable set of packages.
Problem 1
- symfony/flex is locked to version v1.6.2 and an update of this package was not requested.
- symfony/flex v1.6.2 requires composer-plugin-api ^1.0 -> found composer-plugin-api[2.3.0] but it does not match the constraint.
Problem 2
- ocramius/package-versions 1.4.2 requires composer-plugin-api ^1.0.0 -> found composer-plugin-api[2.3.0] but it does not match the constraint.
- doctrine/doctrine-migrations-bundle 2.1.2 requires doctrine/migrations ^2.2 -> satisfiable by doctrine/migrations[2.2.1].
- symfony/orm-pack v1.0.8 requires doctrine/doctrine-migrations-bundle * -> satisfiable by doctrine/doctrine-migrations-bundle[2.1.2].
- doctrine/migrations 2.2.1 requires ocramius/package-versions ^1.3 -> satisfiable by ocramius/package-versions[1.4.2].
- symfony/orm-pack is locked to version v1.0.8 and an update of this package was not requested.
That's frustrating :/ ...
Next what I was going to do was to clear the cache of composer, in hope that that's the problem. I run
composer clearcache
That's done without any error message and then run again:
composer require api-platform/core:^2.1 --with-all-dependencies
... nope that don't make a different...
Okay, next thing I've done was to delete my composer.lock and my vendor-folder and do a complete install of the dependencies with:
composer install
Next error. This time after composer installed all dependencies and then try to clear the cache. Message:
Script cache:clear returned with error code 1
!!
!! In ArrayNode.php line 331:
!!
!! Unrecognized options "dir_name, namespace" under "doctrine_migrations". Available options are "all_or_nothing", "check_database_platform", "connection
"
!! , "custom_template", "em", "factories", "migrations", "migrations_paths", "organize_migrations", "services", "storage".
!!
!!
!!
Script @auto-scripts was called via post-update-cmd
After a short googleing it seems that this error comes from the doctrine/doctrine-migrations-bundle dependency which should be use in version 2.0 but installed was 3.0.
So I changed the corresponding entry of this package in the composer.json to version 2.0 and run:
composer update --with-all-dependencies
...and surprise done without an error message.
Okay new hope for my actual problem.
As a reminder I want to install the api-platform with composer...
So I run again:
composer require api-platform/core:^2.1 --with-all-dependencies
... and YES it installed the api-platfrom dependency without an error messages. I hadn't believed in it anymore after this chain of error (pain).
Supplement:
As I continued with the Tutorial from Symfonycast I saw that with the origin command
composer require api:1.2.0
they installed not only just the api-platform/core bundle but also some other bundles with seems to be helpful.
They installes a package with called api-platform/api-pack which contains the following child bundles:
- api-platform/core
- nelmio/cors-bundle
- symfony/asset
- symfony/expression-language
- symfony/orm-pack
- symfony/security-bundle
- symfony/serializer-pack
- symfony/twig-bundle
- symfony/validator
I think that I also need those bundles later on. So back in the "rabbit hole of dependencies" I run:
composer require api-platform/api-pack:1.2.2 --with-all-dependencies
...runs and ...also successful, puhhh yeah.
I used the version 1.2.2 of the api-pack, because this was the latest version in which the api-platfrom/core:2.1 was included.
Those Informations about the composer bundles you can find under:
Packagist
See you next time in the dependency hell...
Posted on June 21, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.