modifié:         core/lib/Thelia/Core/FileFormat/Archive/AbstractArchiveBuilder.php
	modifié:         core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/TarArchiveException.php
	modifié:         core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/Exception/ZipArchiveException.php
	modifié:         core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilder.php
	modifié:         core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilder.php
	modifié:         core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilder.php
	modifié:         core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilder.php
	modifié:         core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderInterface.php
	modifié:         core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php
	modifié:         core/lib/Thelia/Core/FileFormat/FormatInterface.php
	modifié:         core/lib/Thelia/Core/FileFormat/Formatter/AbstractFormatter.php
	modifié:         core/lib/Thelia/Core/FileFormat/Formatter/Exception/BadFormattedStringException.php
	nouveau fichier: core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php
	nouveau fichier: core/lib/Thelia/Core/FileFormat/Formatter/FormatterInterface.php
	modifié:         core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php
	modifié:         core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarArchiveBuilderTest.php
	modifié:         core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarBz2ArchiveBuilderTest.php
	modifié:         core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/TarGzArchiveBuilderTest.php
	modifié:         core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilder/ZipArchiveBuilderTest.php
	modifié:         core/lib/Thelia/Tests/FileFormat/Archive/ArchiveBuilderManagerTest.php
	modifié:         core/lib/Thelia/Tests/FileFormat/Formatter/FormatterManagerTest.php
	modifié:         core/lib/Thelia/Tests/Tools/FakeFileDownloader.php
	modifié:         core/lib/Thelia/Tests/Tools/FileDownloaderTest.php
This commit is contained in:
Benjamin Perche
2014-07-04 10:01:29 +02:00
parent 2702c20014
commit 671b0f3d73
23 changed files with 142 additions and 99 deletions

View File

