@@ -77,7 +77,13 @@ public function preset()
77
77
protected function get ()
78
78
{
79
79
if (! is_null ($ this ->path ) && $ this ->fileExists ((string ) $ this ->path )) {
80
- return tap (json_decode (file_get_contents ($ this ->path ), true ), function ($ configuration ) {
80
+ $ baseConfig = json_decode (file_get_contents ($ this ->path ), true );
81
+
82
+ if (isset ($ baseConfig ['extend ' ])) {
83
+ $ baseConfig = $ this ->resolveExtend ($ baseConfig );
84
+ }
85
+
86
+ return tap ($ baseConfig , function ($ configuration ) {
81
87
if (! is_array ($ configuration )) {
82
88
abort (1 , sprintf ('The configuration file [%s] is not valid JSON. ' , $ this ->path ));
83
89
}
@@ -99,4 +105,23 @@ protected function fileExists(string $path)
99
105
default => file_exists ($ path )
100
106
};
101
107
}
108
+
109
+ /**
110
+ * Resolve the file to extend.
111
+ *
112
+ * @param array<string, array<int, string>|string> $configuration
113
+ * @return array<string, array<int, string>|string>
114
+ */
115
+ private function resolveExtend (array $ configuration )
116
+ {
117
+ $ path = realpath (dirname ($ this ->path ).DIRECTORY_SEPARATOR .$ configuration ['extend ' ]);
118
+
119
+ $ extended = json_decode (file_get_contents ($ path ), true );
120
+
121
+ if (isset ($ extended ['extend ' ])) {
122
+ throw new \LogicException ('Pint configuration cannot extend from more than 1 file. ' );
123
+ }
124
+
125
+ return array_replace_recursive ($ extended , $ configuration );
126
+ }
102
127
}
0 commit comments