1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77:
<?php
namespace Nethgui\Module\Help;
class Read extends Common implements \Nethgui\Component\DependencyConsumer
{
public function prepareView(\Nethgui\View\ViewInterface $view)
{
$module = $this->getTargetModule();
if (is_null($module)) {
return;
}
$filePath = $this->getHelpDocumentPath($this->getTargetModule());
if ( ! $this->getPhpWrapper()->file_exists($filePath)) {
throw new \Nethgui\Exception\HttpException(sprintf("%s: resource not found", __CLASS__), 404, 1351702294);
}
$readModule = $this;
$phpWrapper = $readModule->getPhpWrapper();
$this->rootView->setTemplate(function(\Nethgui\View\ViewInterface $renderer, $T, \Nethgui\Utility\HttpResponse $response) use ($readModule, $phpWrapper, $filePath) {
$contents = $readModule->expandIncludes(
$phpWrapper->file_get_contents($filePath)
);
if (NETHGUI_ENABLE_HTTP_CACHE_HEADERS) {
$response->addHeader(sprintf('Last-Modified: %s', date(DATE_RFC1123, $phpWrapper->filemtime($filePath))));
$response->addHeader(sprintf('Expires: %s', date(DATE_RFC1123, time() + 3600)));
}
$response->addHeader(sprintf('Content-Length: %d', strlen($contents)));
return $contents;
});
}
public function setRootView(\Nethgui\View\ViewInterface $view)
{
$this->rootView = $view;
return $this;
}
public function getDependencySetters()
{
return array_merge(parent::getDependencySetters(), array('View' => array($this, 'setRootView')));
}
}