Finish implementing and testing zip

modifié:         core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php
	nouveau fichier: core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/TarArchiveException.php
	renommé:         core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveException.php -> core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/ZipArchiveException.php
	nouveau fichier: core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php
	modifié:         core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php
	modifié:         core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php
	nouveau fichier: core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php
	modifié:         core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php
This commit is contained in:
Benjamin Perche
2014-07-03 13:10:53 +02:00
parent 9eecad5658
commit 83cf3b59e0
9 changed files with 611 additions and 45 deletions

View File

@@ -46,7 +46,13 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder
const TEMP_DIRECTORY_NAME = "archive_builder"; const TEMP_DIRECTORY_NAME = "archive_builder";
<<<<<<< HEAD
>>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources >>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources
=======
/** @var string */
protected $cacheFile;
>>>>>>> Finish implementing and testing zip
/** @var \Thelia\Core\Translation\Translator */ /** @var \Thelia\Core\Translation\Translator */
protected $translator; protected $translator;
@@ -84,11 +90,15 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder
); );
} }
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
$archiveBuilderCacheDir = $this->cacheDir = $theliaCacheDir . static::TEMP_DIRECTORY_NAME; $archiveBuilderCacheDir = $this->cacheDir = $theliaCacheDir . static::TEMP_DIRECTORY_NAME;
======= =======
$archiveBuilderCacheDir = $this->cache_dir = $theliaCacheDir . static::TEMP_DIRECTORY_NAME; $archiveBuilderCacheDir = $this->cache_dir = $theliaCacheDir . static::TEMP_DIRECTORY_NAME;
>>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources >>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources
=======
$archiveBuilderCacheDir = $this->cacheDir = $theliaCacheDir . static::TEMP_DIRECTORY_NAME;
>>>>>>> Finish implementing and testing zip
if (!is_dir($archiveBuilderCacheDir) && !mkdir($archiveBuilderCacheDir, 0755)) { if (!is_dir($archiveBuilderCacheDir) && !mkdir($archiveBuilderCacheDir, 0755)) {
throw new \ErrorException( throw new \ErrorException(
@@ -105,6 +115,9 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder
} }
<<<<<<< HEAD <<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> Finish implementing and testing zip
/** /**
* @param $pathToFile * @param $pathToFile
* @param $destination * @param $destination
@@ -196,8 +209,11 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder
return $this; return $this;
} }
<<<<<<< HEAD
======= =======
>>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources >>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources
=======
>>>>>>> Finish implementing and testing zip
public function getCacheDir() public function getCacheDir()
{ {
@@ -220,11 +236,15 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder
return $this->translator; return $this->translator;
} }
<<<<<<< HEAD <<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> Finish implementing and testing zip
public function getCacheFile() public function getCacheFile()
{ {
return $this->cacheFile; return $this->cacheFile;
} }
<<<<<<< HEAD
/** /**
* @param string $environment * @param string $environment
@@ -244,3 +264,6 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder
======= =======
} }
>>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources >>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources
=======
}
>>>>>>> Finish implementing and testing zip

View File

@@ -20,4 +20,8 @@ namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception;
class TarArchiveException extends \Exception class TarArchiveException extends \Exception
{ {
<<<<<<< HEAD
} }
=======
}
>>>>>>> Finish implementing and testing zip

View File

@@ -20,4 +20,4 @@ namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception;
class ZipArchiveException extends \ErrorException class ZipArchiveException extends \ErrorException
{ {
} }

View File

@@ -10,7 +10,7 @@
/* file that was distributed with this source code. */ /* file that was distributed with this source code. */
/*************************************************************************************/ /*************************************************************************************/
namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder; namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception;
/** /**
* Class ZipArchiveException * Class ZipArchiveException
@@ -20,4 +20,4 @@ namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder;
class ZipArchiveException extends \ErrorException class ZipArchiveException extends \ErrorException
{ {
} }

View File

@@ -13,10 +13,15 @@
namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder; namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder;
use Thelia\Core\FileFormat\Archive\AbstractArchiveBuilder; use Thelia\Core\FileFormat\Archive\AbstractArchiveBuilder;
use Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\TarArchiveException; use Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\TarArchiveException;
<<<<<<< HEAD
use Thelia\Core\HttpFoundation\Response; use Thelia\Core\HttpFoundation\Response;
use Thelia\Core\Thelia; use Thelia\Core\Thelia;
use Thelia\Core\Translation\Translator; use Thelia\Core\Translation\Translator;
use Thelia\Exception\FileNotReadableException; use Thelia\Exception\FileNotReadableException;
=======
use Thelia\Core\FileFormat\Archive\ArchiveBuilderInterface;
use Thelia\Core\Translation\Translator;
>>>>>>> Finish implementing and testing zip
use Thelia\Log\Tlog; use Thelia\Log\Tlog;
use Thelia\Tools\FileDownload\FileDownloaderInterface; use Thelia\Tools\FileDownload\FileDownloaderInterface;
@@ -47,6 +52,32 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
/** @var \Thelia\Log\Tlog */ /** @var \Thelia\Log\Tlog */
protected $logger; protected $logger;
<<<<<<< HEAD
=======
function __construct($compressionType = null)
{
$this->translator = Translator::getInstance();
$this->logger = Tlog::getNewInstance();
$supportedCompression = [
"gz",
"bz2",
null
];
if (!in_array($compressionType, $supportedCompression)) {
throw new TarArchiveException(
$this->translator->trans(
"The compression %type is not supported"
)
);
}
$this->compression = $compressionType;
}
/**
>>>>>>> Finish implementing and testing zip
public function __destruct() public function __destruct()
{ {
if ($this->tar instanceof \PharData) { if ($this->tar instanceof \PharData) {
@@ -54,6 +85,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
unlink($this->cacheFile); unlink($this->cacheFile);
} }
} }
<<<<<<< HEAD
} }
/** /**
@@ -61,6 +93,15 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
* @param string $directoryInArchive This is the directory where it will be stored in the archive * @param string $directoryInArchive This is the directory where it will be stored in the archive
* @param null|string $name The name of the file in the archive. if it null or empty, it keeps the same name * @param null|string $name The name of the file in the archive. if it null or empty, it keeps the same name
* @param bool $isOnline * @param bool $isOnline
=======
}*/
/**
* @param string $filePath It is the path to access the file.
* @param string $directoryInArchive This is the directory where it will be stored in the archive
* @param null|string $name The name of the file in the archive. if it null or empty, it keeps the same name
* @param bool $isOnline
>>>>>>> Finish implementing and testing zip
* @return $this * @return $this
* @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotFoundException
* @throws \Thelia\Exception\FileNotReadableException * @throws \Thelia\Exception\FileNotReadableException
@@ -80,7 +121,11 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
* Download the file if it is online * Download the file if it is online
* If it's local check if the file exists and if it is redable * If it's local check if the file exists and if it is redable
*/ */
<<<<<<< HEAD
$fileDownloadCache = $this->cacheDir . DS . md5(uniqid()) . ".tmp"; $fileDownloadCache = $this->cacheDir . DS . md5(uniqid()) . ".tmp";
=======
$fileDownloadCache = $this->cacheDir . DS . "download.tmp";
>>>>>>> Finish implementing and testing zip
$this->copyFile($filePath, $fileDownloadCache, $isOnline); $this->copyFile($filePath, $fileDownloadCache, $isOnline);
/** /**
@@ -96,18 +141,25 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
$this->tar->addFile($filePath, $name); $this->tar->addFile($filePath, $name);
<<<<<<< HEAD
/** /**
* And clear the download temp file * And clear the download temp file
*/ */
unlink($fileDownloadCache); unlink($fileDownloadCache);
=======
>>>>>>> Finish implementing and testing zip
return $this; return $this;
} }
/** /**
* @param $content * @param $content
* @param $name * @param $name
<<<<<<< HEAD
* @param string $directoryInArchive * @param string $directoryInArchive
=======
* @param string $directoryInArchive
>>>>>>> Finish implementing and testing zip
* @return mixed * @return mixed
* @throws \ErrorException * @throws \ErrorException
* *
@@ -132,7 +184,11 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
} }
try { try {
$this->tar->addFromString($name, $content); $this->tar->addFromString($name, $content);
<<<<<<< HEAD
} catch (\Exception $e) { } catch (\Exception $e) {
=======
} catch(\Exception $e) {
>>>>>>> Finish implementing and testing zip
throw new \ErrorException( throw new \ErrorException(
$this->translator->trans( $this->translator->trans(
"Error while writing the file into the archive, error message: %errmes", "Error while writing the file into the archive, error message: %errmes",
@@ -144,6 +200,10 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
} }
} }
<<<<<<< HEAD
=======
>>>>>>> Finish implementing and testing zip
/** /**
* @param $directoryPath * @param $directoryPath
* @return $this * @return $this
@@ -159,7 +219,11 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
try { try {
$this->tar->addEmptyDir($directoryInArchive); $this->tar->addEmptyDir($directoryInArchive);
<<<<<<< HEAD
} catch (\Exception $e) { } catch (\Exception $e) {
=======
} catch(\Exception $e) {
>>>>>>> Finish implementing and testing zip
throw new \ErrorException( throw new \ErrorException(
$this->translator->trans( $this->translator->trans(
"The directory %dir has not been created in the archive", "The directory %dir has not been created in the archive",
@@ -175,7 +239,11 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
} }
/** /**
<<<<<<< HEAD
* @param string $pathToFile * @param string $pathToFile
=======
* @param string $pathToFile
>>>>>>> Finish implementing and testing zip
* @return null|string * @return null|string
* @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotFoundException
* @throws \Thelia\Exception\FileNotReadableException * @throws \Thelia\Exception\FileNotReadableException
@@ -185,6 +253,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
*/ */
public function getFileContent($pathToFile) public function getFileContent($pathToFile)
{ {
<<<<<<< HEAD
$pathToFile = $this->formatFilePath($pathToFile); $pathToFile = $this->formatFilePath($pathToFile);
if (!$this->hasFile($pathToFile)) { if (!$this->hasFile($pathToFile)) {
@@ -205,6 +274,12 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
return $content; return $content;
} }
=======
}
>>>>>>> Finish implementing and testing zip
/** /**
* @param $pathInArchive * @param $pathInArchive
* @return $this * @return $this
@@ -236,6 +311,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
* *
* This method return an instance of a Response with the archive as content. * This method return an instance of a Response with the archive as content.
*/ */
<<<<<<< HEAD
public function buildArchiveResponse($filename) public function buildArchiveResponse($filename)
{ {
$this->tar->setMetadata("Generated by Thelia v" . Thelia::THELIA_VERSION); $this->tar->setMetadata("Generated by Thelia v" . Thelia::THELIA_VERSION);
@@ -272,6 +348,18 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
* @param string $environment * @param string $environment
* @param bool $isOnline * @param bool $isOnline
* @param FileDownloaderInterface $fileDownloader * @param FileDownloaderInterface $fileDownloader
=======
public function buildArchiveResponse()
{
}
/**
* @param string $pathToArchive
* @param string $environment
* @param bool $isOnline
* @param FileDownloaderInterface $fileDownloader
>>>>>>> Finish implementing and testing zip
* @return $this * @return $this
* @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotFoundException
* @throws \Thelia\Exception\HttpUrlException * @throws \Thelia\Exception\HttpUrlException
@@ -279,6 +367,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
* *
* Loads an archive * Loads an archive
*/ */
<<<<<<< HEAD
public function loadArchive($pathToArchive, $isOnline = false) public function loadArchive($pathToArchive, $isOnline = false)
{ {
$tar = clone $this; $tar = clone $this;
@@ -286,13 +375,36 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
$tar $tar
->setCacheFile($tar->generateCacheFile($this->environment)) ->setCacheFile($tar->generateCacheFile($this->environment))
->copyFile($pathToArchive, $tar->getCacheFile(), $isOnline); ->copyFile($pathToArchive, $tar->getCacheFile(), $isOnline);
=======
public static function loadArchive(
$pathToArchive,
$environment,
$isOnline = false,
FileDownloaderInterface $fileDownloader = null
) {
/** @var TarArchiveBuilder $instance */
$instance = new static();
if ($fileDownloader !== null) {
$instance->setFileDownloader($fileDownloader);
}
$instance->setCacheFile($instance->getCacheFile())
->copyFile($pathToArchive, $isOnline);
>>>>>>> Finish implementing and testing zip
/** /**
* This throws TarArchiveBuilderException if * This throws TarArchiveBuilderException if
* the archive is not valid. * the archive is not valid.
*/ */
<<<<<<< HEAD
return $tar->setEnvironment($tar->environment); return $tar->setEnvironment($tar->environment);
=======
$instance->setEnvironment($environment);
return $instance;
>>>>>>> Finish implementing and testing zip
} }
/** /**
@@ -312,19 +424,31 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
/** @var \PharFileInfo $fileInfo */ /** @var \PharFileInfo $fileInfo */
$fileInfo = $this->tar[$pathToFile]; $fileInfo = $this->tar[$pathToFile];
<<<<<<< HEAD
if ($fileInfo->isFile()) { if ($fileInfo->isFile()) {
=======
if($fileInfo->isFile()) {
>>>>>>> Finish implementing and testing zip
$isFile = true; $isFile = true;
} }
/** /**
* Catch the exception to avoid its displaying. * Catch the exception to avoid its displaying.
*/ */
<<<<<<< HEAD
} catch (\BadMethodCallException $e) {} } catch (\BadMethodCallException $e) {}
=======
} catch(\BadMethodCallException $e) {}
>>>>>>> Finish implementing and testing zip
return $isFile; return $isFile;
} }
/** /**
<<<<<<< HEAD
* @param string $directory * @param string $directory
=======
* @param string $directory
>>>>>>> Finish implementing and testing zip
* @return bool * @return bool
* *
* Check if the archive has a directory * Check if the archive has a directory
@@ -338,19 +462,31 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
/** @var \PharFileInfo $fileInfo */ /** @var \PharFileInfo $fileInfo */
$fileInfo = $this->tar[$pathToDir]; $fileInfo = $this->tar[$pathToDir];
<<<<<<< HEAD
if ($fileInfo->isDir()) { if ($fileInfo->isDir()) {
=======
if($fileInfo->isDir()) {
>>>>>>> Finish implementing and testing zip
$isDir = true; $isDir = true;
} }
/** /**
* Catch the exception to avoid its displaying. * Catch the exception to avoid its displaying.
*/ */
<<<<<<< HEAD
} catch (\BadMethodCallException $e) {} } catch (\BadMethodCallException $e) {}
=======
} catch(\BadMethodCallException $e) {}
>>>>>>> Finish implementing and testing zip
return $isDir; return $isDir;
} }
/** /**
<<<<<<< HEAD
* @param string $environment * @param string $environment
=======
* @param string $environment
>>>>>>> Finish implementing and testing zip
* @return $this * @return $this
* *
* Sets the execution environment of the Kernel, * Sets the execution environment of the Kernel,
@@ -358,6 +494,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
*/ */
public function setEnvironment($environment) public function setEnvironment($environment)
{ {
<<<<<<< HEAD
if (empty($environment)) { if (empty($environment)) {
throw new \ErrorException( throw new \ErrorException(
$this->translator->trans( $this->translator->trans(
@@ -366,6 +503,8 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
); );
} }
=======
>>>>>>> Finish implementing and testing zip
if ($this->cacheFile === null) { if ($this->cacheFile === null) {
$cacheFile = $this->generateCacheFile($environment); $cacheFile = $this->generateCacheFile($environment);
@@ -381,14 +520,33 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
try { try {
$this->tar = new \PharData($cacheFile, null, null, static::PHAR_FORMAT); $this->tar = new \PharData($cacheFile, null, null, static::PHAR_FORMAT);
<<<<<<< HEAD
$this->compressionEntryPoint(); $this->compressionEntryPoint();
} catch (\BadMethodCallException $e) { } catch (\BadMethodCallException $e) {
=======
switch ($this->compression) {
case "gz":
$this->tar = $this->tar->compress(\Phar::GZ);
$cacheFile .= ".gz";
break;
case "bz2":
$this->tar = $this->tar->compress(\Phar::BZ2);
$cacheFile .= ".bz2";
break;
}
} catch(\BadMethodCallException $e) {
>>>>>>> Finish implementing and testing zip
/** /**
* This should not happen * This should not happen
*/ */
$errorMessage = "You have badly called the method setEnvironment twice for %file"; $errorMessage = "You have badly called the method setEnvironment twice for %file";
<<<<<<< HEAD
} catch (\UnexpectedValueException $e) { } catch (\UnexpectedValueException $e) {
=======
} catch(\UnexpectedValueException $e) {
>>>>>>> Finish implementing and testing zip
$errorMessage = "The file %file is corrupted"; $errorMessage = "The file %file is corrupted";
} }
@@ -404,13 +562,20 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
} }
$this->cacheFile = $cacheFile; $this->cacheFile = $cacheFile;
<<<<<<< HEAD
$this->environment = $environment; $this->environment = $environment;
=======
>>>>>>> Finish implementing and testing zip
return $this; return $this;
} }
/** /**
<<<<<<< HEAD
* @param string $initialString * @param string $initialString
=======
* @param string $initialString
>>>>>>> Finish implementing and testing zip
* @return string * @return string
* *
* Gives a valid file path for \ZipArchive * Gives a valid file path for \ZipArchive
@@ -431,7 +596,11 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
} }
/** /**
<<<<<<< HEAD
* @param string $initialString * @param string $initialString
=======
* @param string $initialString
>>>>>>> Finish implementing and testing zip
* @return string * @return string
* *
* Gives a valid directory path for \ZipArchive * Gives a valid directory path for \ZipArchive
@@ -453,7 +622,17 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
*/ */
public function getName() public function getName()
{ {
<<<<<<< HEAD
return "tar"; return "tar";
=======
$name = "tar";
if ($this->compression !== null) {
$name .= "." . $this->compression;
}
return $name;
>>>>>>> Finish implementing and testing zip
} }
/** /**
@@ -467,7 +646,11 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
*/ */
public function getExtension() public function getExtension()
{ {
<<<<<<< HEAD
return "tar"; return "tar";
=======
return $this->getName();
>>>>>>> Finish implementing and testing zip
} }
/** /**
@@ -480,6 +663,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
*/ */
public function getMimeType() public function getMimeType()
{ {
<<<<<<< HEAD
return "application/x-tar"; return "application/x-tar";
} }
@@ -496,3 +680,12 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
return $this->compression; return $this->compression;
} }
} }
=======
return $this->compression === null ?
"application/x-tar" :
"application/x-gtar"
;
}
}
>>>>>>> Finish implementing and testing zip

