I have a concern with the following service in my project:
app.security.guardAuthenticatorLoginPassword:
class: AppBundle\Security\LoginPasswordAuthenticator
arguments: ["#router"]
app.jwt_token_authenticator:
class: AppBundle\Security\JwtAuthenticator
arguments: ['#doctrine.orm.entity_manager', '#lexik_jwt_authentication.encoder']
I feel that whatever I do it is not recognized by my program ..
I have been looking for a few hours already but I do not understand why it does not work. While I have both my LoginPasswordAuthenticator and JwtAuthenticator classes in the specified path ..
Thank you in advance for your help
Here is some potentials issues:
_ Clear the cache
_ Check if you didn't forget a 'use' for your differents classes
_ Give to your services a name (and why not an alias) and use it when you call your service:
app.security.guardAuthenticatorLoginPassword:
class: AppBundle\Security\LoginPasswordAuthenticator
arguments: ["#router"]
tags:
- { name: login.password.authenticator, alias: login.auth }
app.jwt_token_authenticator:
class: AppBundle\Security\JwtAuthenticator
arguments:['#doctrine.orm.entity_manager','#lexik_jwt_authentication.encoder']
tags:
- { name: security.authenticator, alias: security.auth }
Related
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
I configured service for using GetSetMethodNormalizer
services:
Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer:
arguments: [ '#Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface', '#serializer.name_converter.camel_case_to_snake_case' ]
tags: [serializer.normalizer]
And when I call $serializer->serialize() I got an empty array as a value for serialized date variable.
Could you please advise how it can be fixed?
The problem was in the priority of normalizers. Here is a solution:
services:
Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer:
arguments: ['#Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface', '#serializer.name_converter.camel_case_to_snake_case']
tags:
- { name: 'serializer.normalizer', priority: -1100 }
The new priority will put this normalizer right after all standard ones and serialization will works as expected.
I want to use custom namespace in our RedisAdapter to cache in our Symfony4 app. However, when i want to set arguments like this in our services.yaml;
cache.adapter.redis:
class: Symfony\Component\Cache\Adapter\RedisAdapter
arguments:
- '#Redis'
- 'app'
I see this error message:
Symfony\Component\Cache\Traits\RedisTrait::init() expects parameter 1 to be Redis, RedisArray, RedisCluster or Predis\ClientInterface, string given.
By the way, our cache config(config/packages/cache.yaml) is simple like below. So, how can I set namespace directly from any config?
cache:
app: cache.adapter.redis
default_redis_provider: 'redis://%env(REDIS_HOST)%:%env(REDIS_PORT)%'
I solved it with this config:
app.cache.adapter.redis:
parent: 'cache.adapter.redis'
public: true
autowire: true
autoconfigure: false
tags:
- {name: 'cache.pool', namespace: 'app'}
If you need the namespace to be interoperable with a third-party app,
you can take control over auto-generation by setting the namespace attribute of the cache.pool service tag.
For example, you can override the service definition of the adapter:
# config/services.yaml
services:
app.cache.adapter.redis:
parent: 'cache.adapter.redis'
tags:
- { name: 'cache.pool', namespace: 'my_custom_namespace' }
more details here: https://github.com/symfony/symfony-docs/pull/12527
This gives exception (Tags must be array, check YAML syntax):
services:
application.presentation.twig.extension.nullableDateTime:
class: AppBundle\Application\Presentation\Twig\Extension\NullableDateTime
tags: [twig.extension]
This does not:
services:
application.presentation.twig.extension.nullableDateTime:
class: AppBundle\Application\Presentation\Twig\Extension\NullableDateTime
tags:
- {name: twig.extension}
Why is that? The Symfony docs says to use [] for tags.
I have used the {} syntax somewhere else, maybe only one syntax is accepted?
https://symfony.com/doc/current/service_container/tags.html
I'm trying to set up AWS S3/Cloudfront to work with liipimaginebundle in Symfony, but I really have no idea what I'm doing.
So far I have tried the following documented here http://symfony.com/doc/current/bundles/LiipImagineBundle/cache-resolver/aws_s3.html:
Installed aws-sdk-php:
"require": {
"aws/aws-sdk-php": "^3.28",
}
Set up my parameters (with the correct values not this dummy data):
amazon.s3.key: "your-aws-key"
amazon.s3.secret: "your-aws-secret"
amazon.s3.bucket: "your-bucket.example.com"
amazon.s3.region: "your-bucket-region"
Set up a resolver (although I'm not sure what that even means).
"%amazon.s3.cache_bucket%" is in the documentation but the parameter doesn't exist so I used "%amazon.s3.bucket%" instead:
liip_imagine:
cache: profile_photos
resolvers:
profile_photos:
aws_s3:
client_config:
credentials:
key: "%amazon.s3.key%"
secret: "%amazon.s3.secret%"
region: "%amazon.s3.region%"
bucket: "%amazon.s3.bucket%"
get_options:
Scheme: https
put_options:
CacheControl: "max-age=86400"
Added these lines to create the services:
services:
acme.amazon_s3:
class: Aws\S3\S3Client
factory: Aws\S3\S3Client
arguments:
-
credentials: { key: "%amazon.s3.key%", secret: "%amazon.s3.secret%" }
region: "%amazon.s3.region%"
acme.imagine.cache.resolver.amazon_s3:
class: Liip\ImagineBundle\Imagine\Cache\Resolver\AwsS3Resolver
arguments:
- "#acme.amazon_s3"
- "%amazon.s3.bucket%"
tags:
- { name: "liip_imagine.cache.resolver", resolver: "amazon_s3" }
I'm currently getting this error when I run php bin/console server:run:
PHP Fatal error: Uncaught Symfony\Component\Debug\Exception\UndefinedFunctionException: Attempted to call function "S3Client" from namespace "Aws\S3". in /var/www/swing-polls/var/cache/dev/appDevDebugProjectContainer.php:360
I've tried half a dozen other configs/tutorials to no avail. If someone can point me in the right direction I'd be incredibly grateful.
Using the code provided at Simple S3 Symfony Service with a few tweaks, I've been able to get my images to upload to my s3 bucket, but I just don't know how to get liipimaginebundle work with them.
In vendor/liip/imagine-bundle/DependencyInjection/Compiler/ResolversCompilerPass.php you can see the CompilerPass is getting the value from "resolver" attribute of the tag and is using it to create a Reference object. This means the resolver should contain the id of a service.
Try replacing
tags:
- { name: "liip_imagine.cache.resolver", resolver: "amazon_s3" }
with
tags:
- { name: "liip_imagine.cache.resolver", resolver: "acme.amazon_s3" }