Clean code

This commit is contained in:
Laurent Destailleur 2022-01-26 14:42:26 +01:00
parent 0d66646052
commit 9180e9a5c6
2 changed files with 7 additions and 4 deletions

View File

@ -223,16 +223,17 @@ class Segment implements IteratorAggregate, Countable
*/
public function setVars($key, $value, $encode = true, $charset = 'ISO-8859')
{
if (strpos($this->xml, $this->odf->getConfig('DELIMITER_LEFT') . $key . $this->odf->getConfig('DELIMITER_RIGHT')) === false) {
$tag = $this->odf->getConfig('DELIMITER_LEFT') . $key . $this->odf->getConfig('DELIMITER_RIGHT');
if (strpos($this->xml, $tag) === false) {
//throw new SegmentException("var $key not found in {$this->getName()}");
}
$tag = $this->odf->getConfig('DELIMITER_LEFT') . $key . $this->odf->getConfig('DELIMITER_RIGHT');
$this->vars[$tag] = $this->odf->convertVarToOdf($value, $encode, $charset);
return $this;
}
/**
* Assign a template variable as a picture
*

View File

@ -122,7 +122,8 @@ class Odf
}
/**
* Assing a template variable
* Assing a template variable into ->vars.
* For example, key is {object_date} and value is '2021-01-01'
*
* @param string $key Name of the variable within the template
* @param string $value Replacement value
@ -134,6 +135,7 @@ class Odf
public function setVars($key, $value, $encode = true, $charset = 'ISO-8859')
{
$tag = $this->config['DELIMITER_LEFT'] . $key . $this->config['DELIMITER_RIGHT'];
// TODO Warning string may be:
// <text:span text:style-name="T13">{</text:span><text:span text:style-name="T12">aaa</text:span><text:span text:style-name="T13">}</text:span>
// instead of {aaa} so we should enhance this function.