This repository was archived by the owner on Dec 29, 2022. It is now read-only.
forked from romainneutron/PHPExiftool
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExiftool.php
More file actions
92 lines (72 loc) · 2.12 KB
/
Exiftool.php
File metadata and controls
92 lines (72 loc) · 2.12 KB
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
<?php
/*
* This file is part of PHPExifTool.
*
* (c) 2012 Romain Neutron <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPExiftool;
use PHPExiftool\Exception\RuntimeException;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\Process\Process;
class Exiftool implements LoggerAwareInterface
{
private $logger;
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}
/**
* {@inheritdoc}
*/
public function setLogger(LoggerInterface $logger)
{
$this->logger = $logger;
return $this;
}
/**
* Execute a command and return the output
*
* @param string $command
* @return string
* @throws \Exception
*/
public function executeCommand($command)
{
$command = self::getBinary() . ' ' . $command;
$process = new Process($command);
$this->logger->addInfo(sprintf('Exiftool executes command %s', $process->getCommandLine()));
$process->run();
if (! $process->isSuccessful()) {
throw new RuntimeException(sprintf('Command %s failed : %s, exitcode %s', $command, $process->getErrorOutput(), $process->getExitCode()));
}
$output = $process->getOutput();
unset($process);
return $output;
}
/**
*
* @return string
*/
protected static function getBinary()
{
static $binary = null;
if ($binary) {
return $binary;
}
$dev = __DIR__ . '/../../vendor/phpexiftool/exiftool/exiftool';
$packaged = __DIR__ . '/../../../../phpexiftool/exiftool/exiftool';
foreach (array($packaged, $dev) as $location) {
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$location .= '.exe';
}
if (is_executable($location)) {
return $binary = realpath($location);
}
}
throw new RuntimeException('Unable to get exiftool binary');
}
}