Witam serdecznie:)
Otóż napisałem sobie system templaków pod xsl xml i php, klasa generuje dokument xml i konwertuje go do html-a za pomoca arkusza styli xsl, ogólnie jeżeli smarty ma wyłączone cachowanie to jest nawet do 20x szybsza, ale kiedy smarty ma włączone cachowanie to po dwóch przeładowaniach wygrywa o około 2 razy. I ja mam pytanko, jak zrobić jakiś fajny system cachowania dla takiej klasy- nie proszę o rozwiązanie ale o wskazóki co i jak, bo nigdy czegoś takiego nie robiłem:
KLASA:
  1. <?php
  2. class etpl{
  3. private $xml;
  4. public $xml_version;
  5. public $xml_encoding;
  6. private $xsl;
  7. public $xsl_path;
  8.  
  9. private function is_array_asc($array){
  10. if(is_array($array) && !is_numeric(array_shift(array_keys($array)))){
  11. return true;
  12. }
  13. return false;
  14. }
  15.  
  16. public function __construct($xsl=false,$xml_version=false,$xml_encoding=false){
  17. file_exists($xsl)?$this->xsl_path=$xsl:$xsl;
  18.  
  19. $xml_version?$this->xml_version=$xml_version:$this->xml_version="1.0";
  20. $xml_encoding?$this->xml_encoding=$xml_encoding:$this->xml_encoding="UTF-8";
  21. //create DOMDocument
  22. $this->xml = new DOMDocument($this->xml_version,$this->xml_encoding);
  23. $this->xml->appendChild($this->xml->createElement('root'));
  24. }
  25. public function setTemplate($xsl){
  26. file_exists($xsl)?$this->xsl_path=$xsl:$xsl;
  27. }
  28. private function array_to_xml($key,$value){
  29. if($this->is_array_asc($value)){
  30. $data .= "<".$key.">";
  31. foreach($value as $k => $v){
  32. if(is_array($v)){
  33. $data.=$this->array_to_xml($k,$v);
  34. }
  35. else{
  36. $data.="<$k>".$v."</$k>";
  37. }
  38. }
  39. $data .= "</".$key.">";
  40. }else{
  41. foreach($value as $v){
  42. $data .= "<".$key.">";
  43. if(is_array($v)){
  44. $data.=$this->array_to_xml($k,$v);
  45. }
  46. else{
  47. $data.="<value>".$v."</value>";
  48. }
  49. $data .= "</".$key.">";
  50. }
  51. }
  52.  
  53. return $data;
  54. }
  55.  
  56. /*
  57. settig values
  58.  */
  59. public function set($key,$value){
  60. if(is_array($value)){
  61. $documentfragment = $this->xml->createDocumentFragment();
  62. $documentfragment->appendXML($this->array_to_xml($key,$value));
  63. $this->xml->documentElement->appendChild($documentfragment);
  64. }else{
  65. $this->xml->documentElement->appendChild($this->xml->createElement($key,$value));
  66. }
  67. }
  68. public function applyTemplate(){
  69.  
  70. $xml = $this->xml;
  71.  
  72.  
  73. $xsl = new DomDocument;
  74. $xsl->loadXML(file_get_contents($this->xsl_path));
  75.  
  76.  
  77. $proc = new xsltprocessor;
  78. $proc->importStyleSheet($xsl);
  79. echo $proc->transformToXML($xml);
  80. }
  81.  
  82. }
  83. ?>

Wykorzystanie plik php:
  1. <?php
  2. $tpl = new etpl("tpl.xsl");
  3. $tpl->set("loop",$data);
  4. $tpl->set("title","tytuł");
  5.  
  6. $tpl->applyTemplate();
  7. ?>

Wykorzystanie plik xsl:
  1. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  2.  
  3. <xsl:output method="html"/>
  4. <xsl:template match="/">
  5. <html xmlns="http://www.w3.org/1999/xhtml">
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  8. <title>
  9.      <xsl:value-of select="//title" />
  10. </title>
  11. </head>
  12.  
  13. <body>
  14.      <xsl:for-each select="//loop">
  15.            <xsl:value-of select="value" />data<br/>
  16.      </xsl:for-each>
  17. </body>
  18. </html>
  19. </xsl:template>
  20.  
  21.  
  22.  
  23. </xsl:stylesheet>