@@ -99,7 +99,8 @@ public function get($filename, $useLocalConfig = true, $forceReload = false)
9999 $ baseConfigPath = $ this ->pathResolver ->getBaseConfigPath ($ filename );
100100 $ this ->files [$ filename ] = $ this ->getFromPaths (
101101 $ baseConfigPath ,
102- $ localConfigPath
102+ $ localConfigPath ,
103+ $ useLocalConfig
103104 );
104105 }
105106
@@ -109,13 +110,14 @@ public function get($filename, $useLocalConfig = true, $forceReload = false)
109110 /**
110111 * Given core and local filenames, retrieve the configuration data.
111112 *
112- * @param string $defaultFile Full path to file containing default YAML
113- * @param string $customFile Full path to file containing local customizations
113+ * @param string $defaultFile Full path to file containing default YAML
114+ * @param string $customFile Full path to file containing local customizations
114115 * (may be null if no local file exists).
116+ * @param bool $useLocalConfig Use local configuration if available
115117 *
116118 * @return array
117119 */
118- protected function getFromPaths ($ defaultFile , $ customFile = null )
120+ protected function getFromPaths ($ defaultFile , $ customFile = null , $ useLocalConfig = true )
119121 {
120122 // Connect to the cache:
121123 $ cache = (null !== $ this ->cacheManager )
@@ -139,7 +141,7 @@ protected function getFromPaths($defaultFile, $customFile = null)
139141
140142 // Generate data if not found in cache:
141143 if ($ cache === false || !($ results = $ cache ->getItem ($ cacheKey ))) {
142- $ results = $ this ->parseYaml ($ customFile , $ defaultFile );
144+ $ results = $ this ->parseYaml ($ customFile , $ defaultFile, $ useLocalConfig );
143145 if ($ cache !== false ) {
144146 $ cache ->setItem ($ cacheKey , $ results );
145147 }
@@ -151,20 +153,28 @@ protected function getFromPaths($defaultFile, $customFile = null)
151153 /**
152154 * Process a YAML file (and its parent, if necessary).
153155 *
154- * @param string $file YAML file to load (will evaluate to null
156+ * @param string $file YAML file to load (will evaluate to null
155157 * if file does not exist).
156- * @param string $defaultParent Parent YAML file from which $file should
158+ * @param string $defaultParent Parent YAML file from which $file should
157159 * inherit (unless overridden by a specific directive in $file). None by
158160 * default.
161+ * @param bool $useLocalConfig Use local configuration if available
159162 *
160163 * @return array
161164 */
162- protected function parseYaml ($ file , $ defaultParent = null )
165+ protected function parseYaml ($ file , $ defaultParent = null , $ useLocalConfig = true )
163166 {
164167 // First load current file:
165168 $ results = (!empty ($ file ) && file_exists ($ file ))
166169 ? Yaml::parse (file_get_contents ($ file )) : [];
167170
171+ if (isset ($ results ['@parent_yaml ' ]) && isset ($ results ['@parent_config_name ' ])) {
172+ error_log (
173+ 'Cannot use both directives @parent_yaml and '
174+ . '@parent_config_name at the same time in one file. '
175+ );
176+ }
177+
168178 // Override default parent with explicitly-defined parent, if present:
169179 if (isset ($ results ['@parent_yaml ' ])) {
170180 // First try parent as absolute path, then as relative:
@@ -178,6 +188,22 @@ protected function parseYaml($file, $defaultParent = null)
178188 // Swallow the directive after processing it:
179189 unset($ results ['@parent_yaml ' ]);
180190 }
191+ // Override default parent with a named configuration, if present:
192+ if (isset ($ results ['@parent_config_name ' ])) {
193+ $ parentConfigName = $ results ['@parent_config_name ' ] . '.yaml ' ;
194+ $ defaultParent = $ useLocalConfig
195+ ? $ this ->pathResolver ->getLocalConfigPath ($ parentConfigName )
196+ : null ;
197+ if ($ defaultParent === null || !file_exists ($ defaultParent )) {
198+ $ defaultParent = $ this ->pathResolver ->getBaseConfigPath ($ parentConfigName );
199+ }
200+ if (!file_exists ($ defaultParent )) {
201+ $ defaultParent = null ;
202+ error_log ('Cannot find parent config: ' . $ parentConfigName );
203+ }
204+ // Swallow the directive after processing it:
205+ unset($ results ['@parent_config_name ' ]);
206+ }
181207 // Check for sections to merge instead of overriding:
182208 $ mergedSections = [];
183209 if (isset ($ results ['@merge_sections ' ])) {
0 commit comments