In a Symfony 3.1 application (which developement has been started on Symfony 2.7) I have this config item in config_prod.yml:
framework:
validation:
cache: validator.mapping.cache.doctrine.apc
To use this setup with PHP7 I needed to change this to:
framework:
validation:
cache: validator.mapping.cache.doctrine.apcu
Since Symfony 3.1 there is as well a new Cache component which for the system is configured like:
framework:
cache:
system: ???
and the official blog article states for it:
"cache.system is where Symfony components store their contents (e.g. the Serializer and Validator metadata) (...) If your server has APCu installed, the cache.system pool uses it. Otherwise, it falls back to the filesystem cache."
What I'd like to understand is whether the framework->validation->cache definition is still required or if that's part of the cache.system pool.
In later case - if I understand it correctly - framework->validation->cache could be removed and still an enabled APCu would cache validation annotations.
EDIT
If my assumption is correct then validations would be cached by the new Symfony ApcuAdapter and not by the Doctrine APC/U Cache anymore.
Based on the upgrade documentation:
"The framework.serializer.cache option and the service serializer.mapping.cache.apc have been deprecated. APCu should now be automatically used when available."
So this means indeed the old configuration can be deleted without any replacement as long as apcu is installed and enabled.
Related
I have symfony 5.2.3 project with a bunch of slow validation unit tests. I want validation constraints mapping to be cached.
Following docs https://symfony.com/doc/current/reference/configuration/framework.html#reference-validation-cache I have my validator.yaml as following (I have dumped it with cli, it is actually set to this):
framework:
validation:
enabled: true
email_validation_mode: html5
cache: cache.default_redis_provider
and cache.yaml:
framework:
cache:
app: cache.adapter.filesystem
default_redis_provider: '%env(REDIS_CACHE_URL)%'
But cache is not being written in my redis. I dig in and find out that Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory is being used for this. So I put some debug there and see that it is getting $cache = null from DI. I override it manually with
$cache = new RedisAdapter(new Client('redis://redis:6379?database=1'));
and my tests are working fast and cache is written and read.
What is going on? Does this validation.cache option even work? I can put any nonsence there and it wont even throw an error
I can't see your complete configuration, but have to set the value of REDIS_CACHE_URL in '.env' file.
In the docs for Symfony 4.4, for the 'secret' configuration option https://symfony.com/doc/4.4/reference/configuration/framework.html#secret, it mentions:
As with any other security-related parameter, it is a good practice to
change this value from time to time. However, keep in mind that
changing this value will invalidate all signed URIs and Remember Me
cookies. That’s why, after changing this value, you should regenerate
the application cache and log out all the application users.
Is this also the preferred practice for orocommerce production instances? Can I be sure that my application will still run the same after clearing and warming up the production cache?
I found no information about the involved processes in the orocommerce docs.
I am using OroCommerce version 4.1 with Symfony 4.4.
You can set the application secret using the environment variable ORO_SECRET, and changing the variable later in runtime will not affect the application cache at all.
Alternatively, if you don't want to use environment variables, you can hardcode the secret value in the parameters.yml file.
The "secret" is not documented in OroCommerce, because it's already mentioned in Symfony framework documentation.
As for the second question, clearing the cache on the production instance is not safe. You should put the application to the maintenance mode before doing that. The full procedure is described in the OroCommerce upgrade guide.
I have integrated symfony messenger bundle and i am trying to encode that message .
It was working in Symfony 3.4.4 version . However it is giving above error in Symfony 3.4.28 version.
I have traced in symfony serialzer component , it seems that jsonEncoder is not listing in serialzer.php and which is causing this issue.
What is the reason for excluding json encoder in symfony serializer component.
See below DoctrineTransportSender:
public function send(Envelope $envelope)
{
$encodedMessage = $this->encoder->encode($envelope);
}
//messenger configuration:
messenger:
transports:
# DSN: doctrine://$repository_alias/$queue_name
# most likely we do not need more repositories (unless there's a need for splitting MySQL table with messages)
main: "doctrine://default/test"
routing:
# message type to transport routes
Bundle\QueueBundle\Message\TestMessage: [ main ]
serializer:
enabled: true
Symfony Messenger switched to PHP's native serialization/deserialization by default. Using php serialization prevents problems, e.g. accidentally omitting properties from being serialized. It will also ensure the component can be used without Symfony Serializer, which is less of an issue with Symfony 3.4, but with Symfony 4 and Flex or when using the messenger outside of Symfony you would have to install this dependency manually leading to errors.
You can still use Symfony Serializer, but it has to be configured. Considering you are on Symfony 3.4 you will likely have to do this manually by providing an appropriate Serializer-instance to the TransportFactory, see:
https://github.com/symfony/symfony/blob/4.4/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php#L1751-L1757
In Symfony 4 you can use the configuration instead, see:
https://symfony.com/doc/current/messenger.html#serializing-messages
Thanks for the response.
I have resolved above issue by adding customized serializer instead of calling messenger serializer(Which includes encoding as well decoding) and it works fine
I am trying to do LDAP authentication, I currently have this type of error :
ServiceNotFoundException: The service
"security.firewall.map.context.main" has a dependency on a
non-existent service "form.csrf_provider".
Any help please ?
You need to enable csrf_protection in your configuration. Open config.yml and be sure that
framework:
csrf_protection: true
is present in your configuration.
The form.csrf_provider is deprecated and removed in Symfony 3.
Use security.csrf.token_manager instead.
My guess is that you are using a bundle that is not ready for symfony3.
Look at the README of your required bundles and to be sure they are compatibile.
See the 3.0 CHANGELOG for all deprecated features.
Update
It's the inverse. You are on a too old symfony version, which doesn't support the form.csrf_provider, and you are surely using a bundle that require it.
Look for adapt your requirements or your symfony version.
NOTE: You should really change your symfony version for a stable release.
Reading these docs:
Doctrine DBAL Configuration with Symfony
Doctrine ORM Configuration with Symfony
Doctrine Configuration with Symfony
I created this and added to /src/MyBundle/Resources/config/services.php of my generated bundle:
My Configuration code
But I get the error:
[Symfony\Component\DependencyInjection\Exception\LogicException]
Container extension "doctrine" is not registered
What more I missed to do? I probably have to add that I did NOT remove the default orm/dbal settings in /app/config/config.yml.
Also I have no idea what 'read' and what 'host'=>'from_user_config.db' is, I copied/pasted from a third-party application and how to inject db credentials from a separate file into this services.php?