JMSSecuritybundle throwing "security.expressions.expression" defined for definition "security.expressions.expression - symfony

i recently configured JMSSecurityExtraBundle and when i try to add an expression to my firewall rules it throws me this error:
Fatal error: Uncaught exception
'Symfony\Component\DependencyInjection\Exception\RuntimeException'
with message 'The parent definition "security.expressions.expression"
defined for definition
"security.expressions.expression.3b9a3b9db79b52922a36b870bc46e5b114425575"
does not exist.'
I followed the exact description as described on this page:
http://jmsyst.com/bundles/JMSSecurityExtraBundle/master/installation
This is when the error occurs:
security:
access_control:
- { path: ^/foo, access: "hasRole('FOO') and hasRole('BAR')" }

You have to activate the expressions for it to work.
add
jms_security_extra:
expressions: true
to your config.yml and try it out

Related

Tags support is not enabled. You must use the flag "Yaml::PARSE_CUSTOM_TAGS" to use "!service_locator"

I am trying to add the webpack-encore-bundle to my Drupal site, I have this in services.yml file:
services:
webpack_encore.twig_entry_files_extension:
class: Symfony\WebpackEncoreBundle\Twig\EntryFilesTwigExtension
arguments:
['#service_container']
tags:
- { name: twig.extension }
webpack_encore.tag_renderer:
class: Symfony\WebpackEncoreBundle\Asset\TagRenderer
tags:
- { name: kernel.reset}
arguments:
['#webpack_encore.entrypoint_lookup_collection', '#assets.packages']
assets.packages:
class: Symfony\Component\Asset\Packages
webpack_encore.default_entrypoint:
class: Symfony\WebpackEncoreBundle\Asset\EntrypointLookup
arguments:
- 'web/themes/custom/mytheme_base/public/build/entrypoints.json'
webpack_encore.entrypoint_lookup_collection:
class: Symfony\WebpackEncoreBundle\Asset\EntrypointLookupCollection
arguments:
- !service_locator
_default: '#webpack_encore.default_entrypoint'
But I am getting this error:
In YamlSymfony.php line 40:
Tags support is not enabled. You must use the flag "Yaml::PARSE_CUSTOM_TAGS" to use "!service_locator" at line 27 (near "!service_locator").
In Parser.php line 1157:
Tags support is not enabled. You must use the flag "Yaml::PARSE_CUSTOM_TAGS" to use "!service_locator" at line 27 (near "!service_locator").
Do you know how to fix it?
If using custom tags in your code : see Symfony documentation : https://symfony.com/doc/5.4/components/yaml.html#parsing-and-dumping-custom-tags
If you are getting this error when running bin/console.php lint:yaml my/repository, try running it with the option "--parse-tags" : bin/console.php lint:yaml --parse-tags my/repository

Symfony 3.4 - Autowire not working for bind values?

I am working on migrating an existing Symfony 2.8 project to Symfony 3.4 and would like to autowire / auto inject the value of the %kernel.environment% parameter into a controller action.
However binding the parameter to a argument name does not work:
// app/config/services.yml
services:
_defaults:
autowire: true
autoconfigure: true
public: false
bind:
$kernelEnvironment: '%kernel.environment%'
MyBundle\:
resource: '../../src/MyBundle/*'
exclude: '../../src/MyBundle/{Entity,Repository,Tests}'
MyBundle\Controller\:
resource: '../../src/MyBundle/Controller'
tags: ['controller.service_arguments']
// src/MyBundle/SomeController.php
public function showPostAction($kernelEnvironment, $post_id) {
...
}
Uncaught PHP Exception RuntimeException: "Controller "MyBundle\Controller\SomeController::showPostAction()" requires that you provide a value for the "$kernelEnvironment" argument. Either the argument is nullable and no null value has been provided, no default value has been provided or because there is a non optional argument after this one."
Why does this not work?
I know that I could specify MyBundle\Controller\SomeController directly within in the services.yml and set the value of $kernelEnvironment in the arguments list. However this solution would mean that I would have to specify the argument for every controller that uses this parameter. This is is not what autorwire is good for. Binding the argument should work, shouldn't it?

Problems with Geoplugin in Symfony 3.4

