I've been trying to install the cache/cache-bundle recipe into my symfony4 flex-configured project, but to no avail. I execute:
composer require cache/cache-bundle
And this is what I got on the shell:
Installing the cache-bundle generates a cache.yml file under config/packages/cache.yml, and its default content is:
cache:
session:
enabled: "%env(bool:SESSION_CACHE_ENABLED)%"
service_id: "cache.provider.default"
use_tagging: true
ttl: 7200
router:
enabled: "%env(bool:ROUTER_CACHE_ENABLED)%"
service_id: "cache.provider.default"
ttl: 86400
logging:
enabled: "%env(bool:APP_DEBUG)%"
logger: "logger"
level: "info"
The problematic line is the first "enabled" one. For some reason, Symfony or composer doesn't like that %env(bool:SESSION_CACHE_ENABLED)% and returns that error message:
Invalid type for path "cache.session.enabled". Expected boolean, but
got string.
SESSION_CACHE_ENABLED is a value introduced in the .env file of the project by composer in a block like this.
###> cache/cache-bundle ###
SESSION_CACHE_ENABLED=true
ROUTER_CACHE_ENABLED=false
###< cache/cache-bundle ###
Then, the question is if someone else has "suffered" this problem and found a fix or workaround to make this config work. My objective is to use this dependency in my mock project to cache arrays in memory to use them as a fake DB system.
I thought to open an issue about this, but since I'm not sure if this is a Simfony issue or just a problem in the recipe I preferred to ask here first.
And for the sake of completion, here's the list of current dependencies already in my project.
"require": {
"php": "^7.1.3",
"easycorp/easy-log-handler": "^1.0",
"friendsofsymfony/rest-bundle": "^2.3",
"hermes/bridge/common": "dev-master",
"hermes/common": "dev-master",
"jms/serializer": "^1.10",
"jms/serializer-bundle": "^2.3",
"ramsey/uuid": "^3.7",
"sensio/framework-extra-bundle": "^5.1",
"symfony/cache": "^4.0",
"symfony/console": "^4.0",
"symfony/framework-bundle": "^4.0",
"symfony/http-foundation": "^4.0",
"symfony/monolog-bundle": "^3.1",
"symfony/stopwatch": "^4.0",
"symfony/web-server-bundle": "^4.0",
"symfony/yaml": "^4.0"
},
"require-dev": {
"symfony/flex": "^1.0",
"symfony/dotenv": "^4.0"
}
I've seen questions about issues regarding booleans in dotenv files, but nothing conclusive for this question, I'm afraid.
Have you tried to get rid off the quotes around "%env(bool:SESSION_CACHE_ENABLED)%"?
Related
PHP Symfony Sylius on Windows 11 with docker
I launch a sylius:install and the 2 steps of 5 stop this : warning error
Step 2 of 5. Setting up the database.
-------------------------------------
Creating Sylius database for environment dev.
It appears that your database already exists.
Warning! This action will erase your database.
Would you like to reset it? (y/N) y
1/4 [░░░░░░░░ ] 25%
In ImagesRemoveListener.php line 40:
Attempted to call an undefined method named "getObjectManager" of class "Doctrine\ORM\Event\OnFlushEventArgs".
doctrine:migrations:migrate [--write-sql [WRITE-SQL]] [--dry-run] [--query-time] [--allow-no-migration] [--all-or-nothing [ALL-OR-NOTHING]] [--configuration CONFIGURATION] [--em EM] [--conn CONN] [--] [<version>]
I confirm have the Doctrine\ORM\Event\OnFlushEventArgs Class.
But nothing getObjectManager method into this.
This is the require of the composer :
"require": {
"php": "^8.0",
"sylius/paypal-plugin": "^1.2.1",
"sylius/sylius": "^1.12#dev",
"symfony/dotenv": "^5.4",
"symfony/flex": "^2.1"
},
"require-dev": {
"behat/behat": "^3.7",
"behat/mink-selenium2-driver": "^1.4",
"dmore/behat-chrome-extension": "^1.3",
"dmore/chrome-mink-driver": "^2.7",
"friends-of-behat/mink": "^1.8",
"friends-of-behat/mink-browserkit-driver": "^1.4",
"friends-of-behat/mink-debug-extension": "^2.0",
"friends-of-behat/mink-extension": "^2.4",
"friends-of-behat/page-object-extension": "^0.3",
"friends-of-behat/suite-settings-extension": "^1.0",
"friends-of-behat/symfony-extension": "^2.1",
"friends-of-behat/variadic-extension": "^1.3",
"lchrusciel/api-test-case": "^5.0",
"phpspec/phpspec": "^7.0",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "1.5.4",
"phpstan/phpstan-doctrine": "1.3.2",
"phpstan/phpstan-webmozart-assert": "^1.1",
"phpunit/phpunit": "^8.5",
"stripe/stripe-php": "^6.43",
"sylius-labs/coding-standard": "^4.0",
"symfony/browser-kit": "^5.4",
"symfony/debug-bundle": "^5.4",
"symfony/intl": "^5.4",
"symfony/web-profiler-bundle": "^5.4",
"polishsymfonycommunity/symfony-mocker-container": "^1.0"
},
The part dealing with doctrine into sylius/sylius vendor bundles composer.json file :
"doctrine/collections": "^1.6",
"doctrine/common": "^3.2",
"doctrine/dbal": "^2.7|^3.0",
"doctrine/doctrine-bundle": "^1.12 || ^2.0",
"doctrine/doctrine-migrations-bundle": "^3.0.1",
"doctrine/event-manager": "^1.1",
"doctrine/inflector": "^1.4 || ^2.0",
"doctrine/migrations": "^3.0",
"doctrine/orm": "^2.7",
"doctrine/persistence": "^2.3",
OnFlushEventArgs.php is part of doctrine/orm package. The 2.7 version.
Downgrade or update version of doctrine/orm ?
I cannot run symfony local server by command: php bin/console server:run.
I get error:
[Symfony\Component\Console\Exception\LogicException]
An option named "connection" already exists.
Dependencies in composer.json:
"require": {
"php": "^7.0, <7.4",
"composer/package-versions-deprecated": "^1.11",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/orm": "^2.5",
"incenteev/composer-parameter-handler": "^2.0",
"sensio/distribution-bundle": "^5.0.19",
"sensio/framework-extra-bundle": "^3.0.2",
"symfony/monolog-bundle": "^3.1.0",
"symfony/polyfill-apcu": "^1.0",
"symfony/swiftmailer-bundle": "^2.3.10",
"symfony/symfony": "3.3.*",
"twig/twig": "^1.0||^2.0"
},
"require-dev": {
"doctrine/data-fixtures": "^1.3",
"doctrine/doctrine-fixtures-bundle": "^2.3",
"liip/functional-test-bundle": "^1.8",
"phpunit/phpunit": "^6.3",
"sensio/generator-bundle": "^3.0",
"symfony/phpunit-bridge": "^3.0"
},
parameters.yml:
# This file is auto-generated during the composer install
parameters:
database_host: 127.0.0.1
database_port: 3306
database_name: tests
database_user: root
database_password: password
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
secret: ThisTokenIsNotSoSecretChangeIt
I think these parameters in parameters.yml used to work earlier.
I use mysql and also sqlite for tests.
I faced the same issue in a Symfony v4.2 project, without changing anything in my code base.
As already found in this issue https://github.com/doctrine/dbal/issues/4565
it appears in certain versions of the doctrine/doctrine-bundle package (in my case v1.11). The RunSqlDoctrineCommand.php from vendor adds the second option which causes the error.
If you can update your doctrine/doctrine-bundle package, you might be fine. In my case, an update or fix by package was not possible.
What can we do in that case?
What comes next is more a hack, than a real good solution, so use it at your own risk!
As statet in the commit from official repository: https://github.com/doctrine/DoctrineBundle/commit/86d2469d6be06d55ad7b9e2f076f6942476f2e87 (thanks to the guys in issue above)
I made a copy of the new RunSqlDoctrineCommand.php from that commit and save it in my project as dist/RunSqlDoctrineCommand.php.
In composer.json change the scripts sections as follows:
{
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd"
},
"doctrine-bugfix": [
"cp -f dist/RunSqlDoctrineCommand.php vendor/doctrine/doctrine-bundle/Command/Proxy/RunSqlDoctrineCommand.php"
],
"post-install-cmd": [
"#auto-scripts",
"#doctrine-bugfix"
],
"post-update-cmd": [
"#auto-scripts",
"#doctrine-bugfix"
]
}
}
This will just copy and override the original file in vendor directory on every composer install/update. This will only work on a unix/linux system, btw.
As said: Not the best solution, but it keeps your project in shape.
In this answer is there is a good explanation
in my case
composer update doctrine/doctrine-bundle
Inside (symfony project) vendor/doctrine/doctrine-bundle/Command/Proxy/RunSqlDoctrineCommand.php change configure function like below:
protected function configure()
{
parent::configure();
$this
->setName('doctrine:query:sql')
//->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'The
connection to use for this command')
->setHelp(<<<EOT
The <info>%command.name%</info> command executes the given SQL query and
outputs the results:
<info>php %command.full_name% "SELECT * FROM users"</info>
EOT
);
if ($this->getDefinition()->hasOption('connection')) {
return;
}
$this->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'The
connection to use for this command');
}
After a composer update to fix some vulnerabilities on package used by my application, I handle an error:
The service "sensio_framework_extra.controller.listener" has a dependency on a non-existent service "annotation_reader"
As suggested in this answer, I tried to add the doctrine/annotations package, but it doesn't solved my issue (package seems to be already installed).
λ composer require doctrine/annotations
Using version ^1.8 for doctrine/annotations
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Restricting packages listed in "symfony/symfony" to "4.2.*"
Nothing to install or update
Here is the packages used by my composer.json:
"require": {
"php": "^7.1.3",
"ext-ctype": "*",
"ext-fileinfo": "*",
"ext-iconv": "*",
"ext-json": "*",
"doctrine/doctrine-fixtures-bundle": "^3.1",
"ekyna/payum-monetico-bundle": "^1.5",
"gedmo/doctrine-extensions": "^2.4",
"knplabs/knp-paginator-bundle": "^3.0",
"payum/offline": "^1.5",
"payum/paypal-express-checkout-nvp": "^1.5",
"payum/payum-bundle": "^2.3",
"php-http/guzzle6-adapter": "^2.0",
"sensio/framework-extra-bundle": "^5.1",
"stof/doctrine-extensions-bundle": "^1.3",
"symfony/asset": "4.2.*",
"symfony/console": "4.2.*",
"symfony/dotenv": "4.2.*",
"symfony/expression-language": "4.2.*",
"symfony/flex": "^1.1",
"symfony/form": "4.2.*",
"symfony/framework-bundle": "4.2.*",
"symfony/monolog-bundle": "^3.1",
"symfony/orm-pack": "1.*",
"symfony/process": "4.2.*",
"symfony/security-bundle": "4.2.*",
"symfony/serializer-pack": "1.*",
"symfony/swiftmailer-bundle": "^3.1",
"symfony/templating": "4.2.*",
"symfony/translation": "4.2.*",
"symfony/twig-bundle": "4.2.*",
"symfony/validator": "4.2.*",
"symfony/web-link": "4.2.*",
"symfony/webpack-encore-bundle": "^1.4",
"symfony/yaml": "4.2.*",
"twig/extensions": "^1.5",
"vich/uploader-bundle": "^1.8"
},
"require-dev": {
"codeception/codeception": "^2.5",
"codeception/c3": "2.*",
"friendsofphp/php-cs-fixer": "^2.14",
"php-coveralls/php-coveralls": "^2.1",
"phpmd/phpmd": "2.*",
"squizlabs/php_codesniffer": "*",
"symfony/debug-pack": "*",
"symfony/maker-bundle": "^1.11",
"symfony/profiler-pack": "*",
"symfony/test-pack": "^1.0",
"symfony/web-server-bundle": "4.2.*"
}
Edit :
I'm using all the framework, I've manually dropped cache to be sure there is no problem. I rebooted my dev computer too. Finally, I went around the problem by deploying my github project in another directory and application works fine. I don't close this question because I want to find the problem if it occurs in production.
since doctrine (or doctrine/annotations) itself does not register services (why would it), I looked up the doctrine bundles and the doctrine/doctrine-bundle provides the annotation_reader service: https://github.com/doctrine/DoctrineBundle/blob/af8ac792c9b970ff2bc25b49ab9b31afd9e03dbf/Resources/config/orm.xml#L82
I ran into a very similar error (The service "doctrine.orm.default_annotation_metadata_driver" has a dependency on a non-existent service "annotation_reader".) while trying to create a new setup. I have some instructions documented and had tried to composer install ormfixtures (--dev) before doctrine. Once I did that in the right order, everything was working as expected.
My specific example is from Twilio's instructions, which have these commands in this order:
composer req --dev maker ormfixtures fakerphp/faker
composer req doctrine twig
It worked when I reversed them to be in this order:
composer req doctrine twig
composer req --dev maker ormfixtures fakerphp/faker
I Had the same issue after a composer update from Symfony 4.4.
It was because I have replace de "Doctrine\Common" with "Doctrine" from all the using instead of "Doctrine\Common\Persistence" with "Doctrine\Persistence".
In other term: no matters why you have this error, it come from a broken namespace in your code.
This is the official link of the SensioFrameworkExtraBundle: https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/index.html
Guzzle is outdated and so I installed instead via composer the recommended replacement
"guzzlehttp/guzzle": "^6.3",
I checked in the vendor directory and there is my guzzlehttp lib:
guzzlehttp, although I also still see the old guzzle even after deleting the whole vendor directory and doing composer update again.
However in my Appkernel.php I want to include now guzzlehttp instead of the old eightpoint guzzle as a Bundle and wonder how to do that.
The old syntax was like this:
new EightPoints\Bundle\GuzzleBundle\GuzzleBundle(),
I tried with
new GuzzleHttp\GuzzleBundle(),
But it isn't found. Do I miss another step? If yes which one?
Edit:
original composer.json where I want to replace guzzle with the guzzleHttp since this guzzle package seems to be abandoned:
"require": {
"php": ">=7.0",
"symfony/symfony": "2.8.*",
"doctrine/orm": "^2.4.8",
"doctrine/dbal": "<2.5",
"doctrine/doctrine-bundle": "~1.4",
"symfony/swiftmailer-bundle": "~2.3",
"symfony/monolog-bundle": "~2.4",
"sensio/distribution-bundle": "~5.0",
"sensio/framework-extra-bundle": "^3.0.2",
"incenteev/composer-parameter-handler": "~2.0",
"eightpoints/guzzle-bundle": "4.5.*",
"symfony/finder": "^2.8",
"jms/serializer-bundle": "^1.1",
"jms/di-extra-bundle": "~1.3",
"jms/aop-bundle": "~1.1",
"jms/cg": "~1.1",
"psr/cache": "~1.0",
"predis/predis": "1.*",
"snc/redis-bundle": "2.*",
"cache/predis-adapter": "*",
"willdurand/hateoas-bundle": "^1.0",
"hautelook/templated-uri-bundle": "^2.0",
"willdurand/rest-extra-bundle": "^1.0",
"friendsofsymfony/rest-bundle": "^1.7",
"friendsofsymfony/http-cache-bundle": "^1.0",
"avtonom/semaphore-bundle": "dev-master",
"symfony/stopwatch": "*"
},
"require-dev": {
"sensio/generator-bundle": "*",
"phpunit/phpunit": "*",
"phpunit/php-invoker": "*",
"squizlabs/php_codesniffer": "*",
"friendsofphp/php-cs-fixer": "*",
"diablomedia/phpunit-pretty-printer": "*"
},
....
The Guzzle lib does not provide any Symfony integration. Seems like you are using an old version of EightPointsGuzzleBundle.
Instead of requiring guzzlehttp/guzzle which is just a lib, do composer require eightpoints/guzzle-bundle and then in your AppKernel add
new EightPoints\Bundle\GuzzleBundle\EightPointsGuzzleBundle()
Maybe you should just update your bundle to a newer version.
I am trying to set up Symfony with the SonataUserBundle. User registration and login works fine. When I try to call up the /profile view, however I get the following error:
Attempted to call method "setCurrentUri" on class "Knp\Menu\MenuItem" in F:\<my project path>\vendor\sonata-project\user-bundle\Block\ProfileMenuBlockService.php line 91. Did you mean to call: "setCurrent"?
The last notice in the "event list" before the error is
INFO - [cms::renderBlock] block.id=53, block.type=sonata.user.block.menu
Has anyone encountered this error before and can provide information on how to resolve it?
TIA
Matt
What versions of KnpMenu and SonataBlockBundle are you using? Please check your composer.json to be sure.
The setCurrentUri method has been deprecated as of KnpMenu v. 2.0, and the composer.json of SonataBlockBundle does not require KnpMenu anywhere but in dev install. So, this leads to a possibility that you could have required a fresher version of knplabs/knp-menu-bundle that is not yet supported by Sonata bundle.
Try requiring knplabs/knp-menu-bundle in 1.1.x:
{
...
"require": {
"knplabs/knp-menu-bundle": "~1.1"
},
...
}
I encountered the same problem, but downgrade to Knpmenu version 1 is not possible for our project. Because of some code update the June 16th, it is now possible to use Sonata User Bundle and Knp Menu Version 2.
Please, have a look on my composer.json :
"require": {
"php": ">=5.3.9",
"symfony/symfony": "2.7.*",
"doctrine/orm": "^2.4.8",
"doctrine/doctrine-bundle": "~1.4",
"doctrine/doctrine-fixtures-bundle": "dev-master",
"doctrine/migrations": "dev-master",
"doctrine/doctrine-migrations-bundle": "dev-master",
"symfony/assetic-bundle": "~2.3",
"symfony/swiftmailer-bundle": "~2.3",
"symfony/monolog-bundle": "~2.4",
"sensio/distribution-bundle": "~4.0",
"sensio/framework-extra-bundle": "^3.0.2",
"incenteev/composer-parameter-handler": "~2.0",
"friendsofsymfony/user-bundle": "~1.3",
"friendsofsymfony/message-bundle": "^1.2",
"sonata-project/admin-bundle": "^2.3",
"sonata-project/doctrine-orm-admin-bundle": "^2.3",
"sonata-project/easy-extends-bundle": "^2.1",
"sonata-project/user-bundle": "dev-master",
"sonata-project/datagrid-bundle": "dev-master",
"sonata-project/block-bundle": "~2.2,>=2.2.7,<2.3",
"sonata-project/exporter": "^1.4",
"sonata-project/intl-bundle": "^2.2",
"knplabs/knp-menu-bundle": "~2.0",
"knplabs/knp-menu": "~2.0"
},
As you can see, sonata-project/user-bundle is under dev-master version and I had to add sonata-project/datagrid-bundle in dev-master
Hope to help developpers who want want to preserve KnpMenu V2 !
I had same issue, This is my solution that you can preserve KnpMenu V2.
-You change setCurrentUri to setCurrent (because KNP changed code) in C:\path\vendor\sonata-project\user-bundle\Block\ProfileMenuBlockService.php
-You can have this problem, Method "currentAncestor" for object "Knp\Menu\MenuItem" does not exist in Sonata
And this works for me.