-

-
: 40 : 1
-
: 165 : 0

 - e-mail

 

 -

   NF_hohol

 -

 LiveInternet.ru:
: 09.11.2007
:
:
: 38

:

(0)

HEDOMElement

, 17 2010 . 01:26 +

DOMElement DIV






echo $DOMElement;



 


<?

class HEDOMElement implements ArrayAccess

    
{

    CONST 
CDATA='{Value}';

    CONST 
COMPLETE='<{Tag} {Attributes}/>';

    CONST 
OPEN="<{Tag} {Attributes}>\r\n{Value}{ChildNodes}</{Tag}>";

    protected 
$Vars=Array(

                            
'Tag'=>Null,

                            
'Type'=>self::CDATA,

                            
'Value'=>Null,

                            
'ChildNodes'=>Null,

                            
'Attributes'=>Null,

                            );

    public function 
offsetExists($Offset)

        {

        return isset(
$this->Vars[$Offset]);

        }

    public function 
offsetGet($Offset)

        {

        return (isset(
$this->Vars[$Offset]))?$this->Vars[$Offset]:null;

        }

    public function 
offsetSet($Offset,$Value)

        {

        return 
False;

        }

    public function 
offsetUnset($Offset)

        {

        return 
False;

        }

    public function 
Keys()

        {

        return 
Array_Keys($this->Vars);

        }

    public function 
__construct($Type=self::CDATA,$Tag=Null)

        {

        
$this->Vars=Array(

                            
'Tag'=>$Tag,

                            
'Type'=>$Type,

                            
'Value'=>Null,

                            
'Attributes'=>new HEDOMElementAttributes(),

                            
'ChildNodes'=>new HEDOMElementChildNodes(),

                            );

        }

    public function 
SetValue($Value)

        {

        
$this->Vars['Value']=$Value;

        }

    public function 
SetAttribute($AttributeName,$AttributeValue)

        {

        
$this['Attributes'][StrToLower($AttributeName)]=$AttributeValue;

        }

    public function 
AppendChild(self $ChildNode,$Index=null)

        {

        if(
$Index) return $this['ChildNodes'][$Index]=$ChildNode;

        else return 
$this['ChildNodes'][]=$ChildNode;

        }

    public function 
__toString()

        {

        
$Vars=Array();

        Foreach(
$this->Keys() As $Key)

            {

            if(
$Key=='Value')

                {

                
$Vars["{{$Key}}"]=(trim($this[$Key])!=null)?"{$this[$Key]}\r\n":StrVal(Null);

                }

            else

                {

                
$Vars["{{$Key}}"]=$this[$Key];

                }

            }

        Return 
StrTr($this['Type'],$Vars);

        }

    }

class 
HEDOMElementAttributes Implements ArrayAccess

    
{

    protected 
$Vars=Array();

    public function 
offsetExists($Offset)

        {

        return isset(
$this->Vars[$Offset]);

        }

    public function 
offsetGet($Offset)

        {

        return (isset(
$this->Vars[$Offset]))?$this->Vars[$Offset]:null;

        }

    public function 
offsetSet($Offset,$Value)

        {

        
$this->Vars[StrToLower($Offset)]=$Value;

        }

    public function 
offsetUnset($Offset)

        {

        if(isset(
$this->Vars[$Offset]))unset($this->Vars[$Offset]);

        }

    public function 
Keys()

        {

        return 
Array_Keys($this->Vars);

        }

    public function 
__toString()

        {

        
$Vars=Array();

        Foreach(
$this->Keys() As $Key)

            {

            
$Value=HTMLSpecialChars($this[$Key]);

            
$Vars[]="{$Key}=\"{$Value}\"";

            }

        return 
implode(" ",$Vars);

        }

    }

class 
HEDOMElementChildNodes implements ArrayAccess

    
{

    protected 
$Vars=Array();

    public function 
offsetExists($Offset)

        {

        return isset(
$this->Vars[$Offset]);

        }

    public function 
offsetGet($Offset)

        {

        return (isset(
$this->Vars[$Offset]))?$this->Vars[$Offset]:null;

        }

    public function 
offsetSet($Offset,$Value)

        {

        if(
$Offset)$this->Vars[StrToLower($Offset)]=$Value;

        else 
$this->Vars[]=$Value;

        }

    public function 
offsetUnset($Offset)

        {

        if(isset(
$this->Vars[$Offset]))unset($this->Vars[$Offset]);

        }

    public function 
Keys()

        {

        return 
Array_Keys($this->Vars);

        }

    public function 
__toString()

        {

        
$Vars=Array();

        Foreach(
$this->Keys() As $Key)

            {

            
$Value=$this[$Key];

            
$Vars[]=$Value;

            }

        return (
count($Vars)>0)?implode("\r\n",$Vars)."\r\n":StrVal(Null);

        }

    }

$DOMElement=new HEDOMElement(HEDOMElement::OPEN,'div');

$DOMElement->SetAttribute('Style','border: 1px solid blue');

$DOMElement->SetValue('    DOMElement     DIV');

$Br=$DOMElement->AppendChild(new HEDOMElement(HEDOMElement::COMPLETE,'br'));

$Input=$DOMElement->AppendChild(new HEDOMElement(HEDOMElement::COMPLETE,'input'));

$Input->SetAttribute('Value','Value');

$Input->SetAttribute('Type','Button');

$Br=$DOMElement->AppendChild(new HEDOMElement(HEDOMElement::COMPLETE,'br'));

$CDATA=$DOMElement->AppendChild(new HEDOMElement());

$CDATA->SetValue('       '.highlight_string('echo $DOMElement;',true));

echo 
$DOMElement;




:  

 : [1]