• Авторизация


Класс HEDOMElement и иже с ним 18-10-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;



вверх^ к полной версии понравилось! в evernote


Вы сейчас не можете прокомментировать это сообщение.

Дневник Класс HEDOMElement и иже с ним | NF_hohol - HEngine | Лента друзей NF_hohol / Полная версия Добавить в друзья Страницы: раньше»