default services conflit ?

This commit is contained in:
armansansd
2022-04-27 11:30:43 +02:00
parent 28190a5749
commit 8bb1064a3b
8132 changed files with 900138 additions and 426 deletions

View File

@@ -0,0 +1,77 @@
<?php
/*
* This file is part of Zippy.
*
* (c) Alchemy <info@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace Alchemy\Zippy\Adapter\VersionProbe;
use Alchemy\Zippy\ProcessBuilder\ProcessBuilderFactoryInterface;
use Symfony\Component\Process\Process;
abstract class AbstractTarVersionProbe implements VersionProbeInterface
{
private $isSupported;
private $inflator;
private $deflator;
public function __construct(ProcessBuilderFactoryInterface $inflator, ProcessBuilderFactoryInterface $deflator)
{
$this->inflator = $inflator;
$this->deflator = $deflator;
}
/**
* {@inheritdoc}
*/
public function getStatus()
{
if (null !== $this->isSupported) {
return $this->isSupported;
}
if (null === $this->inflator || null === $this->deflator) {
return $this->isSupported = VersionProbeInterface::PROBE_NOTSUPPORTED;
}
$good = true;
foreach (array($this->inflator, $this->deflator) as $builder) {
/** @var Process $process */
$process = $builder
->create()
->add('--version')
->getProcess();
$process->run();
if (!$process->isSuccessful()) {
return $this->isSupported = VersionProbeInterface::PROBE_NOTSUPPORTED;
}
$lines = explode("\n", $process->getOutput(), 2);
$good = false !== stripos($lines[0], $this->getVersionSignature());
if (!$good) {
break;
}
}
$this->isSupported = $good ? VersionProbeInterface::PROBE_OK : VersionProbeInterface::PROBE_NOTSUPPORTED;
return $this->isSupported;
}
/**
* Returns the signature of inflator/deflator
*
* @return string
*/
abstract protected function getVersionSignature();
}

View File

@@ -0,0 +1,24 @@
<?php
/*
* This file is part of Zippy.
*
* (c) Alchemy <info@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace Alchemy\Zippy\Adapter\VersionProbe;
class BSDTarVersionProbe extends AbstractTarVersionProbe
{
/**
* {@inheritdoc}
*/
protected function getVersionSignature()
{
return 'bsdtar';
}
}

View File

@@ -0,0 +1,24 @@
<?php
/*
* This file is part of Zippy.
*
* (c) Alchemy <info@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace Alchemy\Zippy\Adapter\VersionProbe;
class GNUTarVersionProbe extends AbstractTarVersionProbe
{
/**
* {@inheritdoc}
*/
protected function getVersionSignature()
{
return '(gnu tar)';
}
}

View File

@@ -0,0 +1,26 @@
<?php
/*
* This file is part of Zippy.
*
* (c) Alchemy <info@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace Alchemy\Zippy\Adapter\VersionProbe;
interface VersionProbeInterface
{
const PROBE_OK = 0;
const PROBE_NOTSUPPORTED = 1;
/**
* Probes for the support of an adapter.
*
* @return integer One of the self::PROBE_* constants
*/
public function getStatus();
}

View File

@@ -0,0 +1,24 @@
<?php
/*
* This file is part of Zippy.
*
* (c) Alchemy <info@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace Alchemy\Zippy\Adapter\VersionProbe;
class ZipExtensionVersionProbe implements VersionProbeInterface
{
/**
* {@inheritdoc}
*/
public function getStatus()
{
return class_exists('\ZipArchive') ? VersionProbeInterface::PROBE_OK : VersionProbeInterface::PROBE_NOTSUPPORTED;
}
}

View File

@@ -0,0 +1,96 @@
<?php
/*
* This file is part of Zippy.
*
* (c) Alchemy <info@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace Alchemy\Zippy\Adapter\VersionProbe;
use Alchemy\Zippy\ProcessBuilder\ProcessBuilderFactoryInterface;
class ZipVersionProbe implements VersionProbeInterface
{
private $isSupported;
private $inflator;
private $deflator;
public function __construct(ProcessBuilderFactoryInterface $inflator, ProcessBuilderFactoryInterface $deflator)
{
$this->inflator = $inflator;
$this->deflator = $deflator;
}
/**
* Set the inflator to zip
*
* @param ProcessBuilderFactoryInterface $inflator
* @return ZipVersionProbe
*/
public function setInflator(ProcessBuilderFactoryInterface $inflator)
{
$this->inflator = $inflator;
return $this;
}
/**
* Set the deflator to unzip
*
* @param ProcessBuilderFactoryInterface $deflator
* @return ZipVersionProbe
*/
public function setDeflator(ProcessBuilderFactoryInterface $deflator)
{
$this->deflator = $deflator;
return $this;
}
/**
* {@inheritdoc}
*/
public function getStatus()
{
if (null !== $this->isSupported) {
return $this->isSupported;
}
if (null === $this->inflator || null === $this->deflator) {
return $this->isSupported = VersionProbeInterface::PROBE_NOTSUPPORTED;
}
$processDeflate = $this
->deflator
->create()
->add('-h')
->getProcess();
$processDeflate->run();
$processInflate = $this
->inflator
->create()
->add('-h')
->getProcess();
$processInflate->run();
if (false === $processDeflate->isSuccessful() || false === $processInflate->isSuccessful()) {
return $this->isSupported = VersionProbeInterface::PROBE_NOTSUPPORTED;
}
$lines = explode("\n", $processInflate->getOutput(), 2);
$inflatorOk = false !== stripos($lines[0], 'Info-ZIP');
$lines = explode("\n", $processDeflate->getOutput(), 2);
$deflatorOk = false !== stripos($lines[0], 'Info-ZIP');
return $this->isSupported = ($inflatorOk && $deflatorOk) ? VersionProbeInterface::PROBE_OK : VersionProbeInterface::PROBE_NOTSUPPORTED;
}
}