4 * This file is part of Zippy.
6 * (c) Alchemy <info@alchemy.fr>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
13 namespace Alchemy\Zippy\Adapter\VersionProbe;
15 use Alchemy\Zippy\ProcessBuilder\ProcessBuilderFactoryInterface;
17 class ZipVersionProbe implements VersionProbeInterface
23 public function __construct(ProcessBuilderFactoryInterface $inflator, ProcessBuilderFactoryInterface $deflator)
25 $this->inflator = $inflator;
26 $this->deflator = $deflator;
30 * Set the inflator to zip
32 * @param ProcessBuilderFactoryInterface $inflator
33 * @return ZipVersionProbe
35 public function setInflator(ProcessBuilderFactoryInterface $inflator)
37 $this->inflator = $inflator;
43 * Set the deflator to unzip
45 * @param ProcessBuilderFactoryInterface $deflator
46 * @return ZipVersionProbe
48 public function setDeflator(ProcessBuilderFactoryInterface $deflator)
50 $this->deflator = $deflator;
58 public function getStatus()
60 if (null !== $this->isSupported) {
61 return $this->isSupported;
64 if (null === $this->inflator || null === $this->deflator) {
65 return $this->isSupported = VersionProbeInterface::PROBE_NOTSUPPORTED;
68 $processDeflate = $this
74 $processDeflate->run();
76 $processInflate = $this
82 $processInflate->run();
84 if (false === $processDeflate->isSuccessful() || false === $processInflate->isSuccessful()) {
85 return $this->isSupported = VersionProbeInterface::PROBE_NOTSUPPORTED;
88 $lines = explode("\n", $processInflate->getOutput(), 2);
89 $inflatorOk = false !== stripos($lines[0], 'Info-ZIP');
91 $lines = explode("\n", $processDeflate->getOutput(), 2);
92 $deflatorOk = false !== stripos($lines[0], 'Info-ZIP');
94 return $this->isSupported = ($inflatorOk && $deflatorOk) ? VersionProbeInterface::PROBE_OK : VersionProbeInterface::PROBE_NOTSUPPORTED;