From e8b1632d64205d1294f9bb2783bba6be353a548d Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Mon, 10 Feb 2020 20:18:37 +0100 Subject: Refactoring element rendering close #60 --- app/class/Element.php | 62 +++++++-------------------------------------------- 1 file changed, 8 insertions(+), 54 deletions(-) (limited to 'app/class/Element.php') diff --git a/app/class/Element.php b/app/class/Element.php index a08e219..d94c76f 100644 --- a/app/class/Element.php +++ b/app/class/Element.php @@ -10,14 +10,10 @@ class Element extends Item protected $type; protected $options; protected $sources = []; - protected $params = []; protected $autolink = 0; protected $markdown = 1; protected $content = ''; - const OPTIONS = ['autolink', 'markdown']; - - // __________________________________________________ F U N ____________________________________________________________ @@ -27,58 +23,21 @@ class Element extends Item { $this->hydrate($datas); $this->analyse($pageid); - } + } private function analyse(string $pageid) { if(!empty($this->options)) { - - // Replace "!" by the real page name - $this->options = str_replace('!', $pageid, $this->options); - - preg_match('~(:([a-z0-9-_+!]+))?(\/([a-z0-9-,_+=]+))?~', $this->options, $matches); - if(isset($matches[2]) && !empty($matches[2])) { - $this->sources = explode('+', $matches[2]); + $this->options = str_replace('*', $pageid, $this->options); + parse_str($this->options, $datas); + if (isset($datas['id'])) { + $this->sources = explode(' ', $datas['id']); } else { - $this->sources[] = $pageid; + $this->sources = [$pageid]; } - if(isset($matches[4])) { - $this->params = explode(',', $matches[4]); - } - - $this->readoptions(); - + $this->hydrate($datas); } else { - $this->sources[] = $pageid; - } - } - - private function readoptions() - { - if(!empty($this->params)) { - foreach ($this->params as $param ) { - preg_match('~([a-z0-9-_]+)(=(-?[0-9]+))?~', $param, $optionmatch); - if(isset($optionmatch[1])) { - $key = $optionmatch[1]; - } - if(isset($optionmatch[3])) { - $value = $optionmatch[3]; - } else { - $read = '

Rendering error :

Paramaters must have a value like : /' . $key . '=__value__ for parameter : ' . $key . '

'; - //throw new Exception($read); - } - $method = 'set' . $key; - if (in_array($key, self::OPTIONS)) { - if (!$this->$method($value)) { - $read = '

Rendering error :

Invalid value input : ' . $value . ' for parameter : ' . $key . '

'; - //throw new Exception($read); - - } - } else { - $read = '

Rendering error :

Parameter name : ' . $optionmatch[1] . ' does not exist

'; - //throw new Exception($read); - } - } + $this->sources = [$pageid]; } } @@ -109,11 +68,6 @@ class Element extends Item return $this->options; } - public function params() - { - return $this->params; - } - public function sources() { return $this->sources; -- cgit v1.2.3