Skip to content

Commit

Permalink
Add exceptions for the official exit codes.
Browse files Browse the repository at this point in the history
  • Loading branch information
howtomakeaturn committed Mar 22, 2015
1 parent 150b536 commit a623291
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 3 deletions.
39 changes: 39 additions & 0 deletions examples/example3.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
require_once('../vendor/autoload.php');

use \Howtomakeaturn\PDFInfo\PDFInfo;

$whoops = new \Whoops\Run;
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
$whoops->register();

$pdf = new PDFInfo('files/EEE.pdf');

echo $pdf->title;
echo '<hr />';
echo $pdf->author;
echo '<hr />';
echo $pdf->creator;
echo '<hr />';
echo $pdf->producer;
echo '<hr />';
echo $pdf->creationDate;
echo '<hr />';
echo $pdf->modDate;
echo '<hr />';
echo $pdf->tagged;
echo '<hr />';
echo $pdf->form;
echo '<hr />';
echo $pdf->pages;
echo '<hr />';
echo $pdf->encrypted;
echo '<hr />';
echo $pdf->pageSize;
echo '<hr />';
echo $pdf->fileSize;
echo '<hr />';
echo $pdf->optimized;
echo '<hr />';
echo $pdf->PDFVersion;
echo '<hr />';
6 changes: 6 additions & 0 deletions src/Howtomakeaturn/PDFInfo/Exceptions/OpenOutputException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
namespace Howtomakeaturn\PDFInfo\Exceptions;

use \Exception;

class OpenOutputException extends Exception{};
6 changes: 6 additions & 0 deletions src/Howtomakeaturn/PDFInfo/Exceptions/OpenPDFException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
namespace Howtomakeaturn\PDFInfo\Exceptions;

use \Exception;

class OpenPDFException extends Exception{};
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

use \Exception;

class BaseException extends Exception{};
class OtherException extends Exception{};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
namespace Howtomakeaturn\PDFInfo\Exceptions;

use \Exception;

class PDFPermissionException extends Exception{};
10 changes: 8 additions & 2 deletions src/Howtomakeaturn/PDFInfo/PDFInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,14 @@ private function loadOutput()
// Surround with double quotes if file name has spaces
exec("$cmd $file", $output, $returnVar);

if ( $returnVar !== 0 ){
throw new Exceptions\BaseException();
if ( $returnVar === 1 ){
throw new Exceptions\OpenPDFException();
} else if ( $returnVar === 2 ){
throw new Exceptions\OpenOutputException();
} else if ( $returnVar === 3 ){
throw new Exceptions\PDFPermissionException();
} else if ( $returnVar === 99 ){
throw new Exceptions\OtherException();
}

$this->output = $output;
Expand Down

0 comments on commit a623291

Please sign in to comment.