-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLineFactory.php
109 lines (101 loc) · 3.78 KB
/
LineFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
namespace NumaxLab\Geslib;
use NumaxLab\Geslib\Exceptions\InvalidLineCodeException;
use NumaxLab\Geslib\Exceptions\NotImplementedLineCodeException;
use NumaxLab\Geslib\Lines\Article;
use NumaxLab\Geslib\Lines\ArticleAuthor;
use NumaxLab\Geslib\Lines\ArticleIndex;
use NumaxLab\Geslib\Lines\ArticleIndexTranslation;
use NumaxLab\Geslib\Lines\ArticleTopic;
use NumaxLab\Geslib\Lines\Author;
use NumaxLab\Geslib\Lines\AuthorBiography;
use NumaxLab\Geslib\Lines\BookshopReference;
use NumaxLab\Geslib\Lines\BookshopReferenceTranslation;
use NumaxLab\Geslib\Lines\Classification;
use NumaxLab\Geslib\Lines\Collection;
use NumaxLab\Geslib\Lines\Country;
use NumaxLab\Geslib\Lines\EBook;
use NumaxLab\Geslib\Lines\EbookInfo;
use NumaxLab\Geslib\Lines\Editorial;
use NumaxLab\Geslib\Lines\EditorialReference;
use NumaxLab\Geslib\Lines\EditorialReferenceTranslation;
use NumaxLab\Geslib\Lines\Format;
use NumaxLab\Geslib\Lines\Ibic;
use NumaxLab\Geslib\Lines\Language;
use NumaxLab\Geslib\Lines\LineInterface;
use NumaxLab\Geslib\Lines\Preposition;
use NumaxLab\Geslib\Lines\PressPublication;
use NumaxLab\Geslib\Lines\Province;
use NumaxLab\Geslib\Lines\RecordLabel;
use NumaxLab\Geslib\Lines\Status;
use NumaxLab\Geslib\Lines\Stock;
use NumaxLab\Geslib\Lines\Topic;
use NumaxLab\Geslib\Lines\Type;
class LineFactory
{
const INITIAL_FILE_CODE = 'I';
private static $entitiesCodes = [
Editorial::CODE => Editorial::class,
RecordLabel::CODE => RecordLabel::class,
'1P' => null,
PressPublication::CODE => PressPublication::class,
Collection::CODE => Collection::class,
Topic::CODE => Topic::class,
Article::CODE => Article::class,
EBook::CODE => EBook::class,
EbookInfo::CODE => EbookInfo::class,
ArticleTopic::CODE => ArticleTopic::class,
Ibic::CODE => Ibic::class,
BookshopReference::CODE => BookshopReference::class,
BookshopReferenceTranslation::CODE => BookshopReferenceTranslation::class,
EditorialReference::CODE => EditorialReference::class,
EditorialReferenceTranslation::CODE => EditorialReferenceTranslation::class,
ArticleIndex::CODE => ArticleIndex::class,
ArticleIndexTranslation::CODE => ArticleIndexTranslation::class,
ArticleAuthor::CODE => ArticleAuthor::class,
Format::CODE => Format::class,
Language::CODE => Language::class,
Preposition::CODE => Preposition::class,
Stock::CODE => Stock::class,
'B2' => null,
Status::CODE => Status::class,
'CLI' => null,
Author::CODE => Author::class,
'IPC' => null,
'P' => null,
'PROCEN' => null,
'PC' => null,
'VTA' => null,
Country::CODE => Country::class,
'CLOTE' => null,
'LLOTE' => null,
Type::CODE => Type::class,
Classification::CODE => Classification::class,
'ATRA' => null,
'CLOTCLI' => null,
'LLOTCLI' => null,
'PROFES' => null,
Province::CODE => Province::class,
'CAGRDTV' => null,
'LAGRDTV' => null,
'CLIDTO' => null,
'CDG' => null,
'LDG' => null,
AuthorBiography::CODE => AuthorBiography::class,
'EMBALA' => null,
'PACK' => null,
];
public static function create(string $code, array $lineFields): LineInterface
{
if (!array_key_exists($code, self::$entitiesCodes)) {
throw new InvalidLineCodeException(sprintf('Invalid line with code %s', $code));
}
$lineClass = self::$entitiesCodes[$code];
if ($lineClass === null) {
throw new NotImplementedLineCodeException(
sprintf('The line with code %s has not an implemented class', $code)
);
}
return $lineClass::fromLine($lineFields);
}
}