@@ -291,11 +291,33 @@ public function addMapping($key, $value)
291291 $ this  ->mappings [] = array ($ key , $ value );
292292 }
293293
294+  /** 
295+  * @param string $path 
296+  * @return string 
297+  */ 
298+  protected  function  removeLeadingSlash ($ path )
299+  {
300+  return  ltrim ($ path , '\\/ ' );
301+  }
302+ 
303+  /** 
304+  * @param string $path 
305+  * @return string 
306+  */ 
294307 protected  function  removeTrailingSlash ($ path )
295308 {
296309 return  rtrim ($ path , '\\/ ' );
297310 }
298311
312+  /** 
313+  * @param string $path 
314+  * @return string 
315+  */ 
316+  protected  function  removeLeadingAndTrailingSlash ($ path )
317+  {
318+  return  trim ($ path , '\\/ ' );
319+  }
320+ 
299321 /** 
300322 * Normalize mapping parameters using a glob wildcard. 
301323 * 
@@ -313,8 +335,8 @@ public function create($source, $dest)
313335 return ;
314336 }
315337
316-  $ sourcePath  = $ this  ->getSourceDir () . '/ '  . $ this  ->removeTrailingSlash ($ source );
317-  $ destPath  = $ this  ->getDestDir () . '/ '  . $ dest ;
338+  $ sourcePath  = $ this  ->getSourceDir () . '/ '  . $ this  ->removeLeadingSlash ($ source );
339+  $ destPath  = $ this  ->getDestDir () . '/ '  . $ this -> removeLeadingSlash ( $ dest) ;
318340
319341 /* List of possible cases, keep around for now, might come in handy again 
320342
@@ -350,9 +372,12 @@ public function create($source, $dest)
350372 $ matches  = glob ($ sourcePath );
351373 if  ($ matches ) {
352374 foreach  ($ matches  as  $ match ) {
353-  $ newDest  = substr ($ destPath  . '/ '  . basename ($ match ), strlen ($ this  ->getDestDir ()));
354-  $ newDest  = ltrim ($ newDest , '  \\/ ' );
355-  $ this  ->create (substr ($ match , strlen ($ this  ->getSourceDir ()) + 1 ), $ newDest );
375+  $ absolutePath  = sprintf ('%s/%s ' , $ this  ->removeTrailingSlash ($ destPath ), basename ($ match ));
376+  $ relativeDestination  = substr ($ absolutePath , strlen ($ this  ->getDestDir ())); //strip off dest dir 
377+  $ relativeDestination  = $ this  ->removeLeadingSlash ($ relativeDestination );
378+  $ relativeSource  = substr ($ match , strlen ($ this  ->getSourceDir ()) + 1 );
379+ 
380+  $ this  ->create ($ relativeSource , $ relativeDestination );
356381 }
357382 return  true ;
358383 }
0 commit comments