mirror of
https://github.com/silverstripe/silverstripe-docsviewer
synced 2024-10-22 09:05:56 +00:00
This major update changes the behaviour of the docviewer module to use a cached manifest rather than on demand. This allows us to simplify the URL matching and store 'nice' URL configuration rather than altering handleAction().
130 lines
2.6 KiB
PHP
130 lines
2.6 KiB
PHP
<?php
|
|
|
|
/**
|
|
* A more specific instance of a {@link DocumentationEntity}. Each instance of
|
|
* a entity will have at least one of these objects attached to encapsulate
|
|
* linking to a particular URL.
|
|
*
|
|
* Versions are assumed to be in numeric format (e.g. '2.4'),
|
|
*
|
|
* They're also parsed through version_compare() in {@link getStableVersion()}
|
|
* which assumes a certain format:
|
|
*
|
|
* @see http://php.net/manual/en/function.version-compare.php
|
|
*
|
|
* Each {@link DocumentationEntityVersion} has a list of supported language
|
|
* instances. All documentation in the docs folder must sit under a supported
|
|
* language {@link DocumentationEntityLanguage}.
|
|
*
|
|
* @package docsviewer
|
|
*/
|
|
|
|
class DocumentationEntityVersion extends ViewableData {
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $supportedLanguages = array();
|
|
|
|
/**
|
|
* @var DocumentationEntity
|
|
*/
|
|
protected $entity;
|
|
|
|
/**
|
|
* @var mixed
|
|
*/
|
|
protected $path, $version, $stable;
|
|
|
|
/**
|
|
* @param DocumentationEntity $entity
|
|
* @param string $path
|
|
* @param float $version
|
|
* @param boolean $stable
|
|
*/
|
|
public function __construct($entity, $path, $version, $stable) {
|
|
$this->entity = $entity;
|
|
$this->path = $path;
|
|
$this->version = $version;
|
|
$this->stable = $stable;
|
|
|
|
// check what languages that this instance will support.
|
|
$langs = scandir($path);
|
|
$available = array();
|
|
|
|
if($langs) {
|
|
$possible = i18n::get_common_languages(true);
|
|
$possible['en'] = true;
|
|
|
|
foreach($langs as $key => $lang) {
|
|
if(isset($possible[$lang])) {
|
|
$this->supportedLanguages[$lang] = Injector::inst()->create(
|
|
'DocumentationEntityLanguage',
|
|
$this,
|
|
$lang
|
|
);
|
|
} else {
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function Link() {
|
|
if($this->stable) {
|
|
return $this->entity->Link();
|
|
}
|
|
|
|
return Controller::join_links($this->entity->Link(), $this->version);
|
|
}
|
|
|
|
/**
|
|
* Return the languages which are available for this version of the entity.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function getSupportedLanguages() {
|
|
return $this->supportedLanguages;
|
|
|
|
}
|
|
|
|
/**
|
|
* Return whether this entity has a given language.
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function hasLanguageSupport($lang) {
|
|
return (in_array($lang, $this->getSupportedLanguages()));
|
|
}
|
|
|
|
/**
|
|
* @return float
|
|
*/
|
|
public function getVersion() {
|
|
return $this->version;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getPath() {
|
|
return $this->path;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getBaseFolder() {
|
|
return $this->entity->getFolder();
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getTitle() {
|
|
return $this->entity->getTitle();
|
|
}
|
|
} |