@@ -77,7 +77,13 @@ public function preset()
7777    protected  function  get ()
7878    {
7979        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 ) {
8187                if  (! is_array ($ configuration )) {
8288                    abort (1 , sprintf ('The configuration file [%s] is not valid JSON. ' , $ this  ->path ));
8389                }
@@ -99,4 +105,23 @@ protected function fileExists(string $path)
99105            default  => file_exists ($ path )
100106        };
101107    }
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+     }
102127}
0 commit comments