Skip to content

Commit 7b3d5c6

Browse files
committed
Symfony filesystem dependency removed
1 parent a8d5758 commit 7b3d5c6

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
"php": ">=5.3.0",
1616
"ext-zip": "*",
1717
"ext-openssl": "*",
18-
"jms/serializer": ">=0.11.0,<0.13-dev",
19-
"symfony/filesystem": ">= 2.1.0"
18+
"jms/serializer": ">=0.11.0,<0.14-dev"
2019
},
2120
"autoload": {
2221
"psr-0": { "Passbook\\": "src/" }

src/Passbook/PassFactory.php

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use Passbook\Certificate\WWDR;
1919
use Passbook\Exception\FileException;
2020
use JMS\Serializer\SerializerBuilder;
21-
use Symfony\Component\Filesystem\Filesystem;
2221

2322
/**
2423
* PassFactory - Creates .pkpass files
@@ -71,15 +70,9 @@ class PassFactory
7170

7271
/**
7372
* Pass file extension
74-
* @var array
75-
*/
76-
private $passExtension = '.pkpass';
77-
78-
/**
79-
* Symfony filesystem component
80-
* @var Symfony\Component\Filesystem\Filesystem
73+
* @var string
8174
*/
82-
private $filesystem;
75+
const PASS_EXTENSION = '.pkpass';
8376

8477
public function __construct($passTypeIdentifier, $teamIdentifier, $organizationName, $p12File, $p12Pass, $wwdrFile)
8578
{
@@ -90,8 +83,6 @@ public function __construct($passTypeIdentifier, $teamIdentifier, $organizationN
9083
// Create certificate objects
9184
$this->p12 = new P12($p12File, $p12Pass);
9285
$this->wwdr = new WWDR($wwdrFile);
93-
// Filesystem
94-
$this->filesystem = new Filesystem();
9586
}
9687

9788
/**
@@ -203,7 +194,7 @@ public function package(PassInterface $pass)
203194
}
204195

205196
// Zip pass
206-
$zipFile = $outputPath . $pass->getSerialNumber() . $this->passExtension;
197+
$zipFile = $outputPath . $pass->getSerialNumber() . self::PASS_EXTENSION;
207198
$zip = new ZipArchive();
208199
if (!$zip->open($zipFile, $this->override ? ZIPARCHIVE::OVERWRITE : ZipArchive::CREATE)) throw new FileException("Couldn't open zip file.");
209200
if ($handle = opendir($passDir)) {
@@ -217,8 +208,21 @@ public function package(PassInterface $pass)
217208
throw new FileException("Error reading pass directory");
218209
}
219210
$zip->close();
220-
// Clean temporary pass directory
221-
$this->filesystem->remove($passDir);
211+
// Remove temporary pass directory
212+
$this->rrmdir($passDir);
222213
return new SplFileObject($zipFile);
223214
}
215+
216+
/**
217+
* Recursive folder remove
218+
*
219+
* @param string $dir
220+
*/
221+
private function rrmdir($dir) {
222+
$files = array_diff(scandir($dir), array('.', '..'));
223+
foreach ($files as $file) {
224+
is_dir("$dir/$file") ? $this->rrmdir("$dir/$file") : unlink("$dir/$file");
225+
}
226+
return rmdir($dir);
227+
}
224228
}

0 commit comments

Comments
 (0)