-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
403 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); |
Oops, something went wrong.