1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Factory for wiring all the different mappers |
4
|
|
|
* |
5
|
|
|
* @link http://github.com/PHPExif/php-exif-native for the canonical source repository |
6
|
|
|
* @copyright Copyright (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; |
13
|
|
|
|
14
|
|
|
use PHPExif\Common\ExifMapper; |
15
|
|
|
use PHPExif\Common\IptcMapper; |
16
|
|
|
use PHPExif\Common\MetadataMapper; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* MapperFactory |
20
|
|
|
* |
21
|
|
|
* Registers all available mappers |
22
|
|
|
* |
23
|
|
|
* @category PHPExif |
24
|
|
|
* @package Native |
25
|
|
|
*/ |
26
|
|
|
class MapperFactory |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Returns a Mapper instance complete with all sub-mappers |
30
|
|
|
* registered |
31
|
|
|
* |
32
|
|
|
* @return MetadataMapper |
33
|
|
|
*/ |
34
|
|
|
public static function getMapper() |
35
|
|
|
{ |
36
|
|
|
$exifMapper = self::getExifMapper(); |
37
|
|
|
$iptcMapper = self::getIptcMapper(); |
38
|
|
|
|
39
|
|
|
$mapper = new MetadataMapper(); |
40
|
|
|
$mapper->registerFieldMapper( |
41
|
|
|
$exifMapper |
42
|
|
|
); |
43
|
|
|
$mapper->registerFieldMapper( |
44
|
|
|
$iptcMapper |
45
|
|
|
); |
46
|
|
|
|
47
|
|
|
return $mapper; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Returns the mapper for Exif data |
52
|
|
|
* |
53
|
|
|
* @return ExifMapper |
54
|
|
|
*/ |
55
|
|
View Code Duplication |
private static function getExifMapper() |
|
|
|
|
56
|
|
|
{ |
57
|
|
|
$exifMapper = new ExifMapper(); |
58
|
|
|
|
59
|
|
|
// find all classes |
60
|
|
|
$reflClass = new \ReflectionClass(self::class); |
61
|
|
|
$namespace = $reflClass->getNamespaceName(); |
62
|
|
|
$namespace .= '\\Mapper\\Exif'; |
63
|
|
|
|
64
|
|
|
$path = realpath(__DIR__ . '/Mapper/Exif'); |
65
|
|
|
|
66
|
|
|
foreach (glob($path . '/*Mapper.php') as $classPath) { |
67
|
|
|
$className = str_replace('.php', '', array_reverse( |
68
|
|
|
explode(DIRECTORY_SEPARATOR, $classPath) |
69
|
|
|
)[0]); |
70
|
|
|
$fqcn = $namespace . '\\' . $className; |
71
|
|
|
|
72
|
|
|
$fieldMapper = new $fqcn(); |
73
|
|
|
|
74
|
|
|
$exifMapper->registerFieldMapper($fieldMapper); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return $exifMapper; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Returns the mapper for Iptc data |
82
|
|
|
* |
83
|
|
|
* @return IptcMapper |
84
|
|
|
*/ |
85
|
|
View Code Duplication |
private static function getIptcMapper() |
|
|
|
|
86
|
|
|
{ |
87
|
|
|
$iptcMapper = new IptcMapper(); |
88
|
|
|
|
89
|
|
|
// find all classes |
90
|
|
|
$reflClass = new \ReflectionClass(self::class); |
91
|
|
|
$namespace = $reflClass->getNamespaceName(); |
92
|
|
|
$namespace .= '\\Mapper\\Iptc'; |
93
|
|
|
|
94
|
|
|
$path = realpath(__DIR__ . '/Mapper/Iptc'); |
95
|
|
|
|
96
|
|
|
foreach (glob($path . '/*Mapper.php') as $classPath) { |
97
|
|
|
$className = str_replace('.php', '', array_reverse( |
98
|
|
|
explode(DIRECTORY_SEPARATOR, $classPath) |
99
|
|
|
)[0]); |
100
|
|
|
$fqcn = $namespace . '\\' . $className; |
101
|
|
|
|
102
|
|
|
$fieldMapper = new $fqcn(); |
103
|
|
|
|
104
|
|
|
$iptcMapper->registerFieldMapper($fieldMapper); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
return $iptcMapper; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.