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

@@ -201,7 +201,7 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder
}
/**
* @param string $environment
* @param string $environment
* @return $this
*
* Sets the execution environment of the Kernel,
@@ -211,4 +211,4 @@ abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilder
{
$this->environment = $environment;
}
}
}

View File

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

View File

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

View File

@@ -57,10 +57,10 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
}
/**
* @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
* @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
* @return $this
* @throws \Thelia\Exception\FileNotFoundException
* @throws \Thelia\Exception\FileNotReadableException
@@ -107,7 +107,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
/**
* @param $content
* @param $name
* @param string $directoryInArchive
* @param string $directoryInArchive
* @return mixed
* @throws \ErrorException
*
@@ -132,7 +132,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
}
try {
$this->tar->addFromString($name, $content);
} catch(\Exception $e) {
} catch (\Exception $e) {
throw new \ErrorException(
$this->translator->trans(
"Error while writing the file into the archive, error message: %errmes",
@@ -144,7 +144,6 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
}
}
/**
* @param $directoryPath
* @return $this
@@ -160,7 +159,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
try {
$this->tar->addEmptyDir($directoryInArchive);
} catch(\Exception $e) {
} catch (\Exception $e) {
throw new \ErrorException(
$this->translator->trans(
"The directory %dir has not been created in the archive",
@@ -176,7 +175,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
}
/**
* @param string $pathToFile
* @param string $pathToFile
* @return null|string
* @throws \Thelia\Exception\FileNotFoundException
* @throws \Thelia\Exception\FileNotReadableException
@@ -206,7 +205,6 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
return $content;
}
/**
* @param $pathInArchive
* @return $this
@@ -269,10 +267,10 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
}
/**
* @param string $pathToArchive
* @param string $environment
* @param bool $isOnline
* @param FileDownloaderInterface $fileDownloader
* @param string $pathToArchive
* @param string $environment
* @param bool $isOnline
* @param FileDownloaderInterface $fileDownloader
* @return $this
* @throws \Thelia\Exception\FileNotFoundException
* @throws \Thelia\Exception\HttpUrlException
@@ -292,6 +290,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
* This throws TarArchiveBuilderException if
* the archive is not valid.
*/
return $tar->setEnvironment($tar->environment);
}
@@ -312,19 +311,19 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
/** @var \PharFileInfo $fileInfo */
$fileInfo = $this->tar[$pathToFile];
if($fileInfo->isFile()) {
if ($fileInfo->isFile()) {
$isFile = true;
}
/**
* Catch the exception to avoid its displaying.
*/
} catch(\BadMethodCallException $e) {}
} catch (\BadMethodCallException $e) {}
return $isFile;
}
/**
* @param string $directory
* @param string $directory
* @return bool
*
* Check if the archive has a directory
@@ -338,19 +337,19 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
/** @var \PharFileInfo $fileInfo */
$fileInfo = $this->tar[$pathToDir];
if($fileInfo->isDir()) {
if ($fileInfo->isDir()) {
$isDir = true;
}
/**
* Catch the exception to avoid its displaying.
*/
} catch(\BadMethodCallException $e) {}
} catch (\BadMethodCallException $e) {}
return $isDir;
}
/**
* @param string $environment
* @param string $environment
* @return $this
*
* Sets the execution environment of the Kernel,
@@ -383,13 +382,12 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
$this->compressionEntryPoint();
} catch(\BadMethodCallException $e) {
} catch (\BadMethodCallException $e) {
/**
* This should not happen
*/
$errorMessage = "You have badly called the method setEnvironment twice for %file";
} catch(\UnexpectedValueException $e) {
} catch (\UnexpectedValueException $e) {
$errorMessage = "The file %file is corrupted";
}
@@ -411,7 +409,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
}
/**
* @param string $initialString
* @param string $initialString
* @return string
*
* Gives a valid file path for \ZipArchive
@@ -432,7 +430,7 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
}
/**
* @param string $initialString
* @param string $initialString
* @return string
*
* Gives a valid directory path for \ZipArchive
@@ -496,4 +494,4 @@ class TarArchiveBuilder extends AbstractArchiveBuilder
{
return $this->compression;
}
}
}

View File

@@ -44,4 +44,4 @@ class TarBz2ArchiveBuilder extends TarArchiveBuilder
return $this;
}
}
}

View File

@@ -49,4 +49,4 @@ class TarGzArchiveBuilder extends TarArchiveBuilder
return $this;
}
}
}

View File

@@ -47,7 +47,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
* On the destruction of the class,
* remove the temporary file.
*/
function __destruct()
public function __destruct()
{
if ($this->zip instanceof \ZipArchive) {
@$this->zip->close();
@@ -59,10 +59,10 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
}
/**
* @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
* @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
* @return $this
* @throws \Thelia\Exception\FileNotFoundException
* @throws \Thelia\Exception\FileNotReadableException
@@ -80,7 +80,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
* Add empty directory if it doesn't exist
*/
if(!empty($directoryInArchive)) {
if (!empty($directoryInArchive)) {
$this->addDirectory($directoryInArchive);
}
@@ -127,7 +127,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
/**
* @param $content
* @param $name
* @param string $directoryInArchive
* @param string $directoryInArchive
* @return mixed
* @throws \ErrorException
*
@@ -194,7 +194,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
}
/**
* @param string $pathToFile
* @param string $pathToFile
* @return null|string
* @throws \Thelia\Exception\FileNotFoundException
* @throws \Thelia\Exception\FileNotReadableException
@@ -224,7 +224,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
/**
* @param string $initialString
* @param string $initialString
* @return string
*
* Gives a valid file path for \ZipArchive
@@ -244,11 +244,12 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
if (preg_match("#\/?[^\/]+\/[^\/]+\/?#", $initialString)) {
$initialString = "/" . $initialString;
}
return $initialString;
}
/**
* @param string $initialString
* @param string $initialString
* @return string
*
* Gives a valid directory path for \ZipArchive
@@ -336,9 +337,9 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
}
/**
* @param string $pathToArchive
* @param bool $isOnline
* @param FileDownloaderInterface $fileDownloader
* @param string $pathToArchive
* @param bool $isOnline
* @param FileDownloaderInterface $fileDownloader
* @return ZipArchiveBuilder
* @throws \Thelia\Exception\FileNotFoundException
* @throws \Thelia\Exception\HttpUrlException
@@ -383,7 +384,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
}
/**
* @param string $directory
* @param string $directory
* @return bool
*
* Checks if the link $directory exists and if it's not a file.
@@ -396,7 +397,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
}
/**
* @param string $environment
* @param string $environment
* @return $this
*
* Sets the execution environment of the Kernel,
@@ -417,7 +418,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
\ZipArchive::CREATE
);
if($opening !== true) {
if ($opening !== true) {
throw new \ErrorException(
$this->translator->trans(
"An unknown error append"
@@ -511,7 +512,7 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
}
/**
* @param string $initialString
* @param string $initialString
* @return string
*
* Gives a valid file path for \ZipArchive
@@ -531,11 +532,12 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
if (preg_match("#\/?[^\/]+\/[^/]+\/?#", $initialString)) {
$initialString = "/" . $initialString;
}
return $initialString;
}
/**
* @param string $initialString
* @param string $initialString
* @return string
*
* Gives a valid directory path for \ZipArchive
@@ -598,4 +600,4 @@ class ZipArchiveBuilder extends AbstractArchiveBuilder
{
return $this->zip;
}
}
}

View File

@@ -12,7 +12,6 @@
namespace Thelia\Core\FileFormat\Archive;
/**
* Interface ArchiveBuilderInterface
* @package Thelia\Core\FileFormat\Archive
@@ -23,10 +22,10 @@ namespace Thelia\Core\FileFormat\Archive;
interface ArchiveBuilderInterface
{
/**
* @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
* @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
* @return $this
* @throws \Thelia\Exception\FileNotFoundException
* @throws \Thelia\Exception\FileNotReadableException
@@ -41,7 +40,7 @@ interface ArchiveBuilderInterface
/**
* @param $content
* @param $name
* @param string $directoryInArchive
* @param string $directoryInArchive
* @return mixed
* @throws \ErrorException
*
@@ -50,7 +49,7 @@ interface ArchiveBuilderInterface
public function addFileFromString($content, $name, $directoryInArchive = "/");
/**
* @param string $pathToFile
* @param string $pathToFile
* @return null|string
* @throws \Thelia\Exception\FileNotFoundException
* @throws \Thelia\Exception\FileNotReadableException
@@ -85,8 +84,8 @@ interface ArchiveBuilderInterface
public function buildArchiveResponse();
/**
* @param string $pathToArchive
* @param bool $isOnline
* @param string $pathToArchive
* @param bool $isOnline
* @return $this
* @throws \Thelia\Exception\FileNotFoundException
* @throws \Thelia\Exception\HttpUrlException
@@ -104,11 +103,11 @@ interface ArchiveBuilderInterface
public function hasFile($pathToFile);
/**
* @param string $directory
* @param string $directory
* @return bool
*
* Check if the archive has a directory
*/
public function hasDirectory($directory);
}
}

