When defining services using the configuration file, how can I pass a PHP constant (CURLAUTH_DIGEST
in this example) as a constructor argument?
I can't test it right now but I assume that:
services:
my_service:
class: "%my_service.class%"
arguments: [CURLAUTH_DIGEST]
Wouldn't work because CURLAUTH_DIGEST
is converted to a string
.
Here's a way to do this
Add a line in your config to include a .php
configuration
app/config/config.yml
imports:
- { resource: constants.php }
Create a new file constants.php
app/config/constants.php
<?php
$container->setParameter('curlauth.digest', CURLAUTH_DIGEST);
You can now access this constant in your service
@Bundle/Resources/config/services.yml
services:
my_service:
class: "%my_service.class%"
arguments: [%curlauth.digest%]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With