refactored AbstractFactory

This commit is contained in:
Dominik Liebler
2018-06-15 18:47:18 +02:00
parent bca6af02c0
commit 5954a570a8
15 changed files with 145 additions and 647 deletions

View File

@@ -0,0 +1,35 @@
<?php
namespace DesignPatterns\Creational\AbstractFactory;
class CsvParser implements Parser
{
const OPTION_CONTAINS_HEADER = true;
const OPTION_CONTAINS_NO_HEADER = false;
/**
* @var bool
*/
private $skipHeaderLine;
public function __construct(bool $skipHeaderLine)
{
$this->skipHeaderLine = $skipHeaderLine;
}
public function parse(string $input): array
{
$headerWasParsed = false;
$parsedLines = [];
foreach (explode(PHP_EOL, $input) as $line) {
if (!$headerWasParsed && $this->skipHeaderLine === self::OPTION_CONTAINS_HEADER) {
continue;
}
$parsedLines[] = str_getcsv($line);
}
return $parsedLines;
}
}