{"action":"created","issue":{"url":"https://api.github.com/repos/symfony/symfony/issues/15270","labels_url":"https://api.github.com/repos/symfony/symfony/issues/15270/labels{/name}","comments_url":"https://api.github.com/repos/symfony/symfony/issues/15270/comments","events_url":"https://api.github.com/repos/symfony/symfony/issues/15270/events","html_url":"https://github.com/symfony/symfony/issues/15270","id":94901381,"number":15270,"title":"[config] Error occurs when the key attribute is removed from the child node and only a key named 'value' is left there","user":{"login":"zerustech","id":417412,"avatar_url":"https://avatars.githubusercontent.com/u/417412?v=3","gravatar_id":"","url":"https://api.github.com/users/zerustech","html_url":"https://github.com/zerustech","followers_url":"https://api.github.com/users/zerustech/followers","following_url":"https://api.github.com/users/zerustech/following{/other_user}","gists_url":"https://api.github.com/users/zerustech/gists{/gist_id}","starred_url":"https://api.github.com/users/zerustech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zerustech/subscriptions","organizations_url":"https://api.github.com/users/zerustech/orgs","repos_url":"https://api.github.com/users/zerustech/repos","events_url":"https://api.github.com/users/zerustech/events{/privacy}","received_events_url":"https://api.github.com/users/zerustech/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/symfony/symfony/labels/Config","name":"Config","color":"DDDDDD"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-07-14T09:12:37Z","updated_at":"2015-07-25T23:37:08Z","closed_at":null,"body":"When the key attribute is removed from a child node of a prototyped array node, if there is only one key named 'value' left in the child node, the child node will be degenerated from an array into a string.\r\nWhen processing the config tree, an 'Symfony\\Component\\Config\\Definition\\Exception\\InvalidTypeException' is thrown.\r\n\r\nThe root cause of this issue is: \r\nbefore the degeneration, the prototype of the child node is ArrayNode and the child node matches its prototype. After the degeneration, the child node has become a ScalarNode, but its prototype is still ArrayNode.\r\nI have created PR #14082 for this issue, but didn't receive any feedback yet.\r\n\r\nThe following example may reproduce this issue:\r\n\r\n```php\r\n<?php\r\n\r\n$loader = require_once __DIR__.'/app/autoload.php';\r\n\r\nuse Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder;\r\nuse Symfony\\Component\\Config\\Definition\\Processor;\r\nuse Symfony\\Component\\Yaml\\Parser as YamlParser;\r\n\r\n$builder = new TreeBuilder();\r\n$configs = array();\r\n$parser = new YamlParser();\r\n$files = array(__DIR__.'/attribute-as-key-left-value-only.yml');      \r\n          \r\n$root = $builder->root('app');\r\n$root\r\n    ->fixXmlConfig('parameter')\r\n    ->children()\r\n        ->arrayNode('parameters')\r\n            ->useAttributeAsKey('name')\r\n            ->prototype('array')\r\n                ->children()\r\n                    ->scalarNode('name')->end()\r\n                    ->scalarNode('value')->end()\r\n                ->end()\r\n        ->end()\r\n    ->end();\r\n\r\nforeach($files as $file)\r\n{\r\n    $config = $parser->parse(file_get_contents($file));\r\n    $configs[] = $config['app'];\r\n}\r\n\r\n$processor = new Processor();\r\n$tree = $builder->buildTree();\r\n$result = $processor->process($tree, $configs);\r\n```\r\n```yml\r\n# attribute-as-key-left-value-only.yml\r\napp:\r\n    parameters:\r\n        - name: server_name\r\n          value: web.local\r\n        - name: ip\r\n          value: 192.168.1.2\r\n        - name: username\r\n          value: admin\r\n        - name: password\r\n          value: password\r\n```"},"comment":{"url":"https://api.github.com/repos/symfony/symfony/issues/comments/124914923","html_url":"https://github.com/symfony/symfony/issues/15270#issuecomment-124914923","issue_url":"https://api.github.com/repos/symfony/symfony/issues/15270","id":124914923,"user":{"login":"zerustech","id":417412,"avatar_url":"https://avatars.githubusercontent.com/u/417412?v=3","gravatar_id":"","url":"https://api.github.com/users/zerustech","html_url":"https://github.com/zerustech","followers_url":"https://api.github.com/users/zerustech/followers","following_url":"https://api.github.com/users/zerustech/following{/other_user}","gists_url":"https://api.github.com/users/zerustech/gists{/gist_id}","starred_url":"https://api.github.com/users/zerustech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zerustech/subscriptions","organizations_url":"https://api.github.com/users/zerustech/orgs","repos_url":"https://api.github.com/users/zerustech/repos","events_url":"https://api.github.com/users/zerustech/events{/privacy}","received_events_url":"https://api.github.com/users/zerustech/received_events","type":"User","site_admin":false},"created_at":"2015-07-25T23:37:08Z","updated_at":"2015-07-25T23:37:08Z","body":"@xabbuh \r\nAssume the original data parsed from YAML is as follows:\r\n```php\r\narray(\r\n    'parameters' => array(\r\n        array(\r\n            'name' => 'name1', \r\n            'value' => 'value1'\r\n        ),\r\n        array(\r\n            'name' => 'name2',\r\n            'value' => 'value2'\r\n        )\r\n    )\r\n)\r\n```\r\nIf the 'parameters' node is defined as a prototyped array and its key attribute is 'name', then the data will be changed to:\r\n```php\r\narray(\r\n    'parameters' => array(\r\n        'name1' => array(\r\n            'value' => 'value1'\r\n        ),\r\n        'name2' => array(\r\n            'value' => 'value2'\r\n        )\r\n    )\r\n)\r\n```\r\nNow, because there is only one key named 'value' left in its child nodes, which is a special name as per the specification, the data is supposed to be further simplified to:\r\n```php\r\narray(\r\n    'parameters' => array(\r\n        'name1' => 'value1', \r\n        'name2' => 'value2'\r\n    )\r\n)\r\n```\r\nBut, if you try the example code I provided, an `Symfony\\Component\\Config\\Definition\\Exception\\InvalidTypeException` is thrown.\r\n\r\nI have addressed the root cause of this issue:\r\n1) The original prototype of node 'parameters' is an array node, which matches the type of its child nodes:\r\n```php\r\narray(\r\n    'parameters' => array(\r\n        array( // child node is array, prototype is array too\r\n            'name' => 'name1', \r\n            'value' => 'value1'\r\n        ),\r\n        ...\r\n    )\r\n)\r\n```\r\n2) After the data structure is simplified, the type of its child nodes is changed to scalar, but the prototype is still an array node:\r\n```php\r\narray(\r\n    'parameters' => array(\r\n        'name' => 'value1', // child node is scalar, but prototype is array\r\n        ...\r\n    )\r\n)\r\n```"}}