Skip to content

Commit

Permalink
Added preliminary support for Input/Output options
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshyPHP committed Oct 21, 2016
1 parent 90b90a4 commit d1d279b
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 15 deletions.
2 changes: 1 addition & 1 deletion composer.json
@@ -1,6 +1,6 @@
{
"name": "s9e/regexp-builder",
"version": "1.2.0",
"version": "1.3.0-dev",
"type": "library",
"description": "Single-purpose library that generates regular expressions that match a list of literals.",
"homepage": "https://github.com/s9e/RegexpBuilder/",
Expand Down
22 changes: 13 additions & 9 deletions src/Builder.php
Expand Up @@ -40,13 +40,15 @@ class Builder
public function __construct(array $config = [])
{
$config += [
'delimiter' => '/',
'input' => 'Bytes',
'output' => 'Bytes'
'delimiter' => '/',
'input' => 'Bytes',
'inputOptions' => [],
'output' => 'Bytes',
'outputOptions' => []
];

$this->setInput($config['input']);
$this->setSerializer($config['output'], $config['delimiter']);
$this->setInput($config['input'], $config['inputOptions']);
$this->setSerializer($config['output'], $config['outputOptions'], $config['delimiter']);
$this->setRunner();
}

Expand Down Expand Up @@ -110,12 +112,13 @@ protected function isEmpty(array $strings)
* Set the InputInterface instance in $this->input
*
* @param string $inputType
* @param array $inputOptions
* @return void
*/
protected function setInput($inputType)
protected function setInput($inputType, array $inputOptions)
{
$className = __NAMESPACE__ . '\\Input\\' . $inputType;
$this->input = new $className;
$this->input = new $className($inputOptions);
}

/**
Expand All @@ -139,13 +142,14 @@ protected function setRunner()
* Set the Serializer instance in $this->serializer
*
* @param string $outputType
* @param array $outputOptions
* @param string $delimiter
* @return void
*/
protected function setSerializer($outputType, $delimiter)
protected function setSerializer($outputType, array $outputOptions, $delimiter)
{
$className = __NAMESPACE__ . '\\Output\\' . $outputType;
$output = new $className;
$output = new $className($outputOptions);
$escaper = new Escaper($delimiter);

$this->serializer = new Serializer($output, $escaper);
Expand Down
23 changes: 23 additions & 0 deletions src/Input/BaseImplementation.php
@@ -0,0 +1,23 @@
<?php

/**
* @package s9e\RegexpBuilder
* @copyright Copyright (c) 2016 The s9e Authors
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
namespace s9e\RegexpBuilder\Input;

abstract class BaseImplementation implements InputInterface
{
/**
* {@inheritdoc}
*/
public function __construct(array $options = [])
{
}

/**
* {@inheritdoc}
*/
abstract public function split($string);
}
2 changes: 1 addition & 1 deletion src/Input/Bytes.php
Expand Up @@ -7,7 +7,7 @@
*/
namespace s9e\RegexpBuilder\Input;

class Bytes implements InputInterface
class Bytes extends BaseImplementation
{
/**
* {@inheritdoc}
Expand Down
5 changes: 5 additions & 0 deletions src/Input/InputInterface.php
Expand Up @@ -9,6 +9,11 @@

interface InputInterface
{
/**
* @param array $options
*/
public function __construct(array $options = []);

/**
* Split given string into a list of values
*
Expand Down
4 changes: 2 additions & 2 deletions src/Input/Utf8.php
Expand Up @@ -9,7 +9,7 @@

use InvalidArgumentException;

class Utf8 implements InputInterface
class Utf8 extends BaseImplementation
{
/**
* {@inheritdoc}
Expand All @@ -25,7 +25,7 @@ public function split($string)
}

/**
* Convert a list of UTF-8 characters to a list of Unicode codepoint
* Convert a list of UTF-8 characters into a list of Unicode codepoint
*
* @param string[] $chars
* @return integer[]
Expand Down
7 changes: 7 additions & 0 deletions src/Output/BaseImplementation.php
Expand Up @@ -21,6 +21,13 @@ abstract class BaseImplementation implements OutputInterface
*/
protected $minValue = 0;

/**
* @param array $options
*/
public function __construct(array $options = [])
{
}

/**
* {@inheritdoc}
*/
Expand Down
4 changes: 2 additions & 2 deletions tests/Output/AbstractTest.php
Expand Up @@ -10,10 +10,10 @@ abstract class AbstractTest extends PHPUnit_Framework_TestCase
/**
* @dataProvider getOutputTests
*/
public function test($original, $expected)
public function test($original, $expected, $options = [])
{
$className = 's9e\\RegexpBuilder\\Output\\' . preg_replace('(.*\\\\(\\w+)Test$)', '$1', get_class($this));
$output = new $className;
$output = new $className($options);

if ($expected instanceof Exception)
{
Expand Down

0 comments on commit d1d279b

Please sign in to comment.