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\Title; |
20
|
|
|
use PHPExif\Common\Mapper\FieldMapper; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Mapper |
24
|
|
|
* |
25
|
|
|
* @category PHPExif |
26
|
|
|
* @package Native |
27
|
|
|
*/ |
28
|
|
|
class BasicStringFieldMapper implements FieldMapper |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @var array |
32
|
|
|
*/ |
33
|
|
|
protected $map = [ |
34
|
|
|
Caption::class => [ |
35
|
|
|
'inputField' => '2#120', |
36
|
|
|
'method' => 'withCaption', |
37
|
|
|
], |
38
|
|
|
Copyright::class => [ |
39
|
|
|
'inputField' => '2#116', |
40
|
|
|
'method' => 'withCopyright', |
41
|
|
|
], |
42
|
|
|
Credit::class => [ |
43
|
|
|
'inputField' => '2#110', |
44
|
|
|
'method' => 'withCredit', |
45
|
|
|
], |
46
|
|
|
Headline::class => [ |
47
|
|
|
'inputField' => '2#105', |
48
|
|
|
'method' => 'withHeadline', |
49
|
|
|
], |
50
|
|
|
Title::class => [ |
51
|
|
|
'inputField' => '2#005', |
52
|
|
|
'method' => 'withTitle', |
53
|
|
|
], |
54
|
|
|
]; |
55
|
|
|
|
56
|
|
|
use GuardInvalidArgumentsTrait; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* {@inheritDoc} |
60
|
|
|
*/ |
61
|
|
|
public function getSupportedFields() |
62
|
|
|
{ |
63
|
|
|
return array( |
64
|
|
|
Caption::class, |
65
|
|
|
Copyright::class, |
66
|
|
|
Credit::class, |
67
|
|
|
Headline::class, |
68
|
|
|
Title::class, |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* {@inheritDoc} |
74
|
|
|
*/ |
75
|
|
|
public function mapField($field, array $input, &$output) |
76
|
|
|
{ |
77
|
|
|
$this->guardInvalidArguments($field, $input, $output); |
78
|
|
|
|
79
|
|
|
$inputField = $this->map[$field]['inputField']; |
80
|
|
|
$method = $this->map[$field]['method']; |
81
|
|
|
|
82
|
|
|
if (!array_key_exists($inputField, $input)) { |
83
|
|
|
return; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
if (!is_string($input[$inputField])) { |
87
|
|
|
return; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$vo = new $field($input[$inputField]); |
91
|
|
|
|
92
|
|
|
$output = $output->$method($vo); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|