I am trying to upgrading my existing Symfony 2.8 web site to 3.4.
I have faced and fixed many issues but I am stuck with a Geoplugin issue.
I have updated like the following my AppBundle/Resources/config/services.yml to respect the new YAML directives (thus I have added '' around #variables) :
app.ipgeo:
class: AppBundle\Utils\Geo\Geoplugin
arguments: ['#request', '#doctrine.orm.entity_manager', '#service_container']
scope: request
tags:
- { name: kernel.event_listener, event: kernel.controller, method: onLoad }
But I get a PHP Fatal error when accessing the web site :
AH01071: Got error 'PHP message: PHP Fatal error: Call to a member function getUri() on string in /var/www/vhosts/alpclic-dev.fr/httpdocs/dev.scenes-locales.com/src/AppBundle/Utils/Geo/Geoplugin.php on line 58
PHP message: PHP Fatal error: Call to a member function getUri() on string in
/var/www/vhosts/alpclic-dev.fr/httpdocs/dev.scenes-locales.com/src/AppBundle/Utils/Geo/Geoplugin.php
on line 58\n'
Any idea ?
Of course, it was perfectly working in 2.8 with the following configuration :
app.ipgeo:
class: AppBundle\Utils\Geo\Geoplugin
arguments: [#request, #doctrine.orm.entity_manager, #service_container]
scope: request
tags:
- { name: kernel.event_listener, event: kernel.controller, method: onLoad }
Not so easy and "self-explanatory" !
I had to migrate to 'request_stack' service as mentioned here : How to inject the #request into a service?

Symfony2 InvalidArgumentException in routing.yml

i have created these routes in src/Dive/LogbookBundle/Resources/config/routing.yml:
login:
path: /
defaults: { _controller: DiveLogbookBundle:Security:login }
login_check:
pattern: /login_check
random:
path: /random/{limit}
defaults: { _controller: DiveLogbookBundle:Random:index }
but when i access the webpage it returns an error:
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'The definition of "login" in "/var/www/src/Dive/LogbookBundle/Resources/config/routing.yml" must be a YAML array.' in /var/www/vendor/symfony/symfony/src/Symfony/Component/Routing/Loader/YamlFileLoader.php:190
Stack trace:
#0 /var/www/vendor/symfony/symfony/src/Symfony/Component/Routing/Loader/YamlFileLoader.php(88): Symfony\Component\Routing\Loader\YamlFileLoader->validate(NULL, 'login', '/var/www/src/Di...')
#1 /var/www/vendor/symfony/symfony/src/Symfony/Component/Config/Loader/FileLoader.php(106): Symfony\Component\Routing\Loader\YamlFileLoader->load('/var/www/src/Di...', NULL)
#2 /var/www/vendor/symfony/symfony/src/Symfony/Component/Routing/Loader/YamlFileLoader.php(155): Symfony\Component\Config\Loader\FileLoader->import('#DiveLogbookBun...', NULL, false, '/var/www/app/co...')
#3 /var/www/vendor/symfony/symfony/src/Symfony/Component/Routing/Loader/YamlFileLoader.php(91): Symfony\Component\Routing\Loader\YamlFileLoader->parseImport(Object(Symfony in /var/www/app/bootstrap.php.cache on line 2986
Does anyone know what causes this problem and how can i resolve this?
Thanks in advance.
Check the formatting of your routing.yml. YAML has quite strict standards regarding whitespace, and should not contain any tab characters - all indentation must be done with spaces. Make sure you have indented everything correctly and maybe do a search and replace for \t if your code editor allows.
Just for the record: the linter can be used to spot the problem immediately php app/console lint:yaml <file_to_lint.yml>

Symfony 2 ScannerException #(64)

I'm getting following exception in my app/config/config.yml file:
ScannerException while scanning for the next token we had this found
character #(64) that cannot start any token
The line that causes exception:- { resource: #BazaBlogBundle/Resources/config/config.yml }
I think it's compatibility problem. I'm following tutorial for Symfony version 2.0 and I'm using 2.16. Any thoughts?
I think you are missing the double quotes :
- { resource: "#BazaBlogBundle/Resources/config/config.yml" }

Resources