-Подписка по e-mail

 

 -Поиск по дневнику

Поиск сообщений в NF_hohol

 -Интересы

 -Постоянные читатели

 -Статистика

Статистика LiveInternet.ru: показано количество хитов и посетителей
Создан: 09.11.2007
Записей:
Комментариев:
Написано: 38

HEngine





HEngine - W3 програмное обеспечение.


Класс HEDOMElement и иже с ним

Понедельник, 18 Октября 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;




Метки:  

Понравилось: 16 пользователям

Поиск сообщений в NF_hohol
Страницы: [1] Календарь