Skip to content

Commit 92c773f

Browse files
committed
Merge pull request #101 from JimmDiGrizli/master
fixed #100 : All basename are replaced.
2 parents cc70d16 + bcfdf63 commit 92c773f

File tree

6 files changed

+66
-6
lines changed

6 files changed

+66
-6
lines changed

src/Adapter/AbstractAdapter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Alchemy\Zippy\Archive\ArchiveInterface;
1717
use Alchemy\Zippy\Exception\InvalidArgumentException;
1818
use Alchemy\Zippy\Resource\ResourceManager;
19+
use Alchemy\Zippy\Resource\PathUtil;
1920
use Alchemy\Zippy\Adapter\VersionProbe\VersionProbeInterface;
2021
use Alchemy\Zippy\Exception\RuntimeException;
2122
use Alchemy\Zippy\Adapter\Resource\ResourceInterface;
@@ -246,6 +247,6 @@ private function makeTargetAbsolute($path)
246247
throw new InvalidArgumentException(sprintf('Target path %s is not writeable.', $directory));
247248
}
248249

249-
return realpath($directory).'/'.basename ($path);
250+
return realpath($directory).'/'.PathUtil::basename($path);
250251
}
251252
}

src/Resource/PathUtil.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/*
4+
* This file is part of Zippy.
5+
*
6+
* (c) Alchemy <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Alchemy\Zippy\Resource;
13+
14+
abstract class PathUtil
15+
{
16+
public static function basename($path)
17+
{
18+
return (false === $pos = strrpos(strtr($path, '\\', '/'), '/')) ? $path : substr($path, $pos + 1);
19+
}
20+
}

src/Resource/Resource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function getContextForProcessInSinglePlace()
8787
return null;
8888
}
8989

90-
if (basename($this->original) === $this->target) {
90+
if (PathUtil::basename($this->original) === $this->target) {
9191
return dirname($this->original);
9292
}
9393
}

src/Resource/TargetLocator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private function locateResource($resource)
6060
throw new TargetLocatorException($resource, 'Unable to retrieve path from resource');
6161
}
6262

63-
return basename($data['path']);
63+
return PathUtil::basename($data['path']);
6464
}
6565

6666
/**
@@ -86,7 +86,7 @@ private function locateString($context, $resource)
8686
return $this->getRelativePathFromContext($url['path'], $context);
8787
}
8888

89-
return basename($resource);
89+
return PathUtil::basename($resource);
9090
}
9191

9292
// resource is a local path
@@ -95,7 +95,7 @@ private function locateString($context, $resource)
9595

9696
return $this->getRelativePathFromContext($resource, $context);
9797
} else {
98-
return basename($resource);
98+
return PathUtil::basename($resource);
9999
}
100100
}
101101

tests/Tests/Resource/PathUtilTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Alchemy\Zippy\Tests\Resource;
4+
5+
use Alchemy\Zippy\Tests\TestCase;
6+
use Alchemy\Zippy\Resource\PathUtil;
7+
8+
class PathUtilTest extends TestCase
9+
{
10+
/**
11+
* @dataProvider providePathData
12+
*/
13+
public function testBasename($expected, $context)
14+
{
15+
$this->assertEquals($expected, PathUtil::basename($context));
16+
}
17+
18+
public function providePathData()
19+
{
20+
return array(
21+
array('file.ext', 'input/path/to/local/file.ext'),
22+
array('file.ext', 'input\path\to\local\file.ext'),
23+
array('file.ext', '\file.ext'),
24+
array('file.ext', 'file.ext'),
25+
array('Ängelholm.jpg', '/tmp/Ängelholm.jpg'),
26+
array('Ängelholm.jpg', '\tmp\Ängelholm.jpg'),
27+
array('Ängelholm.jpg', '\Ängelholm.jpg'),
28+
array('Ängelholm.jpg', 'Ängelholm.jpg'),
29+
array('я-utf8-name.jpg', '/tmp/я-utf8-name.jpg'),
30+
array('я-utf8-name.jpg', '\tmp\я-utf8-name.jpg'),
31+
array('я-utf8-name.jpg', 'я-utf8-name.jpg'),
32+
array('я-utf8-name.jpg', '/я-utf8-name.jpg'),
33+
array('logo.png', 'http://google.com/tmp/logo.png'),
34+
array('Ängelholm.png', 'http://google.com/city/Ängelholm.png'),
35+
array('Ängelholm.png', 'http://google.com/я/Ängelholm.png')
36+
);
37+
}
38+
}

tests/Tests/TestCase.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Alchemy\Zippy\Tests;
44

55
use Alchemy\Zippy\Adapter\AdapterInterface;
6+
use Alchemy\Zippy\Resource\PathUtil;
67
use Alchemy\Zippy\Resource\ResourceCollection;
78
use Alchemy\Zippy\Resource\Resource;
89
use Alchemy\Zippy\Adapter\VersionProbe\VersionProbeInterface;
@@ -120,6 +121,6 @@ protected function getExpectedAbsolutePathForTarget($target)
120121
throw new \InvalidArgumentException(sprintf('Unable to get the absolute path for %s', $target));
121122
}
122123

123-
return realpath($directory).'/'.basename($target);
124+
return realpath($directory).'/'.PathUtil::basename($target);
124125
}
125126
}

0 commit comments

Comments
 (0)