silverstripe-docsviewer/code/DocumentationPage.php
Ingo Schommer 277bca7b11 FEATURE Added parsing support for relative links (relative to module base). Introduced DocumentationPage to encapsulate this information.
ENHANCEMENT Saving $ModuleName in viewer instead of getting it from Remaining[0]
MINOR Don't include version in breadcrumbs, doesn't make sense in this context (e.g. "2.4/en/cms", the "2.4" part is connecte to the cms module, hence an index of all versions regardless of module is not very useful)
2010-08-01 04:46:32 +00:00

90 lines
1.8 KiB
PHP

<?php
/**
* A specific page within a {@link DocumentationEntity}.
* Has to represent an actual file, please use {@link DocumentationViewer}
* to generate "virtual" index views.
*
* @package sapphiredocs
*/
class DocumentationPage extends ViewableData {
/**
* @var DocumentationEntity
*/
protected $entity;
/**
* @var String
*/
protected $relativePath;
protected $lang = 'en';
protected $version;
function __construct($relativePath, $entity, $lang = null, $version = null) {
$this->entity = $entity;
$this->relativePath = $relativePath;
if($lang) $this->lang = $lang;
if($version) $this->version = $version;
if(!file_exists($this->getPath())) {
throw new InvalidArgumentException(sprintf(
'Path could not be found: "%s" (module path: %s, file path: %s)',
$this->getPath(),
$this->entity->getPath(),
$this->relativePath
));
}
parent::__construct();
}
/**
* @return DocumentationEntity
*/
function getEntity() {
return $this->entity;
}
/**
* @return String Relative path to file or folder within the entity (including file extension),
* but excluding version or language folders.
*/
function getRelativePath() {
return $this->relativePath;
}
/**
* Absolute path including version and lang folder.
*
* @return String
*/
function getPath() {
return realpath($this->entity->getPath($this->version, $this->lang) . '/' . $this->getRelativePath());
}
function getLang() {
return $this->lang;
}
function getVersion() {
return $this->version;
}
/**
* @return String
*/
function getMarkdown() {
return file_get_contents($this->getPath());
}
/**
* @param String $baselink
* @return String
*/
function getHTML($baselink = null) {
return DocumentationParser::parse($this, $baselink);
}
}