scratch – Blame information for rev

Subversion Repositories:
Rev:
Rev Author Line No. Line
115 office 1 <?php
2  
3 /*
4 * This file is part of PHP-FFmpeg.
5 *
6 * (c) Alchemy <info@alchemy.fr>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11  
12 namespace FFMpeg\FFProbe;
13  
14 use Alchemy\BinaryDriver\Exception\ExecutionFailureException;
15 use Doctrine\Common\Cache\Cache;
16 use FFMpeg\Driver\FFProbeDriver;
17 use FFMpeg\Exception\RuntimeException;
18  
19 class OptionsTester implements OptionsTesterInterface
20 {
21 /** @var FFProbeDriver */
22 private $ffprobe;
23 /** @var Cache */
24 private $cache;
25  
26 public function __construct(FFProbeDriver $ffprobe, Cache $cache)
27 {
28 $this->ffprobe = $ffprobe;
29 $this->cache = $cache;
30 }
31  
32 /**
33 * {@inheritdoc}
34 */
35 public function has($name)
36 {
37 $id = sprintf('option-%s', $name);
38  
39 if ($this->cache->contains($id)) {
40 return $this->cache->fetch($id);
41 }
42  
43 $output = $this->retrieveHelpOutput();
44  
45 $ret = (Boolean) preg_match('/^'.$name.'/m', $output);
46  
47 $this->cache->save($id, $ret);
48  
49 return $ret;
50 }
51  
52 private function retrieveHelpOutput()
53 {
54 $id = 'help';
55  
56 if ($this->cache->contains($id)) {
57 return $this->cache->fetch($id);
58 }
59  
60 try {
61 $output = $this->ffprobe->command(array('-help', '-loglevel', 'quiet'));
62 } catch (ExecutionFailureException $e) {
63 throw new RuntimeException('Your FFProbe version is too old and does not support `-help` option, please upgrade.', $e->getCode(), $e);
64 }
65  
66 $this->cache->save($id, $output);
67  
68 return $output;
69 }
70 }