Fix cs and add get method in managers

modifié:         core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php
	modifié:         core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php
	modifié:         core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php
	modifié:         core/lib/Thelia/Tools/FileDownload/FileDownloader.php
	modifié:         core/lib/Thelia/Tools/FileDownload/FileDownloaderAwareTrait.php
	modifié:         core/lib/Thelia/Tools/FileDownload/FileDownloaderInterface.php
This commit is contained in:
Benjamin Perche
2014-07-04 13:44:28 +02:00
parent 2e4987a47c
commit c2720c9f2f
6 changed files with 122 additions and 9 deletions

View File

@@ -20,12 +20,16 @@ use Thelia\Core\Translation\Translator;
*/
class ArchiveBuilderManager
{
<<<<<<< HEAD
<<<<<<< HEAD
/** @var array */
protected $archiveBuilders = array();
=======
protected $archiveCreators = array();
>>>>>>> Define archive builders and formatters
=======
protected $archiveBuilders = array();
>>>>>>> Fix cs and add get method in managers
protected $environment;
@@ -57,8 +61,12 @@ class ArchiveBuilderManager
if (null !== $archiveCreator) {
$archiveCreator->setEnvironment($this->environment);
<<<<<<< HEAD
$this->archiveCreators[$archiveCreator->getName()] = $archiveCreator;
>>>>>>> Define archive builders and formatters
=======
$this->archiveBuilders[$archiveCreator->getName()] = $archiveCreator;
>>>>>>> Fix cs and add get method in managers
}
return $this;
@@ -71,6 +79,7 @@ class ArchiveBuilderManager
*/
public function delete($name)
{
<<<<<<< HEAD
<<<<<<< HEAD
if (!array_key_exists($name, $this->archiveBuilders)) {
$this->throwOutOfBounds($name);
@@ -91,6 +100,13 @@ class ArchiveBuilderManager
unset($this->archiveCreators[$name]);
>>>>>>> Define archive builders and formatters
=======
if (!array_key_exists($name, $this->archiveBuilders)) {
$this->throwOutOfBounds($name);
}
unset($this->archiveBuilders[$name]);
>>>>>>> Fix cs and add get method in managers
return $this;
}
@@ -145,7 +161,28 @@ class ArchiveBuilderManager
*/
public function getAll()
{
return $this->archiveCreators;
return $this->archiveBuilders;
}
public function get($name)
{
if (!array_key_exists($name, $this->archiveBuilders)) {
$this->throwOutOfBounds($name);
}
return $this->archiveBuilders[$name];
}
protected function throwOutOfBounds($name)
{
throw new \OutOfBoundsException(
Translator::getInstance()->trans(
"The archive creator %name doesn't exist",
[
"%name" => $name
]
)
);
}
<<<<<<< HEAD
}

View File

@@ -11,6 +11,8 @@
/*************************************************************************************/
namespace Thelia\Core\FileFormat\Formatter;
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Thelia\Core\Translation\Translator;
/**
* Class FormatterData
@@ -19,5 +21,28 @@ namespace Thelia\Core\FileFormat\Formatter;
*/
class FormatterData
{
/** @var array */
protected $data;
/** @var Translator */
protected $translator;
public function __construct()
{
$this->translator = Translator::getInstance();
}
public function loadModelCriteria(ModelCriteria $criteria)
{
$propelData =
$criteria
->find()
;
if (empty($propelData)) {
return null;
}
}
}

View File

@@ -44,14 +44,7 @@ class FormatterManager
public function delete($name)
{
if (!array_key_exists($name, $this->formatters)) {
throw new \OutOfBoundsException(
Translator::getInstance()->trans(
"The formatter %name doesn't exist",
[
"%name" => $name
]
)
);
$this->throwOutOfBounds($name);
}
unset($this->formatters[$name]);
@@ -59,6 +52,15 @@ class FormatterManager
return $this;
}
public function get($name)
{
if (!array_key_exists($name, $this->formatters)) {
$this->throwOutOfBounds($name);
}
return $this->formatters[$name];
}
/**
* @return array[AbstractFormatter]
*/
@@ -66,4 +68,20 @@ class FormatterManager
{
return $this->formatters;
}
/**
* @param $name
* @throws \OutOfBoundsException
*/
protected function throwOutOfBounds($name)
{
throw new \OutOfBoundsException(
Translator::getInstance()->trans(
"The formatter %name doesn't exist",
[
"%name" => $name
]
)
);
}
}

