Skip to content

Commit 32a1048

Browse files
committed
Merge pull request #147 from davidverholen/master
solves #146
2 parents e0c8e4a + a8f771d commit 32a1048

File tree

2 files changed

+77
-23
lines changed

2 files changed

+77
-23
lines changed

src/MagentoHackathon/Composer/Magento/Installer/MagentoInstallerAbstract.php

+35-22
Original file line numberDiff line numberDiff line change
@@ -604,41 +604,54 @@ public function annoy(IOInterface $io)
604604
}
605605

606606
/**
607-
* join 2 paths
607+
* joinFilePath
608608
*
609-
* @param $path1
610-
* @param $path2
611-
* @param $delimiter
612-
* @param bool $prependDelimiter
613-
* @param string $additionalPrefix
609+
* joins 2 Filepaths and replaces the Directory Separators
610+
* with the Systems Directory Separator
614611
*
615-
* @internal param $url1
616-
* @internal param $url2
612+
* @param $path1
613+
* @param $path2
617614
*
618615
* @return string
619616
*/
620-
protected function joinPath($path1, $path2, $delimiter, $prependDelimiter = false, $additionalPrefix = '')
617+
public function joinFilePath($path1, $path2)
621618
{
622-
$prefix = $additionalPrefix . $prependDelimiter ? $delimiter : '';
623-
624-
return $prefix . join(
625-
$delimiter,
626-
array(
627-
explode($path1, $delimiter),
628-
explode($path2, $delimiter)
619+
$prefix = $this->startsWithDs($path1) ? DIRECTORY_SEPARATOR : '';
620+
$suffix = $this->endsWithDs($path2) ? DIRECTORY_SEPARATOR : '';
621+
622+
return $prefix . implode(
623+
DIRECTORY_SEPARATOR,
624+
array_merge(
625+
preg_split('/\\\|\//', $path1, null, PREG_SPLIT_NO_EMPTY),
626+
preg_split('/\\\|\//', $path2, null, PREG_SPLIT_NO_EMPTY)
629627
)
630-
);
628+
) . $suffix;
631629
}
632630

633631
/**
634-
* @param $path1
635-
* @param $path2
632+
* startsWithDs
636633
*
637-
* @return string
634+
* @param $path
635+
*
636+
* @return bool
637+
*/
638+
protected function startsWithDs($path)
639+
{
640+
return strrpos($path, '/', -strlen($path)) !== FALSE
641+
|| strrpos($path, '\\', -strlen($path)) !== FALSE;
642+
}
643+
644+
/**
645+
* endsWithDs
646+
*
647+
* @param $path
648+
*
649+
* @return bool
638650
*/
639-
protected function joinFilePath($path1, $path2)
651+
protected function endsWithDs($path)
640652
{
641-
return $this->joinPath($path1, $path2, DIRECTORY_SEPARATOR, true);
653+
return strpos($path, '/', strlen($path) - 1) !== FALSE
654+
|| strpos($path, '\\', strlen($path) - 1) !== FALSE;
642655
}
643656

644657
/**

tests/MagentoHackathon/Composer/Magento/ModuleInstallerTest.php

+42-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class ModuleInstallerTest extends \PHPUnit_Framework_TestCase
1111
{
1212
/**
13-
* @var Installer
13+
* @var ModuleInstaller
1414
*/
1515
protected $object;
1616

@@ -239,6 +239,30 @@ public function parserTypeProvider()
239239
* translations are specified.
240240
*/
241241

242+
/**
243+
* joinFilePathsProvider
244+
*
245+
* @return array
246+
*/
247+
public function joinFilePathsProvider()
248+
{
249+
$ds = DIRECTORY_SEPARATOR;
250+
return array(
251+
array('app/etc/', '/modules', 'app'.$ds.'etc'.$ds.'modules'),
252+
array('app/etc/', 'modules', 'app'.$ds.'etc'.$ds.'modules'),
253+
array('app/etc', 'modules', 'app'.$ds.'etc'.$ds.'modules'),
254+
array('/app/etc', '/modules', $ds.'app'.$ds.'etc'.$ds.'modules'),
255+
array('/app/etc/', '/modules', $ds.'app'.$ds.'etc'.$ds.'modules'),
256+
array('/app/etc', 'modules/', $ds.'app'.$ds.'etc'.$ds.'modules'.$ds),
257+
array('app\\etc\\', '\\modules', 'app'.$ds.'etc'.$ds.'modules'),
258+
array('app\\etc\\', 'modules', 'app'.$ds.'etc'.$ds.'modules'),
259+
array('app\\etc', 'modules', 'app'.$ds.'etc'.$ds.'modules'),
260+
array('\\app\\etc', '\\modules', $ds.'app'.$ds.'etc'.$ds.'modules'),
261+
array('\\app\\etc\\', '\\modules', $ds.'app'.$ds.'etc'.$ds.'modules'),
262+
array('\\app\\etc', 'modules\\', $ds.'app'.$ds.'etc'.$ds.'modules'.$ds)
263+
);
264+
}
265+
242266
protected function createPathMappingTranslationMock()
243267
{
244268
return $this->createPackageMock(
@@ -345,5 +369,22 @@ public function testMediaPathMappingTranslation2()
345369
$this->assertContains(array('src2/media/images', './media/examplename_images'), $mappings);
346370
}
347371

372+
/**
373+
* testJoinFilePaths
374+
*
375+
* @param $path1
376+
* @param $path2
377+
* @param $expected
378+
*
379+
* @return void
380+
*
381+
* @dataProvider joinFilePathsProvider
382+
* @covers MagentoHackathon\Composer\Magento\Installer\ModuleInstaller::joinFilePaths
383+
*/
384+
public function testJoinFilePaths($path1, $path2, $expected)
385+
{
386+
$this->assertEquals($expected, $this->object->joinFilePath($path1, $path2));
387+
}
388+
348389
}
349390

0 commit comments

Comments
 (0)