Skip to content

Commit b3cca53

Browse files
committed
Initial commit
0 parents  commit b3cca53

File tree

16 files changed

+687
-0
lines changed

16 files changed

+687
-0
lines changed

.github/workflows/phpunit.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: PHPUnit (Unit Tests)
2+
3+
on: [push]
4+
5+
jobs:
6+
unit-tests:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v3
11+
12+
- name: Install Composer dependencies
13+
uses: php-actions/composer@v6
14+
15+
- name: Install QPDF
16+
run: sudo apt-get install -y qpdf
17+
18+
- name: Run PHPUnit
19+
run: vendor/bin/phpunit tests

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/vendor/
2+
/.idea
3+
composer.lock
4+
.DS_Store
5+
.editorconfig
6+
.phpunit*

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
A simple PHP wrapper for QPDF.
2+
3+
https://github.com/qpdf/qpdf

composer.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "msmahon/qpdf-php-wrapper",
3+
"type": "library",
4+
"description": "A simple PHP wrapper for QPDF",
5+
"keywords": ["qpdf", "pdf"],
6+
"homepage": "https://github.com/msmahon/qpdf-php-wrapper",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "Mitchell Mahoney",
11+
"email": "mahoneymitch@gmail.com"
12+
}
13+
],
14+
"autoload": {
15+
"psr-4": {
16+
"Msmahon\\QpdfPhpWrapper\\": "src/"
17+
}
18+
},
19+
"autoload-dev": {
20+
"psr-4": {
21+
"Msmahon\\QpdfPhpWrapper\\Tests\\": "tests/"
22+
}
23+
},
24+
"minimum-stability": "dev",
25+
"require": {
26+
"php": "^8.1",
27+
"symfony/process": "^6.4.2"
28+
},
29+
"require-dev": {
30+
"phpunit/phpunit": "^9.6"
31+
}
32+
}

index.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
require_once 'vendor/autoload.php';
4+
5+
$class = new \Msmahon\QpdfPhpWrapper\Pdf();

phpunit.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<phpunit
2+
bootstrap="vendor/autoload.php"
3+
displayDetailsOnTestsThatTriggerWarnings="true"
4+
>
5+
</phpunit>

src/Enums/ExitCode.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Msmahon\QpdfPhpWrapper\Enums;
4+
5+
enum ExitCode: int
6+
{
7+
/**
8+
* no errors or warnings
9+
*/
10+
case success = 0;
11+
/**
12+
* not used by qpdf but may be used by the shell if unable to invoke qpdf
13+
*/
14+
case nonInvokable = 1;
15+
/**
16+
* errors detected
17+
*/
18+
case error = 2;
19+
/**
20+
* warnings detected, unless --warning-exit-0 is given
21+
*/
22+
case warning = 3;
23+
}

src/Enums/Rotation.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace Msmahon\QpdfPhpWrapper\Enums;
4+
5+
use InvalidArgumentException;
6+
7+
enum Rotation: string
8+
{
9+
CASE RIGHT = '+90';
10+
CASE LEFT = '-90';
11+
CASE DOWN = '+180';
12+
CASE UP = '-180';
13+
14+
/**
15+
* @param int $value
16+
* @return self
17+
* @throws InvalidArgumentException
18+
*/
19+
public static function fromInt(int $value): self
20+
{
21+
return match ($value) {
22+
90 => self::RIGHT,
23+
-90 => self::LEFT,
24+
180 => self::DOWN,
25+
-180 => self::UP,
26+
default => throw new InvalidArgumentException("Invalid rotation value: $value"),
27+
};
28+
}
29+
30+
/**
31+
* @param string $value
32+
* @return self
33+
* @throws InvalidArgumentException
34+
*/
35+
public static function fromCardinal(string $value): self
36+
{
37+
return match ($value) {
38+
'right' => self::RIGHT,
39+
'left' => self::LEFT,
40+
'down' => self::DOWN,
41+
'up' => self::UP,
42+
default => throw new InvalidArgumentException("Invalid rotation value: $value"),
43+
};
44+
}
45+
}

0 commit comments

Comments
 (0)