How to pass a PHP constant as service argument in Symfony 2?
constants, symfony, yaml
Solution
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%]
Problem
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`.