Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Alchemy\Zippy\Archive\ArchiveInterface;
use Alchemy\Zippy\Exception\InvalidArgumentException;
use Alchemy\Zippy\Resource\ResourceManager;
use Alchemy\Zippy\Resource\PathUtil;
use Alchemy\Zippy\Adapter\VersionProbe\VersionProbeInterface;
use Alchemy\Zippy\Exception\RuntimeException;
use Alchemy\Zippy\Adapter\Resource\ResourceInterface;
Expand Down Expand Up @@ -246,6 +247,6 @@ private function makeTargetAbsolute($path)
throw new InvalidArgumentException(sprintf('Target path %s is not writeable.', $directory));
}

return realpath($directory).'/'.basename ($path);
return realpath($directory).'/'.PathUtil::basename($path);
}
}
20 changes: 20 additions & 0 deletions src/Resource/PathUtil.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/*
* This file is part of Zippy.
*
* (c) Alchemy <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Alchemy\Zippy\Resource;

abstract class PathUtil
{
public static function basename($path)
{
return (false === $pos = strrpos(strtr($path, '\\', '/'), '/')) ? $path : substr($path, $pos + 1);
}
}
2 changes: 1 addition & 1 deletion src/Resource/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function getContextForProcessInSinglePlace()
return null;
}

if (basename($this->original) === $this->target) {
if (PathUtil::basename($this->original) === $this->target) {
return dirname($this->original);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Resource/TargetLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private function locateResource($resource)
throw new TargetLocatorException($resource, 'Unable to retrieve path from resource');
}

return basename($data['path']);
return PathUtil::basename($data['path']);
}

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

return basename($resource);
return PathUtil::basename($resource);
}

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

return $this->getRelativePathFromContext($resource, $context);
} else {
return basename($resource);
return PathUtil::basename($resource);
}
}

Expand Down
38 changes: 38 additions & 0 deletions tests/Tests/Resource/PathUtilTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Alchemy\Zippy\Tests\Resource;

use Alchemy\Zippy\Tests\TestCase;
use Alchemy\Zippy\Resource\PathUtil;

class PathUtilTest extends TestCase
{
/**
* @dataProvider providePathData
*/
public function testBasename($expected, $context)
{
$this->assertEquals($expected, PathUtil::basename($context));
}

public function providePathData()
{
return array(
array('file.ext', 'input/path/to/local/file.ext'),
array('file.ext', 'input\path\to\local\file.ext'),
array('file.ext', '\file.ext'),
array('file.ext', 'file.ext'),
array('Ängelholm.jpg', '/tmp/Ängelholm.jpg'),
array('Ängelholm.jpg', '\tmp\Ängelholm.jpg'),
array('Ängelholm.jpg', '\Ängelholm.jpg'),
array('Ängelholm.jpg', 'Ängelholm.jpg'),
array('я-utf8-name.jpg', '/tmp/я-utf8-name.jpg'),
array('я-utf8-name.jpg', '\tmp\я-utf8-name.jpg'),
array('я-utf8-name.jpg', 'я-utf8-name.jpg'),
array('я-utf8-name.jpg', '/я-utf8-name.jpg'),
array('logo.png', 'http://google.com/tmp/logo.png'),
array('Ängelholm.png', 'http://google.com/city/Ängelholm.png'),
array('Ängelholm.png', 'http://google.com/я/Ängelholm.png')
);
}
}
3 changes: 2 additions & 1 deletion tests/Tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Alchemy\Zippy\Tests;

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

return realpath($directory).'/'.basename($target);
return realpath($directory).'/'.PathUtil::basename($target);
}
}