@@ -132,7 +132,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
} }
try { try {
$this->tar->addFromString($name, $content); $this->tar->addFromString($name, $content);
} catch(\Exception $e) { } catch (\Exception $e) {
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,7 +144,6 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
} }
} }
/** /**
* @param $directoryPath * @param $directoryPath
* @return $this * @return $this
@@ -160,7 +159,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
try { try {
$this->tar->addEmptyDir($directoryInArchive); $this->tar->addEmptyDir($directoryInArchive);
} catch(\Exception $e) { } catch (\Exception $e) {
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",
@@ -206,7 +205,6 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
return $content; return $content;
} }
/** /**
* @param $pathInArchive * @param $pathInArchive
* @return $this * @return $this
@@ -292,6 +290,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
* This throws TarArchiveBuilderException if * This throws TarArchiveBuilderException if
* the archive is not valid. * the archive is not valid.
*/ */
return $tar->setEnvironment($tar->environment); return $tar->setEnvironment($tar->environment);
} }
@@ -312,13 +311,13 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
/** @var \PharFileInfo $fileInfo */ /** @var \PharFileInfo $fileInfo */
$fileInfo = $this->tar[$pathToFile]; $fileInfo = $this->tar[$pathToFile];
if($fileInfo->isFile()) { if ($fileInfo->isFile()) {
$isFile = true; $isFile = true;
} }
/** /**
* Catch the exception to avoid its displaying. * Catch the exception to avoid its displaying.
*/ */
} catch(\BadMethodCallException $e) {} } catch (\BadMethodCallException $e) {}
return $isFile; return $isFile;
} }
@@ -338,13 +337,13 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
/** @var \PharFileInfo $fileInfo */ /** @var \PharFileInfo $fileInfo */
$fileInfo = $this->tar[$pathToDir]; $fileInfo = $this->tar[$pathToDir];
if($fileInfo->isDir()) { if ($fileInfo->isDir()) {
$isDir = true; $isDir = true;
} }
/** /**
* Catch the exception to avoid its displaying. * Catch the exception to avoid its displaying.
*/ */
} catch(\BadMethodCallException $e) {} } catch (\BadMethodCallException $e) {}
return $isDir; return $isDir;
} }
@@ -383,13 +382,12 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
$this->compressionEntryPoint(); $this->compressionEntryPoint();
} catch (\BadMethodCallException $e) {
} catch(\BadMethodCallException $e) {
/** /**
* 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";
} catch(\UnexpectedValueException $e) { } catch (\UnexpectedValueException $e) {
$errorMessage = "The file %file is corrupted"; $errorMessage = "The file %file is corrupted";
} }

View File

@@ -47,7 +47,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
* On the destruction of the class, * On the destruction of the class,
* remove the temporary file. * remove the temporary file.
*/ */
function __destruct() public function __destruct()
{ {
if ($this->zip instanceof \ZipArchive) { if ($this->zip instanceof \ZipArchive) {
@$this->zip->close(); @$this->zip->close();
@@ -80,7 +80,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
* Add empty directory if it doesn't exist * Add empty directory if it doesn't exist
*/ */
if(!empty($directoryInArchive)) { if (!empty($directoryInArchive)) {
$this->addDirectory($directoryInArchive); $this->addDirectory($directoryInArchive);
} }
@@ -244,6 +244,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
if (preg_match("#\/?[^\/]+\/[^\/]+\/?#", $initialString)) { if (preg_match("#\/?[^\/]+\/[^\/]+\/?#", $initialString)) {
$initialString = "/" . $initialString; $initialString = "/" . $initialString;
} }
return $initialString; return $initialString;
} }
@@ -417,7 +418,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
\ZipArchive::CREATE \ZipArchive::CREATE
); );
if($opening !== true) { if ($opening !== true) {
throw new \ErrorException( throw new \ErrorException(
$this->translator->trans( $this->translator->trans(
"An unknown error append" "An unknown error append"
@@ -531,6 +532,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
if (preg_match("#\/?[^\/]+\/[^/]+\/?#", $initialString)) { if (preg_match("#\/?[^\/]+\/[^/]+\/?#", $initialString)) {
$initialString = "/" . $initialString; $initialString = "/" . $initialString;
} }
return $initialString; return $initialString;
} }

View File

@@ -12,7 +12,6 @@
namespace Thelia\Core\FileFormat\Archive; namespace Thelia\Core\FileFormat\Archive;
/** /**
* Interface ArchiveBuilderInterface * Interface ArchiveBuilderInterface
* @package Thelia\Core\FileFormat\Archive * @package Thelia\Core\FileFormat\Archive

View File

@@ -18,24 +18,7 @@ use Thelia\Core\FileFormat\FormatInterface;
* @package Thelia\Core\FileFormat\Formatter * @package Thelia\Core\FileFormat\Formatter
* @author Benjamin Perche <bperche@openstudio.fr> * @author Benjamin Perche <bperche@openstudio.fr>
*/ */
abstract class AbstractFormatter implements FormatInterface abstract class AbstractFormatter implements FormatInterface, FormatterInterface
{ {
/**
* @param array $data
* @return mixed
*
* Encodes an array to the desired format.
* $data array only contains array and scalar data.
*/
abstract public function encode(array $data);
/**
* @param $data
* @return array
* @throws \Thelia\Core\FileFormat\Formatter\Exception\BadFormattedStringException
*
* this method must do exactly the opposite of encode and return
* an array composed of array and scalar data.
*/
abstract public function decode($data);
} }

View File

@@ -0,0 +1,23 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Core\FileFormat\Formatter;
/**
* Class FormatterData
* @package Thelia\Core\FileFormat\Formatter
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class FormatterData
{
}

View File

@@ -0,0 +1,39 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Core\FileFormat\Formatter;
/**
* Interface FormatterInterface
* @package Thelia\Core\FileFormat\Formatter
* @author Benjamin Perche <bperche@openstudio.fr>
*/
interface FormatterInterface
{
/**
* @param FormatterData $data
* @return mixed
*
* This method must use a FormatterData object and output
* a formatted value.
*/
public function encode(FormatterData $data);
/**
* @param $rawData
* @return FormatterData
*
* This must takes raw data as argument and outputs
* a FormatterData object.
*/
public function decode($rawData);
}

View File

@@ -12,7 +12,6 @@
namespace Thelia\Tests\FileFormat\Archive\ArchiveBuilder; namespace Thelia\Tests\FileFormat\Archive\ArchiveBuilder;
use Thelia\Core\FileFormat\Archive\ArchiveBuilder\TarGzArchiveBuilder; use Thelia\Core\FileFormat\Archive\ArchiveBuilder\TarGzArchiveBuilder;
use Thelia\Core\HttpFoundation\Response;
/** /**
* Class TarGzArchiveBuilderTest * Class TarGzArchiveBuilderTest