Hoa central
Document.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Xyl\Interpreter\Html;
38 
39 use Hoa\Stream;
40 use Hoa\Xyl;
41 
50 class Document extends Concrete implements Xyl\Element\Executable
51 {
57  protected $_title = null;
58 
59 
60 
67  protected function paint(Stream\IStream\Out $out)
68  {
69  $root = $this->getAbstractElementSuperRoot();
70 
71  $locale = $root->getLocale();
72  $language = null;
73 
74  if (null !== $locale) {
75  $language .= ' lang="' . $locale->getLanguage() . '"';
76  }
77 
78  $out->writeAll(
79  '<!DOCTYPE html>' . "\n\n" .
80  '<!--[if lt IE 7]><html class="ie6"><![endif]-->' . "\n" .
81  '<!--[if IE 7]><html class="ie7"><![endif]-->' . "\n" .
82  '<!--[if IE 8]><html class="ie8"><![endif]-->' . "\n" .
83  '<!--[if (gte IE 9)|!(IE)]>' . "\n" .
84  '<html' . $language . '>' . "\n" .
85  '<![endif]-->' . "\n" .
86  '<head>' . "\n"
87  );
88 
89  if (null !== $this->_title) {
90  $out->writeAll(' ');
91  $this->_title->render($out);
92  }
93 
94  $out->writeAll(
95  "\n" .
96  ' <meta http-equiv="content-type" content="text/html; charset=utf-8" />' . "\n" .
97  ' <meta http-equiv="content-type" content="text/javascript; charset=utf-8" />' . "\n" .
98  ' <meta http-equiv="content-type" content="text/css; charset=utf-8" />' . "\n"
99  );
100 
101  foreach ($root->getMetas() as $meta) {
102  $out->writeAll(' <meta ' . $meta . ' />' . "\n");
103  }
104 
105  $stylesheets = $root->getStylesheets();
106 
107  if (!empty($stylesheets)) {
108  $out->writeAll("\n");
109 
110  foreach ($stylesheets as $href) {
111  $out->writeAll(
112  ' <link type="text/css" href="' . $href .
113  '" rel="stylesheet" />' . "\n"
114  );
115  }
116  }
117 
118  $out->writeAll(
119  '</head>' . "\n" .
120  '<body>' . "\n\n"
121  );
122 
123  foreach ($this as $child) {
124  if ('title' != $child->getName()) {
125  $child->render($out);
126  }
127  }
128 
129  $out->writeAll(
130  "\n\n" . '</body>' . "\n" . '</html>'
131  );
132 
133  return;
134  }
135 
141  public function preExecute()
142  {
143  return;
144  }
145 
151  public function postExecute()
152  {
153  $this->computeTitle();
154 
155  return;
156  }
157 
163  protected function computeTitle()
164  {
165  $xpath = $this->xpath('./__current_ns:title');
166 
167  if (empty($xpath)) {
168  return;
169  }
170 
171  $this->_title = $this->getConcreteElement($xpath[0]);
172 
173  return;
174  }
175 
181  public function getTitle()
182  {
183  return $this->_title;
184  }
185 }
paint(Stream\IStream\Out $out)
Definition: Document.php:67
static getConcreteElement(Element $element)
Definition: Concrete.php:212