View File

@@ -29,7 +29,7 @@ class ArchiveBuilderManager
$this->environment = $environment;
}
/**
* @param AbstractArchiveBuilder $archiveCreator
* @param AbstractArchiveBuilder $archiveCreator
* @return $this
*/
public function add(AbstractArchiveBuilder $archiveCreator)
@@ -73,4 +73,4 @@ class ArchiveBuilderManager
{
return $this->archiveCreators;
}
}
}

View File

@@ -55,4 +55,4 @@ interface FormatInterface
* return "application/json";
*/
public function getMimeType();
}
}

View File

@@ -18,24 +18,7 @@ use Thelia\Core\FileFormat\FormatInterface;
* @package Thelia\Core\FileFormat\Formatter
* @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

@@ -20,4 +20,4 @@ namespace Thelia\Core\FileFormat\Formatter\Exception;
class BadFormattedStringException extends \ErrorException
{
}
}

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

@@ -18,7 +18,7 @@ use Thelia\Core\Translation\Translator;
* @package Thelia\Core\FileFormat\Formatter
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class FormatterManager
class FormatterManager
{
protected $formatters = array();
@@ -66,4 +66,4 @@ class FormatterManager
{
return $this->formatters;
}
}
}

View File

@@ -227,7 +227,7 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase
$this->tar->formatDirectoryPath("//foo/bar///baz/")
);
}
public function testFormatFilePath()
{
$this->assertEquals(
@@ -288,4 +288,4 @@ class TarArchiveBuilderTest extends \PHPUnit_Framework_TestCase
$this->tar->getCompression()
);
}
}
}