View File

@@ -52,6 +52,7 @@ class FileDownloader implements FileDownloaderInterface
}
/**
<<<<<<< HEAD
<<<<<<< HEAD
* @param string $url
* @param string $pathToStore
@@ -59,6 +60,10 @@ class FileDownloader implements FileDownloaderInterface
* @param string $url
* @param string $pathToStore
>>>>>>> Define archive builders and formatters
=======
* @param string $url
* @param string $pathToStore
>>>>>>> Fix cs and add get method in managers
* @throws \Thelia\Exception\FileNotFoundException
* @throws \ErrorException
* @throws \HttpUrlException
@@ -137,11 +142,15 @@ class FileDownloader implements FileDownloaderInterface
*/
$file = @fopen($pathToStore, "w");
<<<<<<< HEAD
<<<<<<< HEAD
if ($file === false) {
=======
if($file === false) {
>>>>>>> Define archive builders and formatters
=======
if ($file === false) {
>>>>>>> Fix cs and add get method in managers
$translatedErrorMessage = $this->translator->trans(
"Failed to open a writing stream on the file: %file",
[
@@ -157,7 +166,11 @@ class FileDownloader implements FileDownloaderInterface
fclose($file);
}
<<<<<<< HEAD
<<<<<<< HEAD
}
=======
}
>>>>>>> Define archive builders and formatters
=======
}
>>>>>>> Fix cs and add get method in managers

View File

@@ -35,11 +35,15 @@ trait FileDownloaderAwareTrait
}
/**
<<<<<<< HEAD
<<<<<<< HEAD
* @param FileDownloaderInterface $fileDownloader
=======
* @param FileDownloaderInterface $fileDownloader
>>>>>>> Define archive builders and formatters
=======
* @param FileDownloaderInterface $fileDownloader
>>>>>>> Fix cs and add get method in managers
* @return $this
*/
public function setFileDownloader(FileDownloaderInterface $fileDownloader)
@@ -49,7 +53,11 @@ trait FileDownloaderAwareTrait
return $this;
}
<<<<<<< HEAD
<<<<<<< HEAD
}
=======
}
>>>>>>> Define archive builders and formatters
=======
}
>>>>>>> Fix cs and add get method in managers

View File

@@ -14,10 +14,13 @@ namespace Thelia\Tools\FileDownload;
use Psr\Log\LoggerInterface;
use Symfony\Component\Translation\Translator;
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> Define archive builders and formatters
=======
>>>>>>> Fix cs and add get method in managers
/**
* Class FileDownloader
* @package Thelia\Tools\FileDownload
@@ -26,6 +29,7 @@ use Symfony\Component\Translation\Translator;
interface FileDownloaderInterface
{
/**
<<<<<<< HEAD
<<<<<<< HEAD
* @param string $url
* @param string $pathToStore
@@ -33,6 +37,10 @@ interface FileDownloaderInterface
* @param string $url
* @param string $pathToStore
>>>>>>> Define archive builders and formatters
=======
* @param string $url
* @param string $pathToStore
>>>>>>> Fix cs and add get method in managers
* @throws \Thelia\Exception\FileNotFoundException
* @throws \ErrorException
* @throws \HttpUrlException
@@ -50,7 +58,11 @@ interface FileDownloaderInterface
*/
public static function getInstance();
<<<<<<< HEAD
<<<<<<< HEAD
}
=======
}
>>>>>>> Define archive builders and formatters
=======
}
>>>>>>> Fix cs and add get method in managers