+ $this->parseDirectory( '', $info['node'], $config );
+ return $config;
+ }
+
+ /**
+ * Recursively parse a directory node and populate the array passed by
+ * reference, throwing EtcdConfigParseError if there is a validation error
+ *
+ * @param string $dirName The relative directory name
+ * @param array $dirNode The decoded directory node
+ * @param array &$config The output array
+ */
+ protected function parseDirectory( $dirName, $dirNode, &$config ) {
+ if ( !isset( $dirNode['nodes'] ) ) {
+ throw new EtcdConfigParseError(
+ "Unexpected JSON response in dir '$dirName'; missing 'nodes' list." );
+ }
+ if ( !is_array( $dirNode['nodes'] ) ) {
+ throw new EtcdConfigParseError(
+ "Unexpected JSON response in dir '$dirName'; 'nodes' is not an array." );
+ }
+
+ foreach ( $dirNode['nodes'] as $node ) {
+ $baseName = basename( $node['key'] );
+ $fullName = $dirName === '' ? $baseName : "$dirName/$baseName";