View File

@@ -35,4 +35,4 @@ class TarBz2ArchiveBuilderTest extends TarArchiveBuilderTest
$this->tar->getCompression()
);
}
}
}

View File

@@ -12,7 +12,6 @@
namespace Thelia\Tests\FileFormat\Archive\ArchiveBuilder;
use Thelia\Core\FileFormat\Archive\ArchiveBuilder\TarGzArchiveBuilder;
use Thelia\Core\HttpFoundation\Response;
/**
* Class TarGzArchiveBuilderTest
@@ -36,4 +35,4 @@ class TarGzArchiveBuilderTest extends TarArchiveBuilderTest
$this->tar->getCompression()
);
}
}
}

View File

@@ -395,4 +395,4 @@ class ZipArchiveBuilderTest extends \PHPUnit_Framework_TestCase
);
}
}
}

View File

@@ -72,4 +72,4 @@ class ArchiveBuilderManagerTest extends \PHPUnit_Framework_TestCase
$this->manager->delete("foo");
}
}
}

View File

@@ -71,4 +71,4 @@ class FormatterManagerTest extends \PHPUnit_Framework_TestCase
{
$this->manager->delete("foo");
}
}
}

View File

@@ -22,8 +22,8 @@ use Thelia\Tools\FileDownload\FileDownloader;
class FakeFileDownloader extends FileDownloader
{
/**
* @param string $url
* @param string $pathToStore
* @param string $url
* @param string $pathToStore
* @throws \Thelia\Exception\FileNotFoundException
* @throws \ErrorException
* @throws \HttpUrlException
@@ -41,4 +41,4 @@ class FakeFileDownloader extends FileDownloader
}
}
}
}

View File

@@ -60,4 +60,4 @@ class FileDownloaderTest extends \PHPUnit_Framework_TestCase
{
$this->downloader->download("https://github.com/thelia/thelia", "php://temp");
}
}
}