Remove conflicts
modifié: core/lib/Thelia/Core/FileFormat/Formatting/AbstractFormatter.php modifié: core/lib/Thelia/Core/FileFormat/Formatting/FormatterData.php modifié: core/lib/Thelia/Tests/FileFormat/Formatting/FormatterDataTest.php
This commit is contained in:
@@ -12,6 +12,11 @@
|
|||||||
|
|
||||||
namespace Thelia\Core\FileFormat\Formatting;
|
namespace Thelia\Core\FileFormat\Formatting;
|
||||||
use Thelia\Core\FileFormat\FormatInterface;
|
use Thelia\Core\FileFormat\FormatInterface;
|
||||||
|
<<<<<<< HEAD
|
||||||
|
=======
|
||||||
|
use Thelia\Core\Translation\Translator;
|
||||||
|
use Thelia\Log\Tlog;
|
||||||
|
>>>>>>> Remove conflicts
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class AbstractFormatter
|
* Class AbstractFormatter
|
||||||
@@ -20,5 +25,35 @@ use Thelia\Core\FileFormat\FormatInterface;
|
|||||||
*/
|
*/
|
||||||
abstract class AbstractFormatter implements FormatInterface, FormatterInterface
|
abstract class AbstractFormatter implements FormatInterface, FormatterInterface
|
||||||
{
|
{
|
||||||
|
<<<<<<< HEAD
|
||||||
|
|
||||||
|
=======
|
||||||
|
/** @var \Thelia\Core\Translation\Translator */
|
||||||
|
protected $translator;
|
||||||
|
|
||||||
|
/** @var \Thelia\Log\Tlog */
|
||||||
|
protected $logger;
|
||||||
|
|
||||||
|
/** @var array */
|
||||||
|
protected $aliases = array();
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->translator = Translator::getInstance();
|
||||||
|
|
||||||
|
$this->logger = Tlog::getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAliases(array $aliases)
|
||||||
|
{
|
||||||
|
$this->aliases = $aliases;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAliases()
|
||||||
|
{
|
||||||
|
return $this->aliases;
|
||||||
|
}
|
||||||
|
>>>>>>> Remove conflicts
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,11 @@ use Propel\Runtime\ActiveQuery\ModelCriteria;
|
|||||||
use Propel\Runtime\ActiveQuery\ModelJoin;
|
use Propel\Runtime\ActiveQuery\ModelJoin;
|
||||||
use Propel\Runtime\Map\TableMap;
|
use Propel\Runtime\Map\TableMap;
|
||||||
use Thelia\Core\Translation\Translator;
|
use Thelia\Core\Translation\Translator;
|
||||||
|
<<<<<<< HEAD
|
||||||
|
|
||||||
|
=======
|
||||||
|
use Thelia\Model\Map\ProductTableMap;
|
||||||
|
>>>>>>> Remove conflicts
|
||||||
/**
|
/**
|
||||||
* Class FormatterData
|
* Class FormatterData
|
||||||
* @package Thelia\Core\FileFormat\Formatting
|
* @package Thelia\Core\FileFormat\Formatting
|
||||||
@@ -25,7 +29,11 @@ use Thelia\Core\Translation\Translator;
|
|||||||
class FormatterData
|
class FormatterData
|
||||||
{
|
{
|
||||||
/** @var array */
|
/** @var array */
|
||||||
|
<<<<<<< HEAD
|
||||||
protected $data;
|
protected $data;
|
||||||
|
=======
|
||||||
|
protected $data = array();
|
||||||
|
>>>>>>> Remove conflicts
|
||||||
|
|
||||||
/** @var null|array */
|
/** @var null|array */
|
||||||
protected $aliases;
|
protected $aliases;
|
||||||
@@ -72,6 +80,10 @@ class FormatterData
|
|||||||
* @return $this
|
* @return $this
|
||||||
*
|
*
|
||||||
* Sets raw data with aliases
|
* Sets raw data with aliases
|
||||||
|
<<<<<<< HEAD
|
||||||
|
=======
|
||||||
|
* may bug with some formatter
|
||||||
|
>>>>>>> Remove conflicts
|
||||||
*/
|
*/
|
||||||
public function setData(array $data)
|
public function setData(array $data)
|
||||||
{
|
{
|
||||||
@@ -158,8 +170,80 @@ class FormatterData
|
|||||||
return $formattedData;
|
return $formattedData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
|
=======
|
||||||
|
/**
|
||||||
|
* @param array $row
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function addRow(array $row)
|
||||||
|
{
|
||||||
|
$this->data += [$this->applyAliases($row, $this->aliases)];
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $index
|
||||||
|
* @return array|bool
|
||||||
|
*/
|
||||||
|
public function popRow($index = 0)
|
||||||
|
{
|
||||||
|
$row = $this->getRow($index);
|
||||||
|
|
||||||
|
if (false !== $row) {
|
||||||
|
unset($this->data[$index]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $index
|
||||||
|
* @return array|bool
|
||||||
|
* @throws \OutOfBoundsException
|
||||||
|
*/
|
||||||
|
public function getRow($index = 0)
|
||||||
|
{
|
||||||
|
if (empty($this->data)) {
|
||||||
|
return false;
|
||||||
|
} elseif (!isset($this->data[$index])) {
|
||||||
|
throw new \OutOfBoundsException(
|
||||||
|
$this->translator->trans(
|
||||||
|
"Bad index value %idx",
|
||||||
|
[
|
||||||
|
"%idx" => $index
|
||||||
|
]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$row = $this->reverseAliases($this->data[$index], $this->aliases);
|
||||||
|
|
||||||
|
return $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $data
|
||||||
|
* @param array $aliases
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function reverseAliases(array $data, array $aliases)
|
||||||
|
{
|
||||||
|
return $this->applyAliases($data, array_flip($aliases));
|
||||||
|
}
|
||||||
|
|
||||||
|
>>>>>>> Remove conflicts
|
||||||
public function getData()
|
public function getData()
|
||||||
{
|
{
|
||||||
return $this->data;
|
return $this->data;
|
||||||
}
|
}
|
||||||
|
<<<<<<< HEAD
|
||||||
|
=======
|
||||||
|
|
||||||
|
public function getDataReverseAliases()
|
||||||
|
{
|
||||||
|
return $this->reverseAliases($this->data, $this->aliases);
|
||||||
|
}
|
||||||
|
>>>>>>> Remove conflicts
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -359,4 +359,109 @@ class FormatterDataTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($expectedData,$formattedData);
|
$this->assertEquals($expectedData,$formattedData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
|
=======
|
||||||
|
public function testSetRawDataMultipleDepthWithReverseAliases() {
|
||||||
|
$aliases = [
|
||||||
|
"orange" => "foo",
|
||||||
|
"blackberry" => "banana",
|
||||||
|
];
|
||||||
|
|
||||||
|
$formatterData = new FormatterData($aliases);
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
"orange" => "banana",
|
||||||
|
"apple" => "pear",
|
||||||
|
[
|
||||||
|
"orange" => "tomato",
|
||||||
|
"pepper" => "pear",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[
|
||||||
|
"strawberry" => "raspberry",
|
||||||
|
"blackberry" => "cranberry",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"cherry" => "lemon",
|
||||||
|
"mango" => "cranberry",
|
||||||
|
]
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$formattedData = $formatterData
|
||||||
|
->setData($data)
|
||||||
|
->getDataReverseAliases()
|
||||||
|
;
|
||||||
|
|
||||||
|
$this->assertEquals($data,$formattedData);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* That's why an alias MUST not be the same as a present value
|
||||||
|
*/
|
||||||
|
public function testSetRawDataMultipleDepthWithReverseAliasesFail() {
|
||||||
|
$aliases = [
|
||||||
|
"orange" => "cherry",
|
||||||
|
"blackberry" => "banana",
|
||||||
|
];
|
||||||
|
|
||||||
|
$formatterData = new FormatterData($aliases);
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
"orange" => "banana",
|
||||||
|
"apple" => "pear",
|
||||||
|
[
|
||||||
|
"orange" => "tomato",
|
||||||
|
"pepper" => "pear",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[
|
||||||
|
"strawberry" => "raspberry",
|
||||||
|
"blackberry" => "cranberry",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"cherry" => "lemon",
|
||||||
|
"mango" => "cranberry",
|
||||||
|
]
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$formattedData = $formatterData
|
||||||
|
->setData($data)
|
||||||
|
->getDataReverseAliases()
|
||||||
|
;
|
||||||
|
|
||||||
|
$this->assertNotEquals($data,$formattedData);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAddRow()
|
||||||
|
{
|
||||||
|
$data = new FormatterData();
|
||||||
|
|
||||||
|
$row = [
|
||||||
|
"title" => "A super book",
|
||||||
|
"author" => "Manu",
|
||||||
|
];
|
||||||
|
|
||||||
|
$data->addRow($row);
|
||||||
|
|
||||||
|
$this->assertEquals([$row], $data->getData());
|
||||||
|
$this->assertEquals($row, $data->getRow());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPopRow()
|
||||||
|
{
|
||||||
|
$data = new FormatterData();
|
||||||
|
|
||||||
|
$row = [
|
||||||
|
"title" => "A super book",
|
||||||
|
"author" => "Manu",
|
||||||
|
];
|
||||||
|
|
||||||
|
$data->addRow($row);
|
||||||
|
|
||||||
|
$this->assertEquals($row, $data->popRow());
|
||||||
|
$this->assertFalse($data->getRow());
|
||||||
|
}
|
||||||
|
>>>>>>> Remove conflicts
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user