8
0
daux.io/libs/Config.php

306 Zeilen
6.5 KiB
PHP

<?php namespace Todaymade\Daux;
2020-04-22 22:24:52 +02:00
use Todaymade\Daux\Format\Confluence\Config as ConfluenceConfig;
use Todaymade\Daux\Format\HTML\Config as HTMLConfig;
use Todaymade\Daux\Format\HTML\Theme as Theme;
2020-04-22 22:24:52 +02:00
use Todaymade\Daux\Tree\Content;
use Todaymade\Daux\Tree\Entry;
class Config extends BaseConfig
2015-07-17 23:38:06 +02:00
{
2020-04-22 21:55:53 +02:00
public function getTitle()
{
return $this->getValue('title');
}
2020-04-22 21:55:53 +02:00
public function hasAuthor(): bool
{
return $this->hasValue('author');
}
2020-04-22 21:55:53 +02:00
public function getAuthor()
{
return $this->getValue('author');
}
2020-04-22 21:55:53 +02:00
public function hasTagline(): bool
{
return $this->hasValue('tagline');
}
2020-04-22 21:55:53 +02:00
public function getTagline()
{
return $this->getValue('tagline');
}
2020-04-22 21:55:53 +02:00
public function getCurrentPage()
{
return $this->getValue('current_page');
}
2020-04-22 21:55:53 +02:00
public function setCurrentPage(Content $entry)
{
$this->setValue('current_page', $entry);
2016-09-21 23:30:01 +02:00
}
2020-04-22 21:55:53 +02:00
public function getDocumentationDirectory()
{
return $this->getValue('docs_directory');
}
2020-04-22 21:55:53 +02:00
public function getThemesDirectory()
{
return $this->getValue('themes_directory');
}
2020-04-22 21:55:53 +02:00
public function getThemesPath()
{
return $this->getValue('themes_path');
}
2020-04-22 21:55:53 +02:00
public function getFormat()
{
return $this->getValue('format');
}
2020-04-22 21:55:53 +02:00
public function hasTimezone(): bool
{
return isset($this['timezone']);
}
2020-04-22 21:55:53 +02:00
public function getTimezone()
{
return $this->getValue('timezone');
}
2020-04-22 21:55:53 +02:00
public function getTree()
{
return $this->getValue('tree');
}
2020-04-22 21:55:53 +02:00
public function setTree($tree)
{
$this->setValue('tree', $tree);
}
2020-04-22 21:55:53 +02:00
public function isMultilanguage(): bool
{
return $this->hasValue('languages') && !empty($this->getValue('languages'));
}
2020-04-22 21:55:53 +02:00
public function getLanguages(): array
{
return $this->getValue('languages');
}
2020-04-22 21:55:53 +02:00
public function getLanguage(): string
{
return $this->getValue('language');
}
2020-04-22 21:55:53 +02:00
public function getMode()
{
return $this->getValue('mode');
}
2020-04-22 21:55:53 +02:00
public function isLive()
{
return $this->getValue('mode') == Daux::LIVE_MODE;
}
2020-04-22 21:55:53 +02:00
public function isStatic()
{
return $this->getValue('mode') == Daux::STATIC_MODE;
}
2020-04-22 21:55:53 +02:00
public function shouldInheritIndex()
{
// As the global configuration is always present, we
// need to test for the existence of the legacy value
// first. Then use the current value.
2019-12-07 11:22:40 +01:00
if ($this->hasValue('live') && array_key_exists('inherit_index', $this['live'])) {
return $this['live']['inherit_index'];
}
return $this['html']['inherit_index'];
}
2020-04-22 21:55:53 +02:00
public function getIndexKey()
{
return $this->getValue('mode') == Daux::STATIC_MODE ? 'index.html' : 'index';
}
2020-04-22 21:55:53 +02:00
public function getProcessor()
{
return $this->getValue('processor');
}
2020-04-22 21:55:53 +02:00
public function getConfluenceConfiguration(): ConfluenceConfig
{
return new ConfluenceConfig($this->hasValue('confluence') ? $this->getValue('confluence') : []);
}
2020-04-22 21:55:53 +02:00
public function getHTML(): HTMLConfig
{
return new HTMLConfig($this->hasValue('html') ? $this->getValue('html') : []);
}
2020-04-22 21:55:53 +02:00
public function getTheme(): ?Theme
{
return $this->hasValue('theme') ? new Theme($this->getValue('theme')) : null;
}
2020-04-22 21:55:53 +02:00
public function getValidContentExtensions()
{
return $this->getValue('valid_content_extensions');
}
2020-04-22 21:55:53 +02:00
public function setValidContentExtensions(array $value)
{
$this->setValue('valid_content_extensions', $value);
}
2018-06-06 23:20:29 +02:00
2020-04-22 21:55:53 +02:00
public function canCache()
{
if ($this->hasValue('cache')) {
return $this->getValue('cache');
2018-06-06 23:20:29 +02:00
}
2018-06-06 23:37:26 +02:00
return false;
2018-06-06 23:20:29 +02:00
}
2020-04-22 21:55:53 +02:00
public function getCacheKey()
{
2018-06-06 23:20:29 +02:00
$cloned = [];
foreach ($this as $key => $value) {
$cloned[$key] = ($value instanceof Entry) ? $value->dump() : $value;
}
return sha1(json_encode($cloned));
}
2020-04-22 21:55:53 +02:00
public function hasTranslationKey($language, $key): bool
{
return array_key_exists($language, $this['strings']) && array_key_exists($key, $this['strings'][$language]);
}
2020-04-22 21:55:53 +02:00
public function getTranslationKey($language, $key)
{
return $this['strings'][$language][$key];
}
2020-04-22 21:55:53 +02:00
public function hasImage(): bool
{
return $this->hasValue('image');
}
2020-04-22 21:55:53 +02:00
public function getImage()
{
return $this->getValue('image');
}
2020-04-22 21:55:53 +02:00
public function setImage($value)
{
2019-12-07 11:22:40 +01:00
$this->setValue('image', $value);
}
2020-04-22 21:55:53 +02:00
public function getLocalBase()
{
return $this->getValue('local_base');
}
2020-04-22 21:55:53 +02:00
public function getTemplates()
{
return $this->getValue('templates');
}
2020-04-22 21:55:53 +02:00
public function getBaseUrl()
{
return $this->getValue('base_url');
}
2020-04-22 21:55:53 +02:00
public function getBasePage()
{
if ($this->isLive()) {
$value = '//' . $this->getBaseUrl();
if (!$this['live']['clean_urls']) {
$value .= 'index.php/';
}
return $value;
}
2020-04-22 22:24:52 +02:00
return $this->getBaseUrl();
}
2020-04-22 21:55:53 +02:00
public function hasEntryPage(): bool
{
return $this->hasValue('entry_page') && !empty($this->getValue('entry_page'));
}
2020-04-22 21:55:53 +02:00
public function getEntryPage()
{
return $this->getValue('entry_page');
}
2020-04-22 21:55:53 +02:00
public function setEntryPage($value)
{
2019-12-07 11:22:40 +01:00
$this->setValue('entry_page', $value);
}
2020-04-22 21:55:53 +02:00
public function hasRequest(): bool
{
return $this->hasValue('request') && !empty($this->getValue('request'));
}
2020-04-22 21:55:53 +02:00
public function getRequest()
{
return $this->getValue('request');
}
2020-04-22 21:55:53 +02:00
public function setRequest($value)
{
2019-12-07 11:22:40 +01:00
$this->setValue('request', $value);
}
2020-04-22 21:55:53 +02:00
public function getIndex()
{
return $this->getValue('index');
}
2020-04-22 21:55:53 +02:00
public function setIndex($value)
{
2019-12-07 11:22:40 +01:00
$this->setValue('index', $value);
}
2020-04-22 21:55:53 +02:00
public function hasProcessorInstance()
{
return $this->hasValue('processor_instance');
}
2020-04-22 21:55:53 +02:00
public function getProcessorInstance()
{
return $this->getValue('processor_instance');
}
2020-04-22 21:55:53 +02:00
public function setProcessorInstance($value)
{
2019-12-07 11:22:40 +01:00
$this->setValue('processor_instance', $value);
}
2020-04-22 21:55:53 +02:00
public function getIgnore()
{
return $this->getValue('ignore');
}
2020-04-22 21:55:53 +02:00
public function hasHost()
{
return $this->hasValue('host');
}
2020-04-22 21:55:53 +02:00
public function getHost()
{
return $this->getValue('host');
}
}