Skip to content

Commit a623291

Browse files
Add exceptions for the official exit codes.
1 parent 150b536 commit a623291

File tree

6 files changed

+66
-3
lines changed

6 files changed

+66
-3
lines changed

examples/example3.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
require_once('../vendor/autoload.php');
3+
4+
use \Howtomakeaturn\PDFInfo\PDFInfo;
5+
6+
$whoops = new \Whoops\Run;
7+
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
8+
$whoops->register();
9+
10+
$pdf = new PDFInfo('files/EEE.pdf');
11+
12+
echo $pdf->title;
13+
echo '<hr />';
14+
echo $pdf->author;
15+
echo '<hr />';
16+
echo $pdf->creator;
17+
echo '<hr />';
18+
echo $pdf->producer;
19+
echo '<hr />';
20+
echo $pdf->creationDate;
21+
echo '<hr />';
22+
echo $pdf->modDate;
23+
echo '<hr />';
24+
echo $pdf->tagged;
25+
echo '<hr />';
26+
echo $pdf->form;
27+
echo '<hr />';
28+
echo $pdf->pages;
29+
echo '<hr />';
30+
echo $pdf->encrypted;
31+
echo '<hr />';
32+
echo $pdf->pageSize;
33+
echo '<hr />';
34+
echo $pdf->fileSize;
35+
echo '<hr />';
36+
echo $pdf->optimized;
37+
echo '<hr />';
38+
echo $pdf->PDFVersion;
39+
echo '<hr />';
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
namespace Howtomakeaturn\PDFInfo\Exceptions;
3+
4+
use \Exception;
5+
6+
class OpenOutputException extends Exception{};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
namespace Howtomakeaturn\PDFInfo\Exceptions;
3+
4+
use \Exception;
5+
6+
class OpenPDFException extends Exception{};

src/Howtomakeaturn/PDFInfo/Exceptions/BaseException.php renamed to src/Howtomakeaturn/PDFInfo/Exceptions/OtherException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
use \Exception;
55

6-
class BaseException extends Exception{};
6+
class OtherException extends Exception{};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
namespace Howtomakeaturn\PDFInfo\Exceptions;
3+
4+
use \Exception;
5+
6+
class PDFPermissionException extends Exception{};

src/Howtomakeaturn/PDFInfo/PDFInfo.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,14 @@ private function loadOutput()
4444
// Surround with double quotes if file name has spaces
4545
exec("$cmd $file", $output, $returnVar);
4646

47-
if ( $returnVar !== 0 ){
48-
throw new Exceptions\BaseException();
47+
if ( $returnVar === 1 ){
48+
throw new Exceptions\OpenPDFException();
49+
} else if ( $returnVar === 2 ){
50+
throw new Exceptions\OpenOutputException();
51+
} else if ( $returnVar === 3 ){
52+
throw new Exceptions\PDFPermissionException();
53+
} else if ( $returnVar === 99 ){
54+
throw new Exceptions\OtherException();
4955
}
5056

5157
$this->output = $output;

0 commit comments

Comments
 (0)