1
0
mirror of https://github.com/splitbrain/php-archive.git synced 2025-01-16 21:18:26 +01:00

renamed FileInfo::match() to FileInfo::matchExpression()

In PHP8, `match` is a reserved keyword. In preparation this renames the
method. A fallback via __call() is provided which will trigger a
E_USER_NOTICE.
This commit is contained in:
Andreas Gohr 2020-10-13 14:41:15 +02:00
parent e84a33abed
commit d4cf2d9a2d
4 changed files with 38 additions and 11 deletions

View File

@ -37,6 +37,24 @@ class FileInfo
$this->setPath($path);
}
/**
* Handle calls to deprecated methods
*
* @param string $name
* @param array $arguments
* @return mixed
*/
public function __call($name, $arguments)
{
if($name === 'match') {
trigger_error('FileInfo::match() is deprecated, use FileInfo::matchExpression() instead.', E_USER_NOTICE);
return call_user_func_array([$this, $name], $arguments);
}
trigger_error('Call to undefined method FileInfo::'.$name.'()', E_USER_ERROR);
return null;
}
/**
* Factory to build FileInfo from existing file or directory
*
@ -324,7 +342,7 @@ class FileInfo
* @param string $exclude Regular expression of files to exclude
* @return bool
*/
public function match($include = '', $exclude = '')
public function matchExpression($include = '', $exclude = '')
{
$extract = true;
if ($include && !preg_match($include, $this->getPath())) {

View File

@ -158,7 +158,7 @@ class Tar extends Archive
$fileinfo->strip($strip);
// skip unwanted files
if (!strlen($fileinfo->getPath()) || !$fileinfo->match($include, $exclude)) {
if (!strlen($fileinfo->getPath()) || !$fileinfo->matchExpression($include, $exclude)) {
$this->skipbytes(ceil($header['size'] / 512) * 512);
continue;
}

View File

@ -142,7 +142,7 @@ class Zip extends Archive
$fileinfo->strip($strip);
// skip unwanted files
if (!strlen($fileinfo->getPath()) || !$fileinfo->match($include, $exclude)) {
if (!strlen($fileinfo->getPath()) || !$fileinfo->matchExpression($include, $exclude)) {
continue;
}

View File

@ -71,19 +71,28 @@ class FileInfoTest extends TestCase
$this->assertEquals('baz/bang', $fileinfo->getPath());
}
public function testMatch()
public function testMatchExpression()
{
$fileinfo = new FileInfo('foo/bar/baz/bang');
$this->assertTrue($fileinfo->match());
$this->assertTrue($fileinfo->match('/bang/'));
$this->assertFalse($fileinfo->match('/bark/'));
$this->assertTrue($fileinfo->matchExpression());
$this->assertTrue($fileinfo->matchExpression('/bang/'));
$this->assertFalse($fileinfo->matchExpression('/bark/'));
$this->assertFalse($fileinfo->match('', '/bang/'));
$this->assertTrue($fileinfo->match('', '/bark/'));
$this->assertFalse($fileinfo->matchExpression('', '/bang/'));
$this->assertTrue($fileinfo->matchExpression('', '/bark/'));
$this->assertFalse($fileinfo->match('/bang/', '/foo/'));
$this->assertTrue($fileinfo->match('/bang/', '/bark/'));
$this->assertFalse($fileinfo->matchExpression('/bang/', '/foo/'));
$this->assertTrue($fileinfo->matchExpression('/bang/', '/bark/'));
}
/**
* @expectedException \PHPUnit_Framework_Error_Notice
*/
public function testMatchDeprecation()
{
$fileinfo = new FileInfo('foo/bar/baz/bang');
$fileinfo->match('/bang/', '/bark/');
}
public function testFromPath()