php - Symfony Configuration Default Values -
i believe configuration correct want defaults redis port , scheme configurations option coming out nulls?
can see issue is?
here configuration.
/** * {@inheritdoc} */ public function getconfigtreebuilder() { $treebuilder = new treebuilder(); $rootnode = $treebuilder->root('company_name'); $rootnode ->children() ->arraynode('cache') ->children() ->arraynode('redis') ->adddefaultsifnotset() ->treatnulllike([ 'scheme' => 'tcp', 'port' => 6379, ]) ->children() ->scalarnode('scheme') ->defaultvalue('tcp') ->end() ->scalarnode('host') ->isrequired() ->cannotbeempty() ->end() ->integernode('port') ->defaultvalue(6379) ->end() ->end() ->end() ->end() ->end() ->end(); return $treebuilder; }
and here parameters.yml file
parameters: company_name: cache: redis: host: dev-sessionstore.companyname.com schema: ~ port: ~
console output:
$ php bin/console config:dump-reference companynamecachebundle # default configuration "companynamecachebundle" company_name: cache: redis: namespace: apps scheme: tcp host: ~ # required port: 6379 apcu: namespace: phpcache
i want scheme , port use default values what's causing them null?
i know old question stumbled upon while googling different issue , saw unanswered.
the issue specifying how null should treated entire redis
array, not scheme
, port
values. specify default values, because you're setting individual keys null need specify how null should treated each one:
/** * {@inheritdoc} */ public function getconfigtreebuilder() { // using array values need changed in 1 place $redisdefaults = [ 'scheme' => 'tcp', 'port' => 6379, ]; $treebuilder = new treebuilder(); $rootnode = $treebuilder->root('company_name'); $rootnode ->children() ->arraynode('cache') ->children() ->arraynode('redis') ->adddefaultsifnotset() ->treatnulllike($redisdefaults) ->children() ->scalarnode('scheme') ->defaultvalue($redisdefaults['scheme']) ->treatnulllike($redisdefaults['scheme']) // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->end() ->scalarnode('host') ->isrequired() ->cannotbeempty() ->end() ->integernode('port') ->defaultvalue($redisdefaults['port']) ->treatnulllike($redisdefaults['port']) // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->end() ->end() ->end() ->end() ->end() ->end(); return $treebuilder; }
there's typo in parameters file, should scheme
, not schema
Comments
Post a Comment