Skip to content

Commit e745c21

Browse files
aphofstedeOriHoch
authored andcommitted
Migrate from alchemy/zippy to chumper/zipper (#40)
* Migrate from alchemy/zippy to chumper/zipper * Make phpcs happy * Remove superfluous try-catch
1 parent d363405 commit e745c21

4 files changed

Lines changed: 15 additions & 12 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"php": ">=5.6",
77
"justinrainbow/json-schema": "^5.2",
88
"frictionlessdata/tableschema": "^0.1.9",
9-
"alchemy/zippy": "=0.3.5"
9+
"chumper/zipper": "1.0.x"
1010
},
1111
"require-dev": {
1212
"phpunit/phpunit": "^4.8.35",

src/Datapackages/BaseDatapackage.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use frictionlessdata\datapackage\Utils;
88
use frictionlessdata\datapackage\Validators\DatapackageValidator;
99
use frictionlessdata\datapackage\Exceptions\DatapackageValidationFailedException;
10-
use Alchemy\Zippy\Zippy;
10+
use Chumper\Zipper\Zipper;
1111

1212
abstract class BaseDatapackage implements \Iterator
1313
{
@@ -170,7 +170,7 @@ public function valid()
170170

171171
public function save($zip_filename)
172172
{
173-
$zippy = Zippy::load();
173+
$zipper = new Zipper();
174174
$base = tempnam(sys_get_temp_dir(), 'datapackage-zip-');
175175
$files = [
176176
'datapackage.json' => $base.'datapackage.json',
@@ -185,7 +185,8 @@ public function save($zip_filename)
185185
++$ri;
186186
}
187187
$this->saveDescriptor($files['datapackage.json']);
188-
$zippy->create($zip_filename, $files);
188+
/* @noinspection PhpUnhandledExceptionInspection Never occurs with our args */
189+
$zipper->make($zip_filename)->add($files)->close();
189190
foreach (array_values($files) as $file) {
190191
unlink($file);
191192
}

src/Factory.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use frictionlessdata\datapackage\Datapackages\BaseDatapackage;
66
use frictionlessdata\datapackage\Resources\BaseResource;
7-
use Alchemy\Zippy\Zippy;
7+
use Chumper\Zipper\Zipper;
88

99
/**
1010
* datapackage and resource have different classes depending on the corresponding profile
@@ -349,14 +349,16 @@ protected static function loadHttpZipSource($source)
349349

350350
protected static function loadFileZipSource($source)
351351
{
352-
$zippy = Zippy::load();
352+
$zipper = new Zipper();
353353
$tempdir = tempnam(sys_get_temp_dir(), 'datapackage-php');
354354
unlink($tempdir);
355355
mkdir($tempdir);
356356
register_shutdown_function(function () use ($tempdir) {Utils::removeDir($tempdir); });
357-
$zippy->open($source)->extract($tempdir);
357+
/* @noinspection PhpUnhandledExceptionInspection File existence is checked afterwards anyway */
358+
$zipper->make($source)->extractTo($tempdir);
359+
$zipper->close();
358360
if (!file_exists($tempdir.'/datapackage.json')) {
359-
throw new Exceptions\DatapackageInvalidSourceException('zip file must contain a datappackage.json file');
361+
throw new Exceptions\DatapackageInvalidSourceException('zip file must contain a datapackage.json file');
360362
}
361363

362364
return static::loadSource($tempdir.'/datapackage.json', $tempdir);

tests/DatapackageTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace frictionlessdata\datapackage\tests;
44

5-
use Alchemy\Zippy\Zippy;
5+
use Chumper\Zipper\Zipper;
66
use frictionlessdata\datapackage\Utils;
77
use frictionlessdata\datapackage\Validators\DatapackageValidationError;
88
use PHPUnit\Framework\TestCase;
@@ -465,14 +465,14 @@ public function testCreateEditDatapackageDescriptor()
465465

466466
$filename = tempnam(sys_get_temp_dir(), 'datapackage-php-tests-').'.zip';
467467
$package->save($filename);
468-
$zippy = Zippy::load();
468+
$zipper = new Zipper();
469469
$tempdir = sys_get_temp_dir().DIRECTORY_SEPARATOR.'datapackage-php-tests-zipdir';
470470
if (file_exists($tempdir)) {
471471
Utils::removeDir($tempdir);
472472
}
473473
mkdir($tempdir);
474-
$archive = $zippy->open($filename);
475-
$archive->extract($tempdir);
474+
$zipper->make($filename)->extractTo($tempdir);
475+
$zipper->close();
476476
unlink($filename);
477477
$tempdir = $tempdir.DIRECTORY_SEPARATOR;
478478
$this->assertEquals($expectedDatapackageDescriptor, json_decode(file_get_contents($tempdir.'datapackage.json')));

0 commit comments

Comments
 (0)