I have trait ExportOptions
with two static variables and two functions.
Variables are $Code
and $ExportType
. Content of $ExportType
is set in function Set_ExportType
. And both variables meet each other in function Convert_ExportCode
.
Function Convert_ExportCode
has following simple code:
private function Convert_ExportCode()
{
switch(static::$ExportType)
{
/*
* writes code
*/
case UniT::UNIT_OPTION_END:
self::$GlobalCode[] = $this -> LocalCode;
$Text = preg_replace('/([\n]+)/', "\n", implode('', self::$GlobalCode));
self::$GlobalCode = array();
echo $Text;
break;
/*
* exports code without writing
*/
case UniT::UNIT_OPTION_STEP:
self::$GlobalCode[] = $this -> LocalCode;
$Text = preg_replace('/([\n]+)/', "\n", implode('', self::$GlobalCode));
self::$GlobalCode = array();
return $Text;
break;
/*
* saves part of code
*/
default:
self::$GlobalCode[] = $this -> LocalCode;
for($Order = 0; $Order < count(self::$GlobalCode); $Order++)
{
self::$GlobalCode[$Order] = preg_replace('/([\n]+)/', "\n", self::$GlobalCode[$Order]);
}
}
}
and it is (as whole trait, of course) used by three classes (CodeGenerator
, SimpleAssembler
, MenuAssembler_SelectOptgroup
). It would be not problem, if those classes could not use each other.
Class CodeGenerator
is used by both other classes - and class SimpleAssembler
is used by class MenuAssembler_SelectOptgroup
.
I know (because I tested it - and that class is on the first level) that CodeGenerator
accepts and outputs (and handles) content of variable self::$Code
as it should, even if it gets as text wrapped into any closed element code generated.
public function Execute()
{
$CodePartNumber = count(self::$Code);
/* some code that not handles with sel::$Code */
// base of code storage into self::$Code
self::$Code[$CodePartNumber] = $this -> Get_AssembledCode(/* arguments for vsprintf */);
return $this -> Convert_ExportCode();
}
Class SimpleAssembler
assembles and stores code in similar way:
public function Execute()
{
$this -> Check_Orders();
$CodePartNumber = count(self::$Code);
/*
* generation of sub-level
*/
for($Order = 0; $Order < count($this -> Content); $Order++)
{
$VMaX = new CodeGenerator($this -> Elements['sub']['main']);
$VMaX -> Set_Text((empty($this -> Content[$Order]) ? '' : $this -> Content[$Order] ));
if($Order < count($this -> Content)-1 )
{
$VMaX -> Set_ExportType(UniT::UNIT_OPTION_GOON);
$VMaX -> Execute();
}
else
{
$VMaX -> Set_ExportType(UniT::UNIT_OPTION_STEP);
self::$Code[$CodePartNumber] = $VMaX -> Execute();
}
}
if($this -> Disable_TopLevel == FALSE)
{
/*
* generation of top level element and inserting of columns into it
*/
$VMaX = new CodeGenerator($this -> Elements['top']['main']);
$VMaX -> Set_ExportType(static::$ExportType);
$VMaX -> Set_Text(self::$Code[$CodePartNumber]);
return $VMaX -> Execute();
}
else
{
return $this -> Convert_ExportCode();
}
}
But class 'SimpleAssembler' has a problem with accepting of content of this variable. And in final output is
<ol >
<ol >
<li >1</li>
<li >2</li>
<li >3</li>
</ol>
<li >4</li>
<li >5</li>
<li >6</li>
</ol>
instead
<ol >
<li >1</li>
<li >2</li>
<li >3</li>
</ol>
<ol >
<li >4</li>
<li >5</li>
<li >6</li>
</ol>
I would like to know how to solve it.
Edit:
I tried to use also non-static variable for in-class code storage between various operations - and give only final code to that static variable, and even if I added
$this -> LocalCode = NULL;
to constructor and destructor, result is still the same.
Edit:
I improved code in the beginning of question to new version, as is currently.