OSDN Git Service

keep unknown config values in memory
authorscribu <mail@scribu.net>
Sat, 23 Nov 2013 10:51:17 +0000 (12:51 +0200)
committerscribu <mail@scribu.net>
Sat, 23 Nov 2013 11:10:06 +0000 (13:10 +0200)
php/WP_CLI/Configurator.php
php/WP_CLI/Runner.php

index 283e0eb..e3b178f 100644 (file)
@@ -5,7 +5,9 @@ namespace WP_CLI;
 class Configurator {
 
        private $spec;
+
        private $config = array();
+       private $extra_config = array();
 
        function __construct( $path ) {
                $this->spec = include $path;
@@ -26,7 +28,7 @@ class Configurator {
        }
 
        function to_array() {
-               return $this->config;
+               return array( $this->config, $this->extra_config );
        }
 
        /**
@@ -85,16 +87,21 @@ class Configurator {
        }
 
        function merge_yml( $path ) {
-               $this->merge_config( self::load_yml( $path ), 'file' );
+               foreach ( self::load_yml( $path ) as $key => $value ) {
+                       if ( !isset( $this->spec[ $key ] ) || false === $this->spec[ $key ]['file'] ) {
+                               $this->extra_config[ $key ] = $value;
+                       } elseif ( $this->spec[ $key ]['multiple'] ) {
+                               self::arrayify( $value );
+                               $this->config[ $key ] = array_merge( $this->config[ $key ], $value );
+                       } else {
+                               $this->config[ $key ] = $value;
+                       }
+               }
        }
 
        function merge_array( $config ) {
-               $this->merge_config( $config, 'runtime' );
-       }
-
-       private function merge_config( $config, $type ) {
                foreach ( $this->spec as $key => $details ) {
-                       if ( false !== $details[ $type ] && isset( $config[ $key ] ) ) {
+                       if ( false !== $details['runtime'] && isset( $config[ $key ] ) ) {
                                $value = $config[ $key ];
 
                                if ( $details['multiple'] ) {
index 25f6c0b..a66ed04 100644 (file)
@@ -8,7 +8,9 @@ use WP_CLI\Utils;
 
 class Runner {
 
-       private $global_config_path, $project_config_path, $config;
+       private $global_config_path, $project_config_path;
+
+       private $config, $extra_config;
 
        private $arguments, $assoc_args;
 
@@ -379,7 +381,7 @@ class Runner {
                        $configurator->merge_array( $runtime_config );
                }
 
-               $this->config = $configurator->to_array();
+               list( $this->config, $this->extra_config ) = $configurator->to_array();
 
                if ( !isset( $this->config['path'] ) ) {
                        $this->config['path'] = dirname( Utils\find_file_upward( 'wp-load.php' ) );