@@ -291,11 +291,33 @@ public function addMapping($key, $value)
291
291
$ this ->mappings [] = array ($ key , $ value );
292
292
}
293
293
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
+ */
294
307
protected function removeTrailingSlash ($ path )
295
308
{
296
309
return rtrim ($ path , '\\/ ' );
297
310
}
298
311
312
+ /**
313
+ * @param string $path
314
+ * @return string
315
+ */
316
+ protected function removeLeadingAndTrailingSlash ($ path )
317
+ {
318
+ return trim ($ path , '\\/ ' );
319
+ }
320
+
299
321
/**
300
322
* Normalize mapping parameters using a glob wildcard.
301
323
*
@@ -313,8 +335,8 @@ public function create($source, $dest)
313
335
return ;
314
336
}
315
337
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) ;
318
340
319
341
/* List of possible cases, keep around for now, might come in handy again
320
342
@@ -350,9 +372,12 @@ public function create($source, $dest)
350
372
$ matches = glob ($ sourcePath );
351
373
if ($ matches ) {
352
374
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 );
356
381
}
357
382
return true ;
358
383
}
0 commit comments