Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

browscap-php is incompatible with psr/cache 3 (e.g. Symfony Cache) #432

Open
j-dobr opened this issue Apr 28, 2022 · 7 comments
Open

browscap-php is incompatible with psr/cache 3 (e.g. Symfony Cache) #432

j-dobr opened this issue Apr 28, 2022 · 7 comments

Comments

@j-dobr
Copy link

j-dobr commented Apr 28, 2022

Tried to use browscap-php with Symfony 6 (symfony/skeleton) but there is dependency conflict:

    - Root composer.json requires browscap/browscap-php 7.0 -> satisfiable by browscap/browscap-php[7.0.0].
    - matthiasmullie/scrapbook 1.4.8 requires psr/cache ~1.0 -> satisfiable by psr/cache[1.0.0, 1.0.1].
    - You can only install one version of a package, so only one of these can be installed: psr/cache[1.0.0, 1.0.1, 2.0.0, 3.0.0].
    - symfony/cache-contracts v3.0.0 requires psr/cache ^3.0 -> satisfiable by psr/cache[3.0.0].
    - symfony/cache v6.0.6 requires symfony/cache-contracts ^1.1.7|^2|^3 -> satisfiable by symfony/cache-contracts[v3.0.0].
    - doctrine/doctrine-bundle 2.6.0 requires symfony/cache ^4.3.3|^5.0|^6.0 -> satisfiable by symfony/cache[v6.0.6].
    - browscap/browscap-php 7.0.0 requires matthiasmullie/scrapbook ^1.4.8 -> satisfiable by matthiasmullie/scrapbook[1.4.8].
    - doctrine/doctrine-bundle is locked to version 2.6.0 and an update of this package was not requested.

Is there any way to resolve this?

@Rubinum
Copy link
Contributor

Rubinum commented Sep 26, 2022

its been half a year... are there any updates? do you need help upgrading this?

@asgrim
Copy link
Member

asgrim commented Sep 26, 2022

If a patch can be made, sure, it would be welcome 👍 thanks.

Please note: we must retain support for psr/cache:^1.0, which I think is where the difficulty lies.

@j-dobr
Copy link
Author

j-dobr commented Sep 26, 2022

That is the problem indeed - psr/cache:^1.0 is not compatible with Symfony (symfony/cache to be specific, which is part of symfony/skeleton). And since support for psr/cache:^1.0 must be retained, there is no solution.

Main reason for me bringing this up were release notes of v7.0.0 with #418 which made me think it should be compatible with Symfony 6, but it seems that was only about specific Symfony component.

@asgrim asgrim changed the title Symfony 6 dependency conflict - psr/cache cannot be satisfied Incompatible with psr/cache 3 (e.g. Symfony Cache) Sep 26, 2022
@asgrim asgrim changed the title Incompatible with psr/cache 3 (e.g. Symfony Cache) browscap-php is incompatible with psr/cache 3 (e.g. Symfony Cache) Sep 26, 2022
@Rubinum
Copy link
Contributor

Rubinum commented Sep 26, 2022

You can reproduce this issue if you

  • require symfony cache 5.4
  • require this project at the latest stable version
  • upgrade to symfony 6.* by following the instructions mentioned in the upgrade guide.

@holtkamp
Copy link
Contributor

holtkamp commented Oct 14, 2022

Additionally: matthiasmullie/scrapbook 1.4.8 requires psr/cache ~1.0

Since matthiasmullie/scrapbook is a currently a hard dependency

"matthiasmullie/scrapbook": "^1.4.8",
this dependency also needs to support psr/cache ^2.0 || ^3.0

Requested this here matthiasmullie/scrapbook#54

Isolate the Commands and reduce dependencies?
Another approach might be to isolate the Commands (which use matthiasmullie/scrapbook) in a separate repository along with dependencies such as symfony/console and league/flysystem, only used in the Commands...

@Rubinum
Copy link
Contributor

Rubinum commented Dec 30, 2022

I found out, that you can circumvent this issue by:

  1. removing browsecap via composer remove browscap/browscap-php
  2. updating symfony to symfony 6 according to the official guide
  3. installing it again via composer require browscap/browscap-php

If someone has the same issue, try this. I hope it helps :). No clue why composer is throwing this issue while updating but if someone can bring more light into this, why this happens, I am definitely interested.

@Crovitche-1623
Copy link

Crovitche-1623 commented Oct 31, 2023

Hello guys,

I don't know if the following snippets can help you but here's how I managed to get Symfony's cache working with Browscap.

First, register a new cache pool:

# config/packages/cache.yaml

framework:
    cache:
        pools:
            # To prevent the browscap cache being deleted by the `cache:clear`
            # command. A custom cache pool is used.
            #
            # Note: this cache can be cleared using the 
            #       `cache:pool:clear browscap_cache` in order to force the 
            #       browscap cache to be reloaded.
            browscap_cache:
                adapter: cache.adapter.filesystem

Then, configure the dependencie for Browscap classes:

# config/services.yaml

services:
  # As Browscap uses a PSR-16 cache but Symfony use a PSR-6 cache, we need to
  # wrap the PSR-6 cache into a PSR-16 cache
  Symfony\Component\Cache\Psr16Cache:
    arguments:
      # The cache pool is defined in `config/packages/cache.yaml`
      # the name matters, it must be the same as the one defined in cache.yaml
      - '@browscap_cache'

  BrowscapPHP\Browscap:
    arguments:
      # Note that the used cache must be the same as the one use for
      # `BrowscapPHP\BrowscapUpdater`
      - '@Symfony\Component\Cache\Psr16Cache'
      - '@logger'

  BrowscapPHP\BrowscapUpdater:
    arguments:
      # Note that the used cache must be the same as the one use for
      # `BrowscapPHP\Browscap`
      - '@Symfony\Component\Cache\Psr16Cache'
      - '@logger'

Now, you can directly inject Browscap classes and it will work. For instance:

<?php

use BrowscapPHP\Browscap;

readonly class FooBarService
{
    public function __construct(
        private Browscap $browscap,
    ) {
    }

    public function test(Request $request)
    {
        $information = $this->browscap->getBrowser($request->headers->get('User-Agent'));
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants