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:
@@ -20,7 +20,7 @@ use Thelia\Core\Translation\Translator;
|
|||||||
*/
|
*/
|
||||||
class ArchiveBuilderManager
|
class ArchiveBuilderManager
|
||||||
{
|
{
|
||||||
protected $archiveCreators = array();
|
protected $archiveBuilders = array();
|
||||||
|
|
||||||
protected $environment;
|
protected $environment;
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ class ArchiveBuilderManager
|
|||||||
if (null !== $archiveCreator) {
|
if (null !== $archiveCreator) {
|
||||||
$archiveCreator->setEnvironment($this->environment);
|
$archiveCreator->setEnvironment($this->environment);
|
||||||
|
|
||||||
$this->archiveCreators[$archiveCreator->getName()] = $archiveCreator;
|
$this->archiveBuilders[$archiveCreator->getName()] = $archiveCreator;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@@ -50,18 +50,11 @@ class ArchiveBuilderManager
|
|||||||
*/
|
*/
|
||||||
public function delete($name)
|
public function delete($name)
|
||||||
{
|
{
|
||||||
if (!array_key_exists($name, $this->archiveCreators)) {
|
if (!array_key_exists($name, $this->archiveBuilders)) {
|
||||||
throw new \OutOfBoundsException(
|
$this->throwOutOfBounds($name);
|
||||||
Translator::getInstance()->trans(
|
|
||||||
"The archive creator %name doesn't exist",
|
|
||||||
[
|
|
||||||
"%name" => $name
|
|
||||||
]
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unset($this->archiveCreators[$name]);
|
unset($this->archiveBuilders[$name]);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -71,6 +64,27 @@ class ArchiveBuilderManager
|
|||||||
*/
|
*/
|
||||||
public function getAll()
|
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
|
||||||
|
]
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,8 @@
|
|||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
|
|
||||||
namespace Thelia\Core\FileFormat\Formatter;
|
namespace Thelia\Core\FileFormat\Formatter;
|
||||||
|
use Propel\Runtime\ActiveQuery\ModelCriteria;
|
||||||
|
use Thelia\Core\Translation\Translator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class FormatterData
|
* Class FormatterData
|
||||||
@@ -19,5 +21,28 @@ namespace Thelia\Core\FileFormat\Formatter;
|
|||||||
*/
|
*/
|
||||||
class FormatterData
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,14 +44,7 @@ class FormatterManager
|
|||||||
public function delete($name)
|
public function delete($name)
|
||||||
{
|
{
|
||||||
if (!array_key_exists($name, $this->formatters)) {
|
if (!array_key_exists($name, $this->formatters)) {
|
||||||
throw new \OutOfBoundsException(
|
$this->throwOutOfBounds($name);
|
||||||
Translator::getInstance()->trans(
|
|
||||||
"The formatter %name doesn't exist",
|
|
||||||
[
|
|
||||||
"%name" => $name
|
|
||||||
]
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unset($this->formatters[$name]);
|
unset($this->formatters[$name]);
|
||||||
@@ -59,6 +52,15 @@ class FormatterManager
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function get($name)
|
||||||
|
{
|
||||||
|
if (!array_key_exists($name, $this->formatters)) {
|
||||||
|
$this->throwOutOfBounds($name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->formatters[$name];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array[AbstractFormatter]
|
* @return array[AbstractFormatter]
|
||||||
*/
|
*/
|
||||||
@@ -66,4 +68,20 @@ class FormatterManager
|
|||||||
{
|
{
|
||||||
return $this->formatters;
|
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
|
||||||
|
]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,8 +45,8 @@ class FileDownloader implements FileDownloaderInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $url
|
* @param string $url
|
||||||
* @param string $pathToStore
|
* @param string $pathToStore
|
||||||
* @throws \Thelia\Exception\FileNotFoundException
|
* @throws \Thelia\Exception\FileNotFoundException
|
||||||
* @throws \ErrorException
|
* @throws \ErrorException
|
||||||
* @throws \HttpUrlException
|
* @throws \HttpUrlException
|
||||||
@@ -125,7 +125,7 @@ class FileDownloader implements FileDownloaderInterface
|
|||||||
*/
|
*/
|
||||||
$file = @fopen($pathToStore, "w");
|
$file = @fopen($pathToStore, "w");
|
||||||
|
|
||||||
if($file === false) {
|
if ($file === false) {
|
||||||
$translatedErrorMessage = $this->translator->trans(
|
$translatedErrorMessage = $this->translator->trans(
|
||||||
"Failed to open a writing stream on the file: %file",
|
"Failed to open a writing stream on the file: %file",
|
||||||
[
|
[
|
||||||
@@ -140,4 +140,4 @@ class FileDownloader implements FileDownloaderInterface
|
|||||||
fputs($file, $response);
|
fputs($file, $response);
|
||||||
fclose($file);
|
fclose($file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ trait FileDownloaderAwareTrait
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param FileDownloaderInterface $fileDownloader
|
* @param FileDownloaderInterface $fileDownloader
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setFileDownloader(FileDownloaderInterface $fileDownloader)
|
public function setFileDownloader(FileDownloaderInterface $fileDownloader)
|
||||||
@@ -44,4 +44,4 @@ trait FileDownloaderAwareTrait
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ namespace Thelia\Tools\FileDownload;
|
|||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Component\Translation\Translator;
|
use Symfony\Component\Translation\Translator;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class FileDownloader
|
* Class FileDownloader
|
||||||
* @package Thelia\Tools\FileDownload
|
* @package Thelia\Tools\FileDownload
|
||||||
@@ -23,8 +22,8 @@ use Symfony\Component\Translation\Translator;
|
|||||||
interface FileDownloaderInterface
|
interface FileDownloaderInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param string $url
|
* @param string $url
|
||||||
* @param string $pathToStore
|
* @param string $pathToStore
|
||||||
* @throws \Thelia\Exception\FileNotFoundException
|
* @throws \Thelia\Exception\FileNotFoundException
|
||||||
* @throws \ErrorException
|
* @throws \ErrorException
|
||||||
* @throws \HttpUrlException
|
* @throws \HttpUrlException
|
||||||
@@ -41,4 +40,4 @@ interface FileDownloaderInterface
|
|||||||
* Returns an hydrated instance
|
* Returns an hydrated instance
|
||||||
*/
|
*/
|
||||||
public static function getInstance();
|
public static function getInstance();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user