@@ 21-55 (lines=35) @@ | ||
18 | use Graze\DataFile\Format\JsonFormatInterface; |
|
19 | use InvalidArgumentException; |
|
20 | ||
21 | class FormatterFactory implements FormatterFactoryInterface |
|
22 | { |
|
23 | /** |
|
24 | * @param FormatInterface $format |
|
25 | * |
|
26 | * @return FormatterInterface |
|
27 | */ |
|
28 | public function getFormatter(FormatInterface $format) |
|
29 | { |
|
30 | switch ($format->getType()) { |
|
31 | case 'csv': |
|
32 | if ($format instanceof CsvFormatInterface) { |
|
33 | return new CsvFormatter($format); |
|
34 | } else { |
|
35 | throw new InvalidArgumentException( |
|
36 | "Format indicates it is csv but does not implement CsvFormatInterface" |
|
37 | ); |
|
38 | } |
|
39 | ||
40 | // fallthrough |
|
41 | case 'json': |
|
42 | if ($format instanceof JsonFormatInterface) { |
|
43 | return new JsonFormatter($format); |
|
44 | } else { |
|
45 | throw new InvalidArgumentexception( |
|
46 | "Format indicates it is json but does not implement JsonFormatInterface" |
|
47 | ); |
|
48 | } |
|
49 | ||
50 | // fallthrough |
|
51 | default: |
|
52 | throw new InvalidArgumentException("Supplied format: {$format->getType()} is unknown"); |
|
53 | } |
|
54 | } |
|
55 | } |
|
56 |
@@ 21-55 (lines=35) @@ | ||
18 | use Graze\DataFile\Format\JsonFormatInterface; |
|
19 | use InvalidArgumentException; |
|
20 | ||
21 | class ParserFactory implements ParserFactoryInterface |
|
22 | { |
|
23 | /** |
|
24 | * @param FormatInterface $format |
|
25 | * |
|
26 | * @return ParserInterface |
|
27 | */ |
|
28 | public function getParser(FormatInterface $format) |
|
29 | { |
|
30 | switch ($format->getType()) { |
|
31 | case 'csv': |
|
32 | if ($format instanceof CsvFormatInterface) { |
|
33 | return new CsvParser($format); |
|
34 | } else { |
|
35 | throw new InvalidArgumentException( |
|
36 | "Format indicates it is csv but does not implement CsvFormatInterface" |
|
37 | ); |
|
38 | } |
|
39 | ||
40 | // fallthrough |
|
41 | case 'json': |
|
42 | if ($format instanceof JsonFormatInterface) { |
|
43 | return new JsonParser($format); |
|
44 | } else { |
|
45 | throw new InvalidArgumentexception( |
|
46 | "Format indicates it is json but does not implement JsonFormatInterface" |
|
47 | ); |
|
48 | } |
|
49 | ||
50 | // fallthrough |
|
51 | default: |
|
52 | throw new InvalidArgumentException("Supplied format: {$format->getType()} is unknown"); |
|
53 | } |
|
54 | } |
|
55 | } |
|
56 |