View File

@@ -13,18 +13,23 @@
namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder; namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder;
use Thelia\Core\FileFormat\Archive\AbstractArchiveBuilder; use Thelia\Core\FileFormat\Archive\AbstractArchiveBuilder;
<<<<<<< HEAD <<<<<<< HEAD
<<<<<<< HEAD
use Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\ZipArchiveException; use Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\ZipArchiveException;
use Thelia\Core\HttpFoundation\Response; use Thelia\Core\HttpFoundation\Response;
use Thelia\Core\Thelia; use Thelia\Core\Thelia;
use Thelia\Exception\FileNotReadableException; use Thelia\Exception\FileNotReadableException;
======= =======
=======
use Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\ZipArchiveException;
>>>>>>> Finish implementing and testing zip
use Thelia\Core\HttpFoundation\Response; use Thelia\Core\HttpFoundation\Response;
use Thelia\Core\Thelia; use Thelia\Core\Thelia;
use Thelia\Core\Translation\Translator;
use Thelia\Exception\FileNotFoundException;
use Thelia\Exception\FileNotReadableException; use Thelia\Exception\FileNotReadableException;
<<<<<<< HEAD
use Thelia\Log\Tlog; use Thelia\Log\Tlog;
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
=======
>>>>>>> Finish implementing and testing zip
use Thelia\Tools\FileDownload\FileDownloaderInterface; use Thelia\Tools\FileDownload\FileDownloaderInterface;
/** /**
@@ -53,6 +58,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
*/ */
protected $zip; protected $zip;
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
public function __construct() public function __construct()
{ {
@@ -70,6 +76,8 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
*/ */
protected $cacheDir; protected $cacheDir;
=======
>>>>>>> Finish implementing and testing zip
public function __construct() public function __construct()
{ {
parent::__construct(); parent::__construct();
@@ -95,6 +103,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
if ($this->zip instanceof \ZipArchive) { if ($this->zip instanceof \ZipArchive) {
@$this->zip->close(); @$this->zip->close();
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
if (file_exists($this->cacheFile)) { if (file_exists($this->cacheFile)) {
@@ -107,6 +116,10 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
if (file_exists($this->zipCacheFile)) { if (file_exists($this->zipCacheFile)) {
unlink($this->zipCacheFile); unlink($this->zipCacheFile);
>>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources >>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources
=======
if (file_exists($this->cacheFile)) {
unlink($this->cacheFile);
>>>>>>> Finish implementing and testing zip
} }
} }
} }
@@ -129,7 +142,11 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
* @return $this * @return $this
* @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotFoundException
* @throws \Thelia\Exception\FileNotReadableException * @throws \Thelia\Exception\FileNotReadableException
<<<<<<< HEAD
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
=======
* @throws \ErrorException
>>>>>>> Finish implementing and testing zip
* *
* This methods adds a file in the archive. * This methods adds a file in the archive.
* If the file is local, $isOnline must be false, * If the file is local, $isOnline must be false,
@@ -137,6 +154,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
*/ */
public function addFile($filePath, $directoryInArchive = null, $name = null, $isOnline = false) public function addFile($filePath, $directoryInArchive = null, $name = null, $isOnline = false)
{ {
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
$directoryInArchive = $this->formatDirectoryPath($directoryInArchive); $directoryInArchive = $this->formatDirectoryPath($directoryInArchive);
@@ -243,16 +261,19 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
if (!empty($directoryInArchive)) { if (!empty($directoryInArchive)) {
======= =======
=======
$directoryInArchive = $this->formatDirectoryPath($directoryInArchive);
>>>>>>> Finish implementing and testing zip
/** /**
* Add empty directory if it doesn't exist * Add empty directory if it doesn't exist
*/ */
if (empty($directoryInArchive) || preg_match("#^\/+$#", $directoryInArchive)) {
$directoryInArchive = "";
}
if(!empty($directoryInArchive)) { if(!empty($directoryInArchive)) {
$directoryInArchive = $this->getDirectoryPath($directoryInArchive); $this->addDirectory($directoryInArchive);
}
<<<<<<< HEAD
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
if (!$this->zip->addEmptyDir($directoryInArchive)) { if (!$this->zip->addEmptyDir($directoryInArchive)) {
throw new \ErrorException( throw new \ErrorException(
@@ -264,6 +285,10 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
) )
); );
} }
=======
if (empty($name) || !is_scalar($name)) {
$name = basename($filePath);
>>>>>>> Finish implementing and testing zip
} }
<<<<<<< HEAD <<<<<<< HEAD
@@ -347,6 +372,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
* Download the file if it is online * Download the file if it is online
* If it's local check if the file exists and if it is redable * If it's local check if the file exists and if it is redable
*/ */
<<<<<<< HEAD
>>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources >>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources
if ($isOnline) { if ($isOnline) {
$fileDownloadCache = $this->cacheDir . DS . "download"; $fileDownloadCache = $this->cacheDir . DS . "download";
@@ -375,18 +401,21 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
if (empty($name)) { if (empty($name)) {
$name = basename($filePath); $name = basename($filePath);
} }
=======
$fileDownloadCache = $this->cacheDir . DS . "download.tmp";
$this->copyFile($filePath, $fileDownloadCache, $isOnline);
>>>>>>> Finish implementing and testing zip
/** /**
* Then write the file in the archive and commit the changes * Then write the file in the archive and commit the changes
*/ */
$destination = $directoryInArchive . $name; $destination = $directoryInArchive . $name;
if (!$this->zip->addFile($filePath,$destination)) { if (!$this->zip->addFile($fileDownloadCache, $destination)) {
$translatedErrorMessage = $this->translator->trans( $translatedErrorMessage = $this->translator->trans(
"An error occurred while adding this file to the archive: %file", "An error occurred while adding this file to the archive: %file",
[ [
"%file" => $filePath "%file" => $fileDownloadCache
] ]
); );
@@ -401,6 +430,146 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
} }
/**
* @param $content
* @param $name
* @param string $directoryInArchive
* @return mixed
* @throws \ErrorException
*
* This method creates a file in the archive with its content
*/
public function addFileFromString($content, $name, $directoryInArchive = "/")
{
$directoryInArchive = $this->formatDirectoryPath($directoryInArchive);
if (!empty($directoryInArchive) && $directoryInArchive !== "/") {
$this->addDirectory($directoryInArchive);
}
if (empty($name) || !is_scalar($name)) {
throw new \ErrorException(
$this->translator->trans(
"The filename is not correct"
)
);
}
$filePath = $this->getFilePath($directoryInArchive . DS . $name);
if (!$this->zip->addFromString($filePath, $content)) {
throw new \ErrorException(
$this->translator->trans(
"Unable to write the file %file into the archive",
[
"%file" => $filePath,
]
)
);
}
$this->commit();
}
/**
* @param $directoryPath
* @return $this
* @throws \ErrorException
*
* This method creates an empty directory
*/
public function addDirectory($directoryPath)
{
$directoryInArchive = $this->formatDirectoryPath($directoryPath);
if (!empty($directoryInArchive)) {
if (!$this->zip->addEmptyDir($directoryInArchive)) {
throw new \ErrorException(
$this->translator->trans(
"The directory %dir has not been created in the archive",
[
"%dir" => $directoryInArchive
]
)
);
}
}
return $this;
}
/**
* @param string $pathToFile
* @return null|string
* @throws \Thelia\Exception\FileNotFoundException
* @throws \Thelia\Exception\FileNotReadableException
* @throws \ErrorException
*
* This method returns a file content
*/
public function getFileContent($pathToFile)
{
$pathToFile = $this->formatFilePath($pathToFile);
if (!$this->hasFile($pathToFile)) {
$this->throwFileNotFound($pathToFile);
}
$stream = $this->zip->getStream($pathToFile);
$content = "";
while (!feof($stream)) {
$content .= fread($stream, 2);
}
fclose($stream);
return $content;
}
/**
* @param string $initialString
* @return string
*
* Gives a valid file path for \ZipArchive
*/
public function getFilePath($initialString)
{
/**
* Remove the / at the beginning and the end.
*/
$initialString = trim($initialString, "/");
/**
* Remove the double, triple, ... slashes
*/
$initialString = preg_replace("#\/{2,}#", "/", $initialString);
if (preg_match("#\/?[^\/]+\/[^/]+\/?#", $initialString)) {
$initialString = "/" . $initialString;
}
return $initialString;
}
/**
* @param string $initialString
* @return string
*
* Gives a valid directory path for \ZipArchive
*/
public function getDirectoryPath($initialString)
{
$initialString = $this->getFilePath($initialString);
if ($initialString[0] !== "/") {
$initialString = "/" . $initialString;
}
return $initialString . "/";
}
/** /**
* @param $pathInArchive * @param $pathInArchive
* @return $this * @return $this
@@ -411,11 +580,15 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
*/ */
public function deleteFile($pathInArchive) public function deleteFile($pathInArchive)
{ {
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
$pathInArchive = $this->formatFilePath($pathInArchive); $pathInArchive = $this->formatFilePath($pathInArchive);
======= =======
$pathInArchive = $this->getFilePath($pathInArchive); $pathInArchive = $this->getFilePath($pathInArchive);
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
=======
$pathInArchive = $this->formatFilePath($pathInArchive);
>>>>>>> Finish implementing and testing zip
if (!$this->hasFile($pathInArchive)) { if (!$this->hasFile($pathInArchive)) {
$this->throwFileNotFound($pathInArchive); $this->throwFileNotFound($pathInArchive);
@@ -452,6 +625,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
$this->commit(); $this->commit();
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
if (!file_exists($this->cacheFile)) { if (!file_exists($this->cacheFile)) {
@@ -473,11 +647,19 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
if (!is_readable($this->zipCacheFile)) { if (!is_readable($this->zipCacheFile)) {
>>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources >>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources
=======
if (!file_exists($this->cacheFile)) {
$this->throwFileNotFound($this->cacheFile);
}
if (!is_readable($this->cacheFile)) {
>>>>>>> Finish implementing and testing zip
throw new FileNotReadableException( throw new FileNotReadableException(
$this->translator->trans( $this->translator->trans(
"The cache file %file is not readable", "The cache file %file is not readable",
[ [
<<<<<<< HEAD <<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
"%file" => $this->cacheFile "%file" => $this->cacheFile
======= =======
@@ -486,11 +668,15 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
======= =======
"%file" => $this->zipCacheFile "%file" => $this->zipCacheFile
>>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources >>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources
=======
"%file" => $this->cacheFile
>>>>>>> Finish implementing and testing zip
] ]
) )
); );
} }
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
$content = file_get_contents($this->cacheFile); $content = file_get_contents($this->cacheFile);
@@ -500,6 +686,9 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
======= =======
$content = file_get_contents($this->zipCacheFile); $content = file_get_contents($this->zipCacheFile);
>>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources >>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources
=======
$content = file_get_contents($this->cacheFile);
>>>>>>> Finish implementing and testing zip
$this->zip->close(); $this->zip->close();
@@ -576,39 +765,9 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
$instance->setFileDownloader($fileDownloader); $instance->setFileDownloader($fileDownloader);
} }
if ($isOnline) { $instance->copyFile($pathToArchive, $instance->getCacheFile(), $isOnline);
/**
* It's an online file
*/
$instance->getFileDownloader()
->download($pathToArchive, $instance->getZipCacheFile())
;
} else {
/**
* It's a local file
*/
if (!is_file($pathToArchive) || !is_readable($pathToArchive)) {
$instance->throwFileNotFound($pathToArchive);
}
if (!copy($pathToArchive, $instance->getZipCacheFile())) { if (true !== $return = $zip->open($instance->getCacheFile())) {
$translatedErrorMessage = $instance->getTranslator()->trans(
"An unknown error happend while copying %prev to %dest",
[
"%prev" => $pathToArchive,
"%dest" => $instance->getZipCacheFile(),
]
);
$instance->getLogger()
->error($translatedErrorMessage)
;
throw new \ErrorException($translatedErrorMessage);
}
}
if (true !== $return = $zip->open($instance->getZipCacheFile())) {
throw new ZipArchiveException( throw new ZipArchiveException(
$instance->getZipErrorMessage($return) $instance->getZipErrorMessage($return)
); );
@@ -627,11 +786,15 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
public function hasFile($pathToFile) public function hasFile($pathToFile)
{ {
return $this->zip return $this->zip
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
->locateName($this->formatFilePath($pathToFile)) !== false ->locateName($this->formatFilePath($pathToFile)) !== false
======= =======
->locateName($this->getFilePath($pathToFile)) !== false ->locateName($this->getFilePath($pathToFile)) !== false
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
=======
->locateName($this->formatFilePath($pathToFile)) !== false
>>>>>>> Finish implementing and testing zip
; ;
} }
@@ -647,11 +810,15 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
*/ */
public function hasDirectory($directory) public function hasDirectory($directory)
{ {
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
$link = $this->zip->locateName($this->formatDirectoryPath($directory)); $link = $this->zip->locateName($this->formatDirectoryPath($directory));
======= =======
$link = $this->zip->locateName($this->getDirectoryPath($directory)); $link = $this->zip->locateName($this->getDirectoryPath($directory));
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
=======
$link = $this->zip->locateName($this->formatDirectoryPath($directory));
>>>>>>> Finish implementing and testing zip
return $link !== false; return $link !== false;
} }
@@ -708,11 +875,15 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
======= =======
<<<<<<< HEAD
$cacheFileName = md5 (uniqid()); $cacheFileName = md5 (uniqid());
$cacheFile = $this->getArchiveBuilderCacheDirectory($environment) . DS; $cacheFile = $this->getArchiveBuilderCacheDirectory($environment) . DS;
$cacheFile .= $cacheFileName . "." . $this->getExtension(); $cacheFile .= $cacheFileName . "." . $this->getExtension();
>>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources >>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources
=======
$cacheFile = $this->generateCacheFile($environment);
>>>>>>> Finish implementing and testing zip
if (file_exists($cacheFile)) { if (file_exists($cacheFile)) {
unlink($cacheFile); unlink($cacheFile);
@@ -742,6 +913,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
); );
} }
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
$this->cacheFile = $cacheFile; $this->cacheFile = $cacheFile;
@@ -751,6 +923,9 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
======= =======
$this->zipCacheFile = $cacheFile; $this->zipCacheFile = $cacheFile;
>>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources >>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources
=======
$this->cacheFile = $cacheFile;
>>>>>>> Finish implementing and testing zip
return $this; return $this;
} }
@@ -822,11 +997,15 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
public function commit() public function commit()
{ {
$this->zip->close(); $this->zip->close();
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
$result = $this->zip->open($this->getCacheFile()); $result = $this->zip->open($this->getCacheFile());
======= =======
$result = $this->zip->open($this->getZipCacheFile()); $result = $this->zip->open($this->getZipCacheFile());
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
=======
$result = $this->zip->open($this->getCacheFile());
>>>>>>> Finish implementing and testing zip
if ($result !== true) { if ($result !== true) {
throw new \ErrorException( throw new \ErrorException(
@@ -849,11 +1028,15 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
* *
* Gives a valid file path for \ZipArchive * Gives a valid file path for \ZipArchive
*/ */
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
public function formatFilePath($initialString) public function formatFilePath($initialString)
======= =======
public function getFilePath($initialString) public function getFilePath($initialString)
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
=======
public function formatFilePath($initialString)
>>>>>>> Finish implementing and testing zip
{ {
/** /**
* Remove the / at the beginning and the end. * Remove the / at the beginning and the end.
@@ -885,6 +1068,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
* *
* Gives a valid directory path for \ZipArchive * Gives a valid directory path for \ZipArchive
*/ */
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
public function formatDirectoryPath($initialString) public function formatDirectoryPath($initialString)
{ {
@@ -893,17 +1077,25 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
if ($initialString !== "" && $initialString[0] !== "/") { if ($initialString !== "" && $initialString[0] !== "/") {
======= =======
public function getDirectoryPath($initialString) public function getDirectoryPath($initialString)
=======
public function formatDirectoryPath($initialString)
>>>>>>> Finish implementing and testing zip
{ {
$initialString = $this->getFilePath($initialString); $initialString = $this->formatFilePath($initialString);
<<<<<<< HEAD
if ($initialString[0] !== "/") { if ($initialString[0] !== "/") {
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
=======
if ($initialString !== "" && $initialString[0] !== "/") {
>>>>>>> Finish implementing and testing zip
$initialString = "/" . $initialString; $initialString = "/" . $initialString;
} }
return $initialString . "/"; return $initialString . "/";
} }
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
======= =======
public function throwFileNotFound($file) public function throwFileNotFound($file)
@@ -921,6 +1113,8 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
} }
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
=======
>>>>>>> Finish implementing and testing zip
/** /**
* @return string * @return string
* *
@@ -991,6 +1185,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
return $this->zip; return $this->zip;
} }
<<<<<<< HEAD <<<<<<< HEAD
<<<<<<< HEAD
} }
======= =======
@@ -1009,3 +1204,6 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
======= =======
} }
>>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources >>>>>>> Begin tar, tar.bz2 and tar.gz formatter, fix zip test resources
=======
}
>>>>>>> Finish implementing and testing zip

View File

@@ -11,6 +11,7 @@
/*************************************************************************************/ /*************************************************************************************/
namespace Thelia\Core\FileFormat\Archive; namespace Thelia\Core\FileFormat\Archive;
use Thelia\Tools\FileDownload\FileDownloaderInterface;
/** /**
* Interface ArchiveBuilderInterface * Interface ArchiveBuilderInterface
@@ -43,7 +44,11 @@ interface ArchiveBuilderInterface
* @return $this * @return $this
* @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotFoundException
* @throws \Thelia\Exception\FileNotReadableException * @throws \Thelia\Exception\FileNotReadableException
<<<<<<< HEAD
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
=======
* @throws \ErrorException
>>>>>>> Finish implementing and testing zip
* *
* This methods adds a file in the archive. * This methods adds a file in the archive.
* If the file is local, $isOnline must be false, * If the file is local, $isOnline must be false,
@@ -52,10 +57,16 @@ interface ArchiveBuilderInterface
public function addFile($filePath, $directoryInArchive = "/", $name = null, $isOnline = false); public function addFile($filePath, $directoryInArchive = "/", $name = null, $isOnline = false);
/** /**
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
* @param $content * @param $content
* @param $name * @param $name
* @param string $directoryInArchive * @param string $directoryInArchive
=======
* @param $content
* @param $name
* @param string $directoryInArchive
>>>>>>> Finish implementing and testing zip
* @return mixed * @return mixed
* @throws \ErrorException * @throws \ErrorException
* *
@@ -64,7 +75,11 @@ interface ArchiveBuilderInterface
public function addFileFromString($content, $name, $directoryInArchive = "/"); public function addFileFromString($content, $name, $directoryInArchive = "/");
/** /**
<<<<<<< HEAD
* @param string $pathToFile * @param string $pathToFile
=======
* @param string $pathToFile
>>>>>>> Finish implementing and testing zip
* @return null|string * @return null|string
* @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotFoundException
* @throws \Thelia\Exception\FileNotReadableException * @throws \Thelia\Exception\FileNotReadableException
@@ -74,6 +89,7 @@ interface ArchiveBuilderInterface
*/ */
public function getFileContent($pathToFile); public function getFileContent($pathToFile);
/** /**
<<<<<<< HEAD
* @param $pathInArchive * @param $pathInArchive
* @return $this * @return $this
* @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotFoundException
@@ -83,6 +99,12 @@ interface ArchiveBuilderInterface
* @return $this * @return $this
* @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotFoundException
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
=======
* @param $pathInArchive
* @return $this
* @throws \Thelia\Exception\FileNotFoundException
* @throws \ErrorException
>>>>>>> Finish implementing and testing zip
* *
* This method deletes a file in the archive * This method deletes a file in the archive
*/ */
@@ -90,6 +112,9 @@ interface ArchiveBuilderInterface
/** /**
<<<<<<< HEAD <<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> Finish implementing and testing zip
* @param $directoryPath * @param $directoryPath
* @return $this * @return $this
* @throws \ErrorException * @throws \ErrorException
@@ -97,11 +122,15 @@ interface ArchiveBuilderInterface
* This method creates an empty directory * This method creates an empty directory
*/ */
public function addDirectory($directoryPath); public function addDirectory($directoryPath);
<<<<<<< HEAD
/** /**
* @params string $filename * @params string $filename
======= =======
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
=======
/**
>>>>>>> Finish implementing and testing zip
* @return \Thelia\Core\HttpFoundation\Response * @return \Thelia\Core\HttpFoundation\Response
* *
* This method return an instance of a Response with the archive as content. * This method return an instance of a Response with the archive as content.
@@ -117,19 +146,28 @@ interface ArchiveBuilderInterface
/** /**
* @param string $pathToArchive * @param string $pathToArchive
* @param string $environment
* @param bool $isOnline * @param bool $isOnline
<<<<<<< HEAD
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
=======
* @param FileDownloaderInterface $fileDownloader
>>>>>>> Finish implementing and testing zip
* @return $this * @return $this
* @throws \Thelia\Exception\FileNotFoundException * @throws \Thelia\Exception\FileNotFoundException
* @throws \Thelia\Exception\HttpUrlException * @throws \Thelia\Exception\HttpUrlException
* *
* Loads an archive * Loads an archive
*/ */
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
public function loadArchive($pathToArchive, $isOnline = false); public function loadArchive($pathToArchive, $isOnline = false);
======= =======
public static function loadArchive($pathToArchive, $environment, $isOnline = false); public static function loadArchive($pathToArchive, $environment, $isOnline = false);
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
=======
public static function loadArchive($pathToArchive, $environment, $isOnline = false, FileDownloaderInterface $fileDownloader = null);
>>>>>>> Finish implementing and testing zip
/** /**
* @param $pathToFile * @param $pathToFile

View File

@@ -33,11 +33,19 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase
Tlog::getNewInstance(); Tlog::getNewInstance();
$this->tar = new TarArchiveBuilder(); $this->tar = new TarArchiveBuilder();
<<<<<<< HEAD
$this->tar->setEnvironment("dev"); $this->tar->setEnvironment("dev");
=======
>>>>>>> Finish implementing and testing zip
} }
public function testAddFileAndDirectory() public function testAddFileAndDirectory()
{ {
<<<<<<< HEAD
=======
$this->tar->setEnvironment("dev");
>>>>>>> Finish implementing and testing zip
/** /**
* File * File
*/ */
@@ -82,6 +90,7 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($this->tar->hasDirectory("bar")); $this->assertTrue($this->tar->hasDirectory("bar"));
} }
<<<<<<< HEAD
public function testAddValidFileFromString() public function testAddValidFileFromString()
{ {
@@ -289,3 +298,6 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase
); );
} }
} }
=======
}
>>>>>>> Finish implementing and testing zip

View File

@@ -73,84 +73,121 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase
{ {
$this->assertEquals( $this->assertEquals(
"foo", "foo",
<<<<<<< HEAD
$this->zip->getFilePath("foo") $this->zip->getFilePath("foo")
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
=======
$this->zip->formatFilePath("foo")
>>>>>>> Finish implementing and testing zip
); );
$this->assertEquals( $this->assertEquals(
"foo", "foo",
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
$this->zip->formatFilePath("/foo") $this->zip->formatFilePath("/foo")
======= =======
$this->zip->getFilePath("/foo") $this->zip->getFilePath("/foo")
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
=======
$this->zip->formatFilePath("/foo")
>>>>>>> Finish implementing and testing zip
); );
$this->assertEquals( $this->assertEquals(
"foo", "foo",
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
$this->zip->formatFilePath("foo/") $this->zip->formatFilePath("foo/")
======= =======
$this->zip->getFilePath("foo/") $this->zip->getFilePath("foo/")
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
=======
$this->zip->formatFilePath("foo/")
>>>>>>> Finish implementing and testing zip
); );
$this->assertEquals( $this->assertEquals(
"foo", "foo",
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
$this->zip->formatFilePath("/foo/") $this->zip->formatFilePath("/foo/")
======= =======
$this->zip->getFilePath("/foo/") $this->zip->getFilePath("/foo/")
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
=======
$this->zip->formatFilePath("/foo/")
>>>>>>> Finish implementing and testing zip
); );
$this->assertEquals( $this->assertEquals(
"/foo/bar", "/foo/bar",
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
$this->zip->formatFilePath("foo/bar") $this->zip->formatFilePath("foo/bar")
======= =======
$this->zip->getFilePath("foo/bar") $this->zip->getFilePath("foo/bar")
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
=======
$this->zip->formatFilePath("foo/bar")
>>>>>>> Finish implementing and testing zip
); );
$this->assertEquals( $this->assertEquals(
"/foo/bar", "/foo/bar",
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
$this->zip->formatFilePath("/foo/bar") $this->zip->formatFilePath("/foo/bar")
======= =======
$this->zip->getFilePath("/foo/bar") $this->zip->getFilePath("/foo/bar")
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
=======
$this->zip->formatFilePath("/foo/bar")
>>>>>>> Finish implementing and testing zip
); );
$this->assertEquals( $this->assertEquals(
"/foo/bar", "/foo/bar",
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
$this->zip->formatFilePath("/foo//bar/") $this->zip->formatFilePath("/foo//bar/")
======= =======
$this->zip->getFilePath("/foo//bar/") $this->zip->getFilePath("/foo//bar/")
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
=======
$this->zip->formatFilePath("/foo//bar/")
>>>>>>> Finish implementing and testing zip
); );
$this->assertEquals( $this->assertEquals(
"/foo/bar", "/foo/bar",
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
$this->zip->formatFilePath("/foo/bar/") $this->zip->formatFilePath("/foo/bar/")
======= =======
$this->zip->getFilePath("/foo/bar/") $this->zip->getFilePath("/foo/bar/")
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
=======
$this->zip->formatFilePath("/foo/bar/")
>>>>>>> Finish implementing and testing zip
); );
$this->assertEquals( $this->assertEquals(
"/foo/bar/baz", "/foo/bar/baz",
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
$this->zip->formatFilePath("foo/bar/baz") $this->zip->formatFilePath("foo/bar/baz")
======= =======
$this->zip->getFilePath("foo/bar/baz") $this->zip->getFilePath("foo/bar/baz")
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
=======
$this->zip->formatFilePath("foo/bar/baz")
>>>>>>> Finish implementing and testing zip
); );
$this->assertEquals( $this->assertEquals(
"/foo/bar/baz", "/foo/bar/baz",
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
$this->zip->formatFilePath("//foo/bar///baz/") $this->zip->formatFilePath("//foo/bar///baz/")
); );
@@ -163,6 +200,9 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase
$this->zip->formatDirectoryPath("foo") $this->zip->formatDirectoryPath("foo")
======= =======
$this->zip->getFilePath("//foo/bar///baz/") $this->zip->getFilePath("//foo/bar///baz/")
=======
$this->zip->formatFilePath("//foo/bar///baz/")
>>>>>>> Finish implementing and testing zip
); );
} }
@@ -170,89 +210,129 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase
{ {
$this->assertEquals( $this->assertEquals(
"/foo/", "/foo/",
<<<<<<< HEAD
$this->zip->getDirectoryPath("foo") $this->zip->getDirectoryPath("foo")
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
=======
$this->zip->formatDirectoryPath("foo")
>>>>>>> Finish implementing and testing zip
); );
$this->assertEquals( $this->assertEquals(
"/foo/", "/foo/",
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
$this->zip->formatDirectoryPath("/foo") $this->zip->formatDirectoryPath("/foo")
======= =======
$this->zip->getDirectoryPath("/foo") $this->zip->getDirectoryPath("/foo")
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
=======
$this->zip->formatDirectoryPath("/foo")
>>>>>>> Finish implementing and testing zip
); );
$this->assertEquals( $this->assertEquals(
"/foo/", "/foo/",
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
$this->zip->formatDirectoryPath("foo/") $this->zip->formatDirectoryPath("foo/")
======= =======
$this->zip->getDirectoryPath("foo/") $this->zip->getDirectoryPath("foo/")
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
=======
$this->zip->formatDirectoryPath("foo/")
>>>>>>> Finish implementing and testing zip
); );
$this->assertEquals( $this->assertEquals(
"/foo/", "/foo/",
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
$this->zip->formatDirectoryPath("/foo/") $this->zip->formatDirectoryPath("/foo/")
======= =======
$this->zip->getDirectoryPath("/foo/") $this->zip->getDirectoryPath("/foo/")
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
=======
$this->zip->formatDirectoryPath("/foo/")
>>>>>>> Finish implementing and testing zip
); );
$this->assertEquals( $this->assertEquals(
"/foo/bar/", "/foo/bar/",
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
$this->zip->formatDirectoryPath("foo/bar") $this->zip->formatDirectoryPath("foo/bar")
======= =======
$this->zip->getDirectoryPath("foo/bar") $this->zip->getDirectoryPath("foo/bar")
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
=======
$this->zip->formatDirectoryPath("foo/bar")
>>>>>>> Finish implementing and testing zip
); );
$this->assertEquals( $this->assertEquals(
"/foo/bar/", "/foo/bar/",
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
$this->zip->formatDirectoryPath("/foo/bar") $this->zip->formatDirectoryPath("/foo/bar")
======= =======
$this->zip->getDirectoryPath("/foo/bar") $this->zip->getDirectoryPath("/foo/bar")
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
=======
$this->zip->formatDirectoryPath("/foo/bar")
>>>>>>> Finish implementing and testing zip
); );
$this->assertEquals( $this->assertEquals(
"/foo/bar/", "/foo/bar/",
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
$this->zip->formatDirectoryPath("/foo//bar/") $this->zip->formatDirectoryPath("/foo//bar/")
======= =======
$this->zip->getDirectoryPath("/foo//bar/") $this->zip->getDirectoryPath("/foo//bar/")
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
=======
$this->zip->formatDirectoryPath("/foo//bar/")
>>>>>>> Finish implementing and testing zip
); );
$this->assertEquals( $this->assertEquals(
"/foo/bar/", "/foo/bar/",
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
$this->zip->formatDirectoryPath("/foo/bar/") $this->zip->formatDirectoryPath("/foo/bar/")
======= =======
$this->zip->getDirectoryPath("/foo/bar/") $this->zip->getDirectoryPath("/foo/bar/")
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
=======
$this->zip->formatDirectoryPath("/foo/bar/")
>>>>>>> Finish implementing and testing zip
); );
$this->assertEquals( $this->assertEquals(
"/foo/bar/baz/", "/foo/bar/baz/",
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
$this->zip->formatDirectoryPath("foo/bar/baz") $this->zip->formatDirectoryPath("foo/bar/baz")
======= =======
$this->zip->getDirectoryPath("foo/bar/baz") $this->zip->getDirectoryPath("foo/bar/baz")
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
=======
$this->zip->formatDirectoryPath("foo/bar/baz")
>>>>>>> Finish implementing and testing zip
); );
$this->assertEquals( $this->assertEquals(
"/foo/bar/baz/", "/foo/bar/baz/",
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
$this->zip->formatDirectoryPath("//foo/bar///baz/") $this->zip->formatDirectoryPath("//foo/bar///baz/")
======= =======
$this->zip->getDirectoryPath("//foo/bar///baz/") $this->zip->getDirectoryPath("//foo/bar///baz/")
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
=======
$this->zip->formatDirectoryPath("//foo/bar///baz/")
>>>>>>> Finish implementing and testing zip
); );
} }
@@ -274,11 +354,15 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase
} }
/** /**
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
* @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\ZipArchiveException * @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\ZipArchiveException
======= =======
* @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\ZipArchiveException * @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\ZipArchiveException
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
=======
* @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\ZipArchiveException
>>>>>>> Finish implementing and testing zip
* @expectedExceptionMessage [Zip Error] The file is not a zip archive * @expectedExceptionMessage [Zip Error] The file is not a zip archive
*/ */
public function testLoadNotValidZip() public function testLoadNotValidZip()
@@ -327,11 +411,15 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase
} }
/** /**
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
* @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\ZipArchiveException * @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\ZipArchiveException
======= =======
* @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\ZipArchiveException * @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\ZipArchiveException
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
=======
* @expectedException \Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\ZipArchiveException
>>>>>>> Finish implementing and testing zip
* @expectedExceptionMessage [Zip Error] The file is not a zip archive * @expectedExceptionMessage [Zip Error] The file is not a zip archive
*/ */
public function testLoadOnlineAvailableAndNotValidFile() public function testLoadOnlineAvailableAndNotValidFile()
@@ -489,6 +577,9 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase
); );
} }
<<<<<<< HEAD <<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> Finish implementing and testing zip
public function testAddValidFileFromString() public function testAddValidFileFromString()
{ {
@@ -504,6 +595,7 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase
"foo", "foo",
$this->loadedZip->getFileContent("bar") $this->loadedZip->getFileContent("bar")
); );
<<<<<<< HEAD
$this->loadedZip->addFileFromString( $this->loadedZip->addFileFromString(
"foo", "bar", "baz" "foo", "bar", "baz"
@@ -517,6 +609,8 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase
"foo", "foo",
$this->loadedZip->getFileContent("baz/bar") $this->loadedZip->getFileContent("baz/bar")
); );
=======
>>>>>>> Finish implementing and testing zip
} }
/** /**
@@ -547,7 +641,11 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase
); );
} }
<<<<<<< HEAD
} }
======= =======
} }
>>>>>>> Define archive builders and formatters >>>>>>> Define archive builders and formatters
=======
}
>>>>>>> Finish implementing and testing zip