Skip to content

Annotations cannot be enabled error occurs when installing anything requiring doctrine/annotations. #24683

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

Closed
nesl247 opened this issue Oct 24, 2017 · 7 comments

Comments

@nesl247
Copy link

nesl247 commented Oct 24, 2017

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 4.0.0-BETA1

When running composer require friendsofphp/php-cs-fixer:2.7-x-dev on Symfony 4, I get the following:

composer require --dev friendsofphp/php-cs-fixer:2.7.x-dev                                                                                 0 < 15:32:54
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 12 installs, 0 updates, 0 removals
  - Installing symfony/stopwatch (v4.0.0-BETA1): Loading from cache
  - Installing symfony/process (v4.0.0-BETA1): Loading from cache
  - Installing symfony/polyfill-php72 (v1.6.0): Loading from cache
  - Installing paragonie/random_compat (v2.0.11): Loading from cache
  - Installing symfony/polyfill-php70 (v1.6.0): Loading from cache
  - Installing symfony/options-resolver (v4.0.0-BETA1): Loading from cache
  - Installing php-cs-fixer/diff (v1.2.0): Loading from cache
  - Installing gecko-packages/gecko-php-unit (v2.2): Loading from cache
  - Installing doctrine/lexer (v1.0.1): Loading from cache
  - Installing doctrine/annotations (v1.5.0): Loading from cache
  - Installing composer/semver (1.4.2): Loading from cache
  - Installing friendsofphp/php-cs-fixer (2.7.x-dev fbc5c68): Loading from cache
Writing lock file
Generating autoload files
Symfony operations: 1 recipe (a31ecc32214b0ec17448c074f556d474)
  - Configuring friendsofphp/php-cs-fixer (2.2): From github.com/symfony/recipes:master
Executing script cache:clear [KO]
 [KO]
Script cache:clear returned with error code 1
!!
!!
!!  In FrameworkExtension.php line 1172:
!!
!!    Annotations cannot be enabled as the Doctrine Cache library is not installe
!!    d.
!!
!!
!!
!!

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

This is a problem in my opinion because installing php-cs-fixer shouldn't require additional packages to make the framework work when I have specifically not installed annotations using flex.

On a related note, it only reverts composer.json, but does not remove the auto-generated .php_cs.dist, changes to .gitignore nor the changes to composer.lock.

@xabbuh
Copy link
Member

xabbuh commented Oct 24, 2017

Are you sure that this is really related to this installation and not a consequence of a previously failing run (e.g. symfony/flex#194)? I don't see why the annotation cache should be enabled in the config just by the command you were running.

@nesl247
Copy link
Author

nesl247 commented Oct 24, 2017

Yes I'm sure. I actually deleted the entire vendor dir, made sure composer.lock was back at it's previous state, aka it's definitely enabled.

I see it's happening because of the default configuration. If I put annotations: false in framework.yaml, then the error goes away.

I also tested it to make sure:

$ composer create-project -s beta symfony/skeleton:4.0.x test
$ cd test
$ composer require --dev friendsofphp/php-cs-fixer:2.7.x-dev

@kamazee
Copy link
Contributor

kamazee commented Oct 24, 2017

Looks like fix for this recently landed to master #24658

@nesl247
Copy link
Author

nesl247 commented Oct 24, 2017

That simply adds doctrine/annotations to the top-level composer.json. The issue is that doctrine/cache is needed here to stop the error.

@weaverryan
Copy link
Member

This looks like a legit bug to me. As soon as the Annotations class is available, the annotations system defaults to enabled. But, then the default cache is php_array, which causes this error.

It seems to me that is the presence of the annotations lib activates the annotation system, and because doctrine/cache is optional, it should not fail if it is not there. I think we should default to “none” cache if Doctrine/cache is not present. See the Configration class.

@nicolas-grekas
Copy link
Member

Anyone willing to work on a PR to fix this one?

@sroze
Copy link
Contributor

sroze commented Oct 29, 2017

Fixed in #24743

fabpot added a commit that referenced this issue Oct 29, 2017
…cache is not present (sroze)

This PR was merged into the 3.4 branch.

Discussion
----------

[FrameworkBundle] Do not activate the cache if Doctrine's cache is not present

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #24683
| License       | MIT
| Doc PR        | ø

Annotations are automatically enabled when the `doctrine/annotations` package is around. These annotations are enabled with the `php_array` cache by default, which require `doctrine/cache`.

This PR allow this scenario to happen by disabling the annotation cache when `doctrine/cache` is not present.

Commits
-------

c5c7a23 Do not activate the cache if Doctrine's cache is not present
@fabpot fabpot closed this as completed Oct 29, 2017
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

8 participants