Skip to content

Commit

Permalink
Symfony filesystem dependency removed
Browse files Browse the repository at this point in the history
  • Loading branch information
eymengunay committed Jun 5, 2013
1 parent a8d5758 commit 7b3d5c6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
"php": ">=5.3.0",
"ext-zip": "*",
"ext-openssl": "*",
"jms/serializer": ">=0.11.0,<0.13-dev",
"symfony/filesystem": ">= 2.1.0"
"jms/serializer": ">=0.11.0,<0.14-dev"
},
"autoload": {
"psr-0": { "Passbook\\": "src/" }
Expand Down
32 changes: 18 additions & 14 deletions src/Passbook/PassFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Passbook\Certificate\WWDR;
use Passbook\Exception\FileException;
use JMS\Serializer\SerializerBuilder;
use Symfony\Component\Filesystem\Filesystem;

/**
* PassFactory - Creates .pkpass files
Expand Down Expand Up @@ -71,15 +70,9 @@ class PassFactory

/**
* Pass file extension
* @var array
*/
private $passExtension = '.pkpass';

/**
* Symfony filesystem component
* @var Symfony\Component\Filesystem\Filesystem
* @var string
*/
private $filesystem;
const PASS_EXTENSION = '.pkpass';

public function __construct($passTypeIdentifier, $teamIdentifier, $organizationName, $p12File, $p12Pass, $wwdrFile)
{
Expand All @@ -90,8 +83,6 @@ public function __construct($passTypeIdentifier, $teamIdentifier, $organizationN
// Create certificate objects
$this->p12 = new P12($p12File, $p12Pass);
$this->wwdr = new WWDR($wwdrFile);
// Filesystem
$this->filesystem = new Filesystem();
}

/**
Expand Down Expand Up @@ -203,7 +194,7 @@ public function package(PassInterface $pass)
}

// Zip pass
$zipFile = $outputPath . $pass->getSerialNumber() . $this->passExtension;
$zipFile = $outputPath . $pass->getSerialNumber() . self::PASS_EXTENSION;
$zip = new ZipArchive();
if (!$zip->open($zipFile, $this->override ? ZIPARCHIVE::OVERWRITE : ZipArchive::CREATE)) throw new FileException("Couldn't open zip file.");
if ($handle = opendir($passDir)) {
Expand All @@ -217,8 +208,21 @@ public function package(PassInterface $pass)
throw new FileException("Error reading pass directory");
}
$zip->close();
// Clean temporary pass directory
$this->filesystem->remove($passDir);
// Remove temporary pass directory
$this->rrmdir($passDir);
return new SplFileObject($zipFile);
}

/**
* Recursive folder remove
*
* @param string $dir
*/
private function rrmdir($dir) {
$files = array_diff(scandir($dir), array('.', '..'));
foreach ($files as $file) {
is_dir("$dir/$file") ? $this->rrmdir("$dir/$file") : unlink("$dir/$file");
}
return rmdir($dir);
}
}

0 comments on commit 7b3d5c6

Please sign in to comment.