1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Mapper for mapping data between raw input and String VO's |
4
|
|
|
* |
5
|
|
|
* @link http://github.com/PHPExif/php-exif-native for the canonical source repository |
6
|
|
|
* @title Title (c) 2016 Tom Van Herreweghe <[email protected]> |
7
|
|
|
* @license http://github.com/PHPExif/php-exif-native/blob/master/LICENSE MIT License |
8
|
|
|
* @category PHPExif |
9
|
|
|
* @package Native |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace PHPExif\Adapter\Native\Reader\Mapper\Iptc; |
13
|
|
|
|
14
|
|
|
use PHPExif\Common\Data\IptcInterface; |
15
|
|
|
use PHPExif\Common\Data\ValueObject\Caption; |
16
|
|
|
use PHPExif\Common\Data\ValueObject\Copyright; |
17
|
|
|
use PHPExif\Common\Data\ValueObject\Credit; |
18
|
|
|
use PHPExif\Common\Data\ValueObject\Headline; |
19
|
|
|
use PHPExif\Common\Data\ValueObject\Jobtitle; |
20
|
|
|
use PHPExif\Common\Data\ValueObject\Source; |
21
|
|
|
use PHPExif\Common\Data\ValueObject\Title; |
22
|
|
|
use PHPExif\Common\Mapper\FieldMapper; |
23
|
|
|
use PHPExif\Common\Mapper\GuardInvalidArgumentsForIptcTrait; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Mapper |
27
|
|
|
* |
28
|
|
|
* @category PHPExif |
29
|
|
|
* @package Native |
30
|
|
|
*/ |
31
|
|
|
class BasicStringFieldMapper implements FieldMapper |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* @var array |
35
|
|
|
*/ |
36
|
|
|
protected $map = [ |
37
|
|
|
Caption::class => [ |
38
|
|
|
'inputField' => '2#120', |
39
|
|
|
'method' => 'withCaption', |
40
|
|
|
], |
41
|
|
|
Copyright::class => [ |
42
|
|
|
'inputField' => '2#116', |
43
|
|
|
'method' => 'withCopyright', |
44
|
|
|
], |
45
|
|
|
Credit::class => [ |
46
|
|
|
'inputField' => '2#110', |
47
|
|
|
'method' => 'withCredit', |
48
|
|
|
], |
49
|
|
|
Headline::class => [ |
50
|
|
|
'inputField' => '2#105', |
51
|
|
|
'method' => 'withHeadline', |
52
|
|
|
], |
53
|
|
|
Jobtitle::class => [ |
54
|
|
|
'inputField' => '2#085', |
55
|
|
|
'method' => 'withJobtitle', |
56
|
|
|
], |
57
|
|
|
Source::class => [ |
58
|
|
|
'inputField' => '2#115', |
59
|
|
|
'method' => 'withSource', |
60
|
|
|
], |
61
|
|
|
Title::class => [ |
62
|
|
|
'inputField' => '2#005', |
63
|
|
|
'method' => 'withTitle', |
64
|
|
|
], |
65
|
|
|
]; |
66
|
|
|
|
67
|
|
|
use GuardInvalidArgumentsForIptcTrait; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* {@inheritDoc} |
71
|
|
|
*/ |
72
|
|
|
public function getSupportedFields() |
73
|
|
|
{ |
74
|
|
|
return array( |
75
|
|
|
Caption::class, |
76
|
|
|
Copyright::class, |
77
|
|
|
Credit::class, |
78
|
|
|
Headline::class, |
79
|
|
|
Jobtitle::class, |
80
|
|
|
Source::class, |
81
|
|
|
Title::class, |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* {@inheritDoc} |
87
|
|
|
*/ |
88
|
|
|
public function mapField($field, array $input, &$output) |
89
|
|
|
{ |
90
|
|
|
$this->guardInvalidArguments($field, $input, $output); |
91
|
|
|
|
92
|
|
|
$inputField = $this->map[$field]['inputField']; |
93
|
|
|
$method = $this->map[$field]['method']; |
94
|
|
|
|
95
|
|
|
if (!array_key_exists($inputField, $input)) { |
96
|
|
|
return; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
if (!is_string($input[$inputField])) { |
100
|
|
|
return; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
$vo = new $field($input[$inputField]); |
104
|
|
|
|
105
|
|
|
$output = $output->$method($vo); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|