diff --git a/Model/Message/Dom.php b/Model/Message/Dom.php new file mode 100644 index 000000000..e40942f3b --- /dev/null +++ b/Model/Message/Dom.php @@ -0,0 +1,188 @@ +content = $content; + } + + /** + * Set selector. + * + * @param string $selector Selector + * + * @return void + * + * @since 1.0.0 + */ + public function setSelector(string $selector) : void + { + $this->selector = $selector; + } + + /** + * Set action. + * + * @param int $action action + * + * @return void + * + * @since 1.0.0 + */ + public function setAction(int $action) : void + { + $this->action = $action; + } + + /** + * Set delay. + * + * @param int $delay Delay in ms + * + * @return void + * + * @since 1.0.0 + */ + public function setDelay(int $delay) : void + { + $this->delay = $delay; + } + + /** + * Render message. + * + * @return string + * + * @since 1.0.0 + */ + public function serialize() : string + { + return $this->__toString(); + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() + { + return $this->toArray(); + } + + /** + * {@inheritdoc} + */ + public function unserialize($raw) + { + $unserialized = \json_decode($raw, true); + + $this->delay = $unserialized['time'] ?? 0; + $this->selector = $unserialized['selector'] ?? ''; + $this->action = $unserialized['action'] ?? ''; + $this->content = $unserialized['content'] ?? ''; + } + + /** + * Stringify. + * + * @return string + * + * @since 1.0.0 + */ + public function __toString() + { + return (string) \json_encode($this->toArray()); + } + + /** + * Generate message array. + * + * @return array + * + * @since 1.0.0 + */ + public function toArray() : array + { + return [ + 'type' => self::TYPE, + 'time' => $this->delay, + 'selector' => $this->selector, + 'action' => $this->action, + 'content' => $this->content, + ]; + } +} diff --git a/Model/Message/DomAction.php b/Model/Message/DomAction.php new file mode 100644 index 000000000..95cfd51f8 --- /dev/null +++ b/Model/Message/DomAction.php @@ -0,0 +1,38 @@ +validation = $validation; + } + + /** + * Render message. + * + * @return string + * + * @since 1.0.0 + */ + public function serialize() : string + { + return $this->__toString(); + } + + /** + * Render message. + * + * @return array + * + * @since 1.0.0 + */ + public function jsonSerialize() + { + return $this->toArray(); + } + + /** + * {@inheritdoc} + */ + public function unserialize($raw) + { + $unserialized = \json_decode($raw, true); + + $this->validation = $unserialized['validation'] ?? []; + } + + /** + * Stringify. + * + * @return string + * + * @since 1.0.0 + */ + public function __toString() + { + return (string) \json_encode($this->toArray()); + } + + /** + * Generate message array. + * + * @return array + * + * @since 1.0.0 + */ + public function toArray() : array + { + return [ + 'type' => self::TYPE, + 'validation' => $this->validation + ]; + } +} diff --git a/Model/Message/Notify.php b/Model/Message/Notify.php new file mode 100644 index 000000000..cbb3058a9 --- /dev/null +++ b/Model/Message/Notify.php @@ -0,0 +1,230 @@ +message = $msg; + $this->level = $level; + } + + /** + * Set delay. + * + * @param int $delay Delay in ms + * + * @return void + * + * @since 1.0.0 + */ + public function setDelay(int $delay) : void + { + $this->delay = $delay; + } + + /** + * Set delay. + * + * @param int $stay Stay in ms + * + * @return void + * + * @since 1.0.0 + */ + public function setStay(int $stay) : void + { + $this->stay = $stay; + } + + /** + * Set title. + * + * @param string $title Title + * + * @return void + * + * @since 1.0.0 + */ + public function setTitle(string $title) : void + { + $this->title = $title; + } + + /** + * Set message. + * + * @param string $message Message + * + * @return void + * + * @since 1.0.0 + */ + public function setMessage(string $message) : void + { + $this->message = $message; + } + + /** + * Set level/type. + * + * @param int $level Notification type/level + * + * @return void + * + * @since 1.0.0 + */ + public function setLevel(int $level) : void + { + $this->level = $level; + } + + /** + * Render message. + * + * @return string + * + * @since 1.0.0 + */ + public function serialize() : string + { + return $this->__toString(); + } + + /** + * Render message. + * + * @return array + * + * @since 1.0.0 + */ + public function jsonSerialize() + { + return $this->toArray(); + } + + /** + * {@inheritdoc} + */ + public function unserialize($raw) + { + $unserialized = \json_decode($raw, true); + + $this->delay = $unserialized['time'] ?? 0; + $this->stay = $unserialized['stay'] ?? ''; + $this->message = $unserialized['msg'] ?? ''; + $this->title = $unserialized['title'] ?? ''; + $this->level = $unserialized['level'] ?? 0; + } + + /** + * Stringify. + * + * @return string + * + * @since 1.0.0 + */ + public function __toString() + { + return (string) \json_encode($this->toArray()); + } + + /** + * Generate message array. + * + * @return array + * + * @since 1.0.0 + */ + public function toArray() : array + { + return [ + 'type' => self::TYPE, + 'time' => $this->delay, + 'stay' => $this->stay, + 'msg' => $this->message, + 'title' => $this->title, + 'level' => $this->level, + ]; + } +} diff --git a/Model/Message/NotifyType.php b/Model/Message/NotifyType.php new file mode 100644 index 000000000..b9f596010 --- /dev/null +++ b/Model/Message/NotifyType.php @@ -0,0 +1,34 @@ +uri = $url; + $this->new = $blank; + } + + /** + * Set delay. + * + * @param int $delay Delay in ms + * + * @return void + * + * @since 1.0.0 + */ + public function setDelay(int $delay) : void + { + $this->delay = $delay; + } + + /** + * Set uri. + * + * @param string $uri Uri + * + * @return void + * + * @since 1.0.0 + */ + public function setUri(string $uri) : void + { + $this->uri = $uri; + } + + /** + * Render message. + * + * @return string + * + * @since 1.0.0 + */ + public function serialize() : string + { + return $this->__toString(); + } + + /** + * Render message. + * + * @return array + * + * @since 1.0.0 + */ + public function jsonSerialize() + { + return $this->toArray(); + } + + /** + * {@inheritdoc} + */ + public function unserialize($raw) + { + $unserialized = \json_decode($raw, true); + + $this->delay = $unserialized['time'] ?? 0; + $this->uri = $unserialized['uri'] ?? ''; + $this->new = $unserialized['new'] ?? ''; + } + + /** + * Stringify. + * + * @return string + * + * @since 1.0.0 + */ + public function __toString() + { + return (string) \json_encode($this->toArray()); + } + + /** + * Generate message array. + * + * @return array + * + * @since 1.0.0 + */ + public function toArray() : array + { + return [ + 'type' => self::TYPE, + 'time' => $this->delay, + 'uri' => $this->uri, + 'new' => $this->new + ]; + } +} diff --git a/Model/Message/Reload.php b/Model/Message/Reload.php new file mode 100644 index 000000000..821898918 --- /dev/null +++ b/Model/Message/Reload.php @@ -0,0 +1,132 @@ +delay = $delay; + } + + /** + * Set delay. + * + * @param int $delay Delay in ms + * + * @return void + * + * @since 1.0.0 + */ + public function setDelay(int $delay) : void + { + $this->delay = $delay; + } + + /** + * Render message. + * + * @return string + * + * @since 1.0.0 + */ + public function serialize() : string + { + return $this->__toString(); + } + + /** + * {@inheritdoc} + */ + public function unserialize($raw) + { + $unserialized = \json_decode($raw, true); + + $this->delay = $unserialized['time'] ?? 0; + } + + /** + * Stringify. + * + * @return string + * + * @since 1.0.0 + */ + public function __toString() + { + return (string) \json_encode($this->toArray()); + } + + /** + * Generate message array. + * + * @return array + * + * @since 1.0.0 + */ + public function toArray() : array + { + return [ + 'type' => self::TYPE, + 'time' => $this->delay + ]; + } + + /** + * Generate message json. + * + * @return array + * + * @since 1.0.0 + */ + public function jsonSerialize() + { + return $this->toArray(); + } +} diff --git a/Views/PaginationView.php b/Views/PaginationView.php new file mode 100644 index 000000000..fab22f0a3 --- /dev/null +++ b/Views/PaginationView.php @@ -0,0 +1,147 @@ +maxPages; + } + + /** + * @param int $maxPages + * + * @return void + * + * @since 1.0.0 + */ + public function setMaxPages(int $maxPages) + { + $this->maxPages = $maxPages; + } + + /** + * @return int + * + * @since 1.0.0 + */ + public function getPages() : int + { + return $this->pages; + } + + /** + * @param int $pages + * + * @return void + * + * @since 1.0.0 + */ + public function setPages(int $pages) + { + $this->pages = $pages; + } + + /** + * @return int + * + * @since 1.0.0 + */ + public function getPage() : int + { + return $this->page; + } + + /** + * @param int $page + * + * @return void + * + * @since 1.0.0 + */ + public function setPage(int $page = 1) + { + $this->page = $page; + } + + /** + * @return int + * + * @since 1.0.0 + */ + public function getResults() : int + { + return $this->results; + } + + /** + * @param int $results + * + * @return void + * + * @since 1.0.0 + */ + public function setResults(int $results = 0) + { + $this->results = $results; + } +} diff --git a/tests/Model/Message/DomActionTest.php b/tests/Model/Message/DomActionTest.php new file mode 100644 index 000000000..b510f2f79 --- /dev/null +++ b/tests/Model/Message/DomActionTest.php @@ -0,0 +1,35 @@ +toArray()['time']); + self::assertEquals('', $obj->toArray()['selector']); + self::assertEquals('', $obj->toArray()['content']); + self::assertEquals(DomAction::MODIFY, $obj->toArray()['action']); + } + + public function testSetGet() + { + $obj = new Dom(); + $obj->setDelay(3); + $obj->setAction(DomAction::SHOW); + $obj->setContent('msg'); + $obj->setSelector('#sel'); + + self::assertEquals([ + 'type' => 'dom', + 'time' => 3, + 'selector' => '#sel', + 'action' => DomAction::SHOW, + 'content' => 'msg', + ], $obj->toArray()); + + self::assertEquals(\json_encode([ + 'type' => 'dom', + 'time' => 3, + 'selector' => '#sel', + 'action' => DomAction::SHOW, + 'content' => 'msg', + ]), $obj->serialize()); + + self::assertEquals([ + 'type' => 'dom', + 'time' => 3, + 'selector' => '#sel', + 'action' => DomAction::SHOW, + 'content' => 'msg', + ], $obj->jsonSerialize()); + + $obj2 = new Dom(); + $obj2->unserialize($obj->serialize()); + self::assertEquals($obj, $obj2); + } +} diff --git a/tests/Model/Message/FormValidationTest.php b/tests/Model/Message/FormValidationTest.php new file mode 100644 index 000000000..fe7fbcc42 --- /dev/null +++ b/tests/Model/Message/FormValidationTest.php @@ -0,0 +1,51 @@ +toArray()['validation']); + } + + public function testSetGet() + { + $arr = ['a' => true, 'b' => false]; + $obj = new FormValidation($arr); + + self::assertEquals(['type' => 'validation', 'validation' => $arr], $obj->toArray()); + self::assertEquals(\json_encode(['type' => 'validation', 'validation' => $arr]), $obj->serialize()); + self::assertEquals(['type' => 'validation', 'validation' => $arr], $obj->jsonSerialize()); + + $obj2 = new FormValidation(); + $obj2->unserialize($obj->serialize()); + self::assertEquals($obj, $obj2); + } +} diff --git a/tests/Model/Message/NotifyTest.php b/tests/Model/Message/NotifyTest.php new file mode 100644 index 000000000..a35c7b510 --- /dev/null +++ b/tests/Model/Message/NotifyTest.php @@ -0,0 +1,87 @@ +toArray()['time']); + self::assertEquals('', $obj->toArray()['title']); + self::assertEquals('', $obj->toArray()['msg']); + self::assertEquals(0, $obj->toArray()['stay']); + self::assertEquals(NotifyType::INFO, $obj->toArray()['level']); + } + + public function testSetGet() + { + $obj = new Notify('message', NotifyType::WARNING); + $obj->setDelay(3); + $obj->setStay(5); + $obj->setLevel(NotifyType::ERROR); + $obj->setMessage('msg'); + $obj->setTitle('title'); + + self::assertEquals([ + 'type' => 'notify', + 'time' => 3, + 'stay' => 5, + 'msg' => 'msg', + 'title' => 'title', + 'level' => NotifyType::ERROR + ], $obj->toArray()); + + self::assertEquals(\json_encode([ + 'type' => 'notify', + 'time' => 3, + 'stay' => 5, + 'msg' => 'msg', + 'title' => 'title', + 'level' => NotifyType::ERROR + ]), $obj->serialize()); + + self::assertEquals([ + 'type' => 'notify', + 'time' => 3, + 'stay' => 5, + 'msg' => 'msg', + 'title' => 'title', + 'level' => NotifyType::ERROR + ], $obj->jsonSerialize()); + + $obj2 = new Notify(); + $obj2->unserialize($obj->serialize()); + self::assertEquals($obj, $obj2); + } +} diff --git a/tests/Model/Message/NotifyTypeTest.php b/tests/Model/Message/NotifyTypeTest.php new file mode 100644 index 000000000..12f822c19 --- /dev/null +++ b/tests/Model/Message/NotifyTypeTest.php @@ -0,0 +1,31 @@ +toArray()['uri']); + self::assertEquals(0, $obj->toArray()['time']); + self::assertEquals(false, $obj->toArray()['new']); + } + + public function testSetGet() + { + $obj = new Redirect('url', true); + + self::assertEquals(['type' => 'redirect', 'time' => 0, 'uri' => 'url', 'new' => true], $obj->toArray()); + self::assertEquals(\json_encode(['type' => 'redirect', 'time' => 0, 'uri' => 'url', 'new' => true]), $obj->serialize()); + self::assertEquals(['type' => 'redirect', 'time' => 0, 'uri' => 'url', 'new' => true], $obj->jsonSerialize()); + + $obj->setDelay(6); + $obj->setUri('test'); + self::assertEquals(['type' => 'redirect', 'time' => 6, 'uri' => 'test', 'new' => true], $obj->toArray()); + + $obj2 = new Redirect(); + $obj2->unserialize($obj->serialize()); + self::assertEquals($obj, $obj2); + } +} diff --git a/tests/Model/Message/ReloadTest.php b/tests/Model/Message/ReloadTest.php new file mode 100644 index 000000000..c487a237f --- /dev/null +++ b/tests/Model/Message/ReloadTest.php @@ -0,0 +1,53 @@ +toArray()['time']); + } + + public function testSetGet() + { + $obj = new Reload(5); + + self::assertEquals(['type' => 'reload', 'time' => 5], $obj->toArray()); + self::assertEquals(\json_encode(['type' => 'reload', 'time' => 5]), $obj->serialize()); + self::assertEquals(['type' => 'reload', 'time' => 5], $obj->jsonSerialize()); + + $obj->setDelay(6); + self::assertEquals(['type' => 'reload', 'time' => 6], $obj->toArray()); + + $obj2 = new Reload(); + $obj2->unserialize($obj->serialize()); + self::assertEquals($obj, $obj2); + } +}