Skip to content

Commit

Permalink
Update basecode
Browse files Browse the repository at this point in the history
  • Loading branch information
baikunz committed Mar 24, 2013
1 parent 781dc02 commit c8e3c10
Show file tree
Hide file tree
Showing 6 changed files with 403 additions and 2 deletions.
19 changes: 19 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="src/autoload.php"
>
<testsuites>
<testsuite name="Slurpy Test Suite">
<directory>./test</directory>
</testsuite>
</testsuites>
</phpunit>
34 changes: 34 additions & 0 deletions src/Shuble/Slurpy/InputFile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Shuble\Slurpy;

/**
* InputFile
*
* @package Slurpy
*
* @author ALKOUM Dorian <[email protected]>
*/
class InputFile
{
/**
* Path to file
*
* @var string
*/
protected $filePath;

/**
* Handle for the file
*
* @var string
*/
protected $handle;

/**
* Password to open file
*
* @var string
*/
protected $password;
}
223 changes: 223 additions & 0 deletions src/Shuble/Slurpy/Operation/PageRange.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
<?php

namespace Shuble\Slurpy\Operation;

/**
* Page range
*
* @package Slurpy
*
* @author ALKOUM Dorian <[email protected]>
*/
class PageRange
{
const PAGE_END = 'end';

const QUALIFIER_EVEN = 'even';
const QUALIFIER_ODD = 'odd';

const ROTATION_NORTH = 'north';
const ROTATION_SOUTH = 'south';
const ROTATION_EAST = 'east';
const ROTATION_WEST = 'west';
const ROTATION_LEFT = 'left';
const ROTATION_RIGHT = 'right';
const ROTATION_DOWN = 'down';

/**
* Handle of the page range file
*
* @var string
*/
protected $fileHandle;

/**
* Starting page for this page range
*
* @var mixed
*/
protected $startPage;

/**
* Ending page for this page range
*
* @var mixed
*/
protected $endPage;

/**
* Qualifier for filtering on odd / even pages
*
* @var null|string
*/
protected $qualifier;

/**
* Rotation for this page range
*
* @var null|string
*/
protected $rotation;

/**
* Constructor
*
* @param string $fileHandle
* @param array $options
*/
public function __construct($fileHandle)
{
$this->setFileHandle($fileHandle);
}

public function setFileHandle($fileHandle)
{
if (!ctype_upper((string) $fileHandle)) {
throw new \InvalidArgumentException(sprintf(
'"%s" is not a valid handle. A handle must be one or more upper-case letters',
$fileHandle
));
}

$this->fileHandle = $fileHandle;

return $this;
}

public function getFileHandle()
{
return $this->fileHandle;
}

public function setStartPage($startPage)
{
if (null !== $startPage && 0 === preg_match('/^r?(end|[1-9][0-9]*)$/', $startPage)) {
throw new \InvalidArgumentException(sprintf(
'"%s" is not a valid page. Expecting "end", "rend", positive int, or "r" followed by positive int.',
$startPage
));
}

$this->startPage = $startPage;

return $this;
}

public function getStartPage()
{
return $this->startPage;
}

public function setEndPage($endPage)
{
if (null !== $endPage && 0 === preg_match('/^r?(end|[1-9][0-9]*)$/', $endPage)) {
throw new \InvalidArgumentException(sprintf(
'"%s" is not a valid page. Expecting "end", "rend", positive int, or "r" followed by positive int.',
$endPage
));
}

$this->endPage = $endPage;

return $this;
}

public function getEndPage()
{
return $this->endPage;
}

public function setQualifier($qualifier)
{
if (null !== $qualifier && !in_array($qualifier, $this->getAllowedQualifiers())) {
throw new \InvalidArgumentException(sprintf(
'"%s" is not a valid qualifier. Expecting one of "%s"',
$qualifier,
implode('", "', $this->getAllowedQualifiers())
));
}

$this->qualifier = $qualifier;

return $this;
}

public function getQualifier()
{
return $this->qualifier;
}

public function setRotation($rotation)
{
if (null !== $rotation && !in_array($rotation, $this->getAllowedRotations())) {
throw new \InvalidArgumentException(sprintf(
'"%s" is not a valid rotation. Expecting one of "%s"',
$rotation,
implode('", "', $this->getAllowedRotations())
));
}

$this->rotation = $rotation;

return $this;
}

public function getRotation()
{
return $this->rotation;
}

public function __toString()
{
$pageRange = $this->fileHandle;

if (null !== $this->startPage) {
$pageRange .= $this->startPage;

if (null !== $this->endPage) {
$pageRange .= sprintf('-%s', $this->endPage);
}
}

if (null !== $this->endPage && null !== $this->qualifier) {
$pageRange .= $this->qualifier;
}

if (null !== $this->rotation) {
$pageRange .= $this->rotation;
}

return $pageRange;
}

/**
* Return an array of supported qualifiers
*
* @return array
*/
protected function getAllowedQualifiers()
{
return array(
static::QUALIFIER_EVEN,
static::QUALIFIER_ODD,
);
}

/**
* Return an array of supported rotations
*
* @return array
*/
protected function getAllowedRotations()
{
return array(
static::ROTATION_NORTH,
static::ROTATION_SOUTH,
static::ROTATION_EAST,
static::ROTATION_WEST,
static::ROTATION_LEFT,
static::ROTATION_RIGHT,
static::ROTATION_DOWN,
);
}
}
4 changes: 2 additions & 2 deletions src/Shuble/Slurpy/PdfToolkit.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Shuble\Slurpy;

/**
* Wrapper of the pdftk library
* Wrapper for the pdftk library
*
* @package Slurpy
*
Expand Down Expand Up @@ -203,7 +203,7 @@ public static function getAvailableOperations()
*/
protected function configure()
{
$this->setOptions(array(
$this->addOptions(array(
'input_pw' => null,
'encrypt_40bit' => null,
'encrypt_128bit' => null,
Expand Down
22 changes: 22 additions & 0 deletions src/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/**
* Simple autoloader that follow the PHP Standards Recommendation #0 (PSR-0)
* @see https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md for more informations.
*
* Code inspired from the SplClassLoader RFC
* @see https://wiki.php.net/rfc/splclassloader#example_implementation
*/
spl_autoload_register(function($className) {
$package = 'Shuble\\Slurpy';
$className = ltrim($className, '\\');
if (0 === strpos($className, $package)) {
$fileName = __DIR__ . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $className) . '.php';
if (is_file($fileName)) {
require $fileName;
return true;
}
}

return false;
});
Loading

0 comments on commit c8e3c10

Please sign in to comment.