2015-06-29 16:11:01 +02:00
|
|
|
<?php namespace Todaymade\Daux;
|
|
|
|
|
|
|
|
use ArrayObject;
|
2016-07-04 20:33:44 +02:00
|
|
|
use Todaymade\Daux\Tree\Content;
|
2015-06-29 16:11:01 +02:00
|
|
|
|
2015-07-17 23:38:06 +02:00
|
|
|
class Config extends ArrayObject
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Merge an array into the object
|
|
|
|
*
|
|
|
|
* @param array $newValues
|
|
|
|
* @param bool $override
|
|
|
|
*/
|
|
|
|
public function merge($newValues, $override = true)
|
|
|
|
{
|
2015-06-29 16:11:01 +02:00
|
|
|
foreach ($newValues as $key => $value) {
|
2015-07-19 16:36:34 +02:00
|
|
|
// If the key doesn't exist yet,
|
|
|
|
// we can simply set it.
|
|
|
|
if (!array_key_exists($key, $this)) {
|
|
|
|
$this[$key] = $value;
|
2015-06-29 16:11:01 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-07-19 16:36:34 +02:00
|
|
|
// We already know this value exists
|
|
|
|
// so if we're in conservative mode
|
|
|
|
// we can skip this key
|
|
|
|
if ($override === false) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Merge the values only if
|
|
|
|
// both values are arrays
|
|
|
|
if (is_array($this[$key]) && is_array($value)) {
|
|
|
|
$this[$key] = array_replace_recursive($this[$key], $value);
|
|
|
|
} else {
|
|
|
|
$this[$key] = $value;
|
|
|
|
}
|
2015-06-29 16:11:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-17 23:38:06 +02:00
|
|
|
/**
|
|
|
|
* Merge an array into the object, ignore already added keys.
|
|
|
|
*
|
|
|
|
* @param $newValues
|
|
|
|
*/
|
|
|
|
public function conservativeMerge($newValues)
|
|
|
|
{
|
2015-06-29 16:11:01 +02:00
|
|
|
$this->merge($newValues, false);
|
|
|
|
}
|
2016-07-04 20:33:44 +02:00
|
|
|
|
|
|
|
public function getCurrentPage()
|
|
|
|
{
|
|
|
|
return $this['current_page'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setCurrentPage(Content $entry)
|
|
|
|
{
|
|
|
|
$this['current_page'] = $entry;
|
|
|
|
}
|
2016-07-27 23:27:51 +02:00
|
|
|
|
2016-07-28 22:48:50 +02:00
|
|
|
public function getDocumentationDirectory()
|
|
|
|
{
|
2016-07-27 23:27:51 +02:00
|
|
|
return $this['docs_directory'];
|
|
|
|
}
|
|
|
|
|
2016-07-28 22:48:50 +02:00
|
|
|
public function setDocumentationDirectory($documentationPath)
|
|
|
|
{
|
2016-07-27 23:27:51 +02:00
|
|
|
$this['docs_directory'] = $documentationPath;
|
|
|
|
}
|
|
|
|
|
2016-07-28 22:48:50 +02:00
|
|
|
public function getThemesDirectory()
|
|
|
|
{
|
2016-07-27 23:27:51 +02:00
|
|
|
return $this['themes_directory'];
|
|
|
|
}
|
|
|
|
|
2016-07-28 22:48:50 +02:00
|
|
|
public function setFormat($format)
|
|
|
|
{
|
2016-07-28 22:47:47 +02:00
|
|
|
$this['format'] = $format;
|
|
|
|
}
|
|
|
|
|
2016-07-28 22:48:50 +02:00
|
|
|
public function getFormat()
|
|
|
|
{
|
2016-07-28 22:47:47 +02:00
|
|
|
return $this['format'];
|
|
|
|
}
|
|
|
|
|
2016-07-28 22:48:50 +02:00
|
|
|
public function isMultilanguage()
|
|
|
|
{
|
2016-07-27 23:27:51 +02:00
|
|
|
return array_key_exists('languages', $this) && !empty($this['languages']);
|
|
|
|
}
|
2016-08-02 23:39:57 +02:00
|
|
|
|
|
|
|
public function shouldInheritIndex()
|
|
|
|
{
|
|
|
|
if (array_key_exists('html', $this) && array_key_exists('inherit_index', $this['html'])) {
|
|
|
|
return $this['html']['inherit_index'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (array_key_exists('live', $this) && array_key_exists('inherit_index', $this['live'])) {
|
|
|
|
return $this['live']['inherit_index'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2015-06-29 16:11:01 +02:00
|
|
|
}
|