... unsure
Some checks reported warnings
/ phplint (push) Has been cancelled

This commit is contained in:
David Bailey 2024-08-24 13:09:28 +02:00
parent 76ca7b9c32
commit 0dcf36052e
18 changed files with 152 additions and 112 deletions

View file

@ -7,7 +7,7 @@ class Post implements ArrayAccess {
private $content_html;
private $content_markdown;
public $site_defaults;
private $site_defaults;
public $data;
@ -15,6 +15,7 @@ class Post implements ArrayAccess {
public $raw_data;
private $_child_posts;
private $_parent_post;
public static function _generate_404($post_data) {
$post_data ??= [
@ -61,13 +62,13 @@ class Post implements ArrayAccess {
return $icon_mapping[$type] ?? 'unknown';
}
function __construct($post_handler, $post_data) {
function __construct($post_handler, $post_data, $site_defaults) {
$this->handler = $post_handler;
$this->content_html = null;
$this->content_markdown = null;
$this->site_defaults = null;
$this->site_defaults = $site_defaults;
if(!isset($post_data) or !isset($post_data['id'])) {
$post_data = $this->_generate_404($post_data);
@ -75,9 +76,17 @@ class Post implements ArrayAccess {
$data = $post_data;
if($data['path'] == '') {
$data['path'] = '/';
$data['title'] ??= 'root';
$data['basename'] ??= 'root';
}
$post_data['host'] ??= 'localhost:8081';
$data['url'] ??= 'https://' . $post_data['host'] . $post_data['path'];
$data['url'] ??= 'http://' . $post_data['host'] . $post_data['path'];
$data['basename'] ??= basename($data['path']);
$data['title'] ??= basename($data['path']);
@ -111,6 +120,9 @@ class Post implements ArrayAccess {
if($name == 'child_posts') {
return $this->get_child_posts();
}
if($name == 'parent') {
return $this->get_parent_post();
}
if(isset($this->data[$name])) {
return $this->data[$name];
@ -137,10 +149,10 @@ class Post implements ArrayAccess {
return !is_null($this->offsetGet($offset));
}
public function offsetSet($offset, $value) : void {
throw RuntimeError("Setting of post data is not allowed!");
$this->data[$offset] = $value;
}
public function offsetUnset($offset) : void {
throw RuntimeError("Unsetting of post data is not allowed!");
unset($this->data[$offset]);
}
public function get_html() {
@ -156,14 +168,11 @@ class Post implements ArrayAccess {
}
public function get_child_posts(...$search_args) {
var_dump($search_args);
if(count($search_args) == 0) {
$this->child_posts ??=
$this->_child_posts ??=
$this->handler->get_children_for($this);
return $this->child_posts;
return $this->_child_posts;
}
else {
return $this->handler->get_children_for($this, ...$search_args);
@ -195,10 +204,9 @@ class Post implements ArrayAccess {
if($parent_path == '')
return null;
$this->parent_post ??= new PostData($this->handler,
$this->handler->get_post_by_path($parent_path));
$this->_parent_post ??= $this->handler->get_post($parent_path);
return $this->parent_post;
return $this->_parent_post;
}
}