OSDN Git Service

Creación y administración de documentos basados en DOM mediante PHP
[dombasic/DOMbasic.git] / DOM_textNode.php
1 <?php
2 //define("TAG", "LinkClass");
3         /**
4          * Clase para crear objetos de NODOS DE TEXTO para elementos del DOM, utiles para insertar texto 'innerHTML' dentro de los
5          * elementos del DOM.
6          **/
7         class DOM_textNode extends DOM_element {
8                 const N_C = __CLASS__;
9                 protected $TAG = "";
10                 protected $TYPE = "textNode";
11                 protected $DESC = "inline DOM text element";
12                 /*
13                  //APERTURA Y CIERRE DE ETIQUETAS DE ELEMENTO DOM. (algunos elementos autocontendidos (como '<img />') pueden modificarlas o
14                  //incluso anularlas)           */
15                 protected $OPEN_TAG_LEFT="";
16                 protected $OPEN_TAG_RIGHT="";
17                 protected $CLOSE_TAG_LEFT="";
18                 protected $CLOSE_TAG_RIGHT="";
19
20                 
21                 /**
22                  * Texto que contiene este elemento.
23                  **/
24                 protected $_text="";
25                 //-----------------  BEGIN: SINGLETON  --------------------
26                 /**
27                  * PATRON ESTATICO SINGLETON
28                  * @var DOM_textNode
29                  * @access protected
30                  */
31                 protected static $instance;
32                 
33                 /**
34                  * PATRON SINGLETON. Tomar una instancia de forma estatica.<br />
35                  * <code>$txt = DOM_textNode::getInstance();</code>
36                  **/
37                 public static function getInstance() {
38                         //if (!isset(self::$instance)) {
39                         if (is_null(self::$instance)) {
40                                 $c = __CLASS__; //self::TAG
41                                 //$instance = new $c;
42                                 self::$instance = new $c();
43                         }
44                         return self::$instance;
45                 }
46                 //private function setInstance() {
47                 //self::$instance=$this;
48                 //}
49                 //-----------------  END: SINGLETON  --------------------
50                 
51                 //CONSTRUCTORES
52                 public function __construct($key=null){
53                         if($key != null) $this->_key=$key;
54                         self::$instance=$this;
55                 }
56                 /*
57                  public static function __set_state($an_array) // A partir de PHP 5.1.0
58                 {
59                 return parent::__set_state($an_array);
60                 }
61                 */
62
63                 //OVERRIDE: se sobreescribe porque le afecta a __toString();
64                 public function getOpenTag(){
65                         return ($this->OPEN_TAG_LEFT . /*$this->TAG . parent::getAttribsStr() .*/ $this->OPEN_TAG_RIGHT);
66                 }
67                 
68                 //OVERRIDE: se sobreescribe porque es distinto, para no crear un bucle infinito;
69                 /**
70                  * Metodo para establecer el texto de este elemento DOM.
71                  * @param string $text para este elemento.
72                  * @return string con el texto anterior.
73                  **/
74                 public function setText($text){
75                         $textoAnterior="";
76                         try{
77                                 $this->tryingWrite("[".$this->_key."]".$this->TAG);
78                                 $textoAnterior=$this->_text;
79                                 $this->_text=addslashes( htmlspecialchars( $text ) );
80                                 //$this->_text=addslashes( htmlspecialchars( $text, ENT_NOQUOTES ) );
81                                 //$this->_text= $text ;
82                                 //parent::setText($text);       //NO ACTIVAR PROVOCA BUCLE INFINITO!!
83                         }catch(Exception $e){
84                                 $this->writeLog($e->getMessage(), $e->getTrace());
85                         }
86                         //return $textoAnterior;
87                         return $this;
88                 }
89
90         }
91 ?>