| Code Coverage
| Classes and Traits | Functions and Methods | Lines
Total | 100.00% covered (success) | 100.00% | 1 / 1 | 100.00% covered (success) | 100.00% | 2 / 2 | CRAP | 100.00% covered (success) | 100.00% | 16 / 16
Cms | 100.00% covered (success) | 100.00% | 1 / 1 | 100.00% covered (success) | 100.00% | 2 / 2 | 3 | 100.00% covered (success) | 100.00% | 16 / 16
install | 100.00% covered (success) | 100.00% | 1 / 1 | 2 | 100.00% covered (success) | 100.00% | 10 / 10
createRoute | 100.00% covered (success) | 100.00% | 1 / 1 | 1 | 100.00% covered (success) | 100.00% | 6 / 6

1 | <?php
2 |
3 | namespace Entity;
4 |
5 | class Cms extends ModelBase
6 | {
7 | protected function install()
8 | {
9 | $dbPrefix = $this->getDbPrefix();
10 | $result = self::$dbo->exec("CREATE TABLE IF NOT EXISTS `{$dbPrefix}cms` (
11 | `id` INTEGER(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
12 | `shurl` VARCHAR(255) NOT NULL,
13 | `controller` VARCHAR(255) NOT NULL,
14 | `order` INTEGER UNSIGNED NOT NULL DEFAULT 0,
15 | UNIQUE(`shurl`)
16 | )");
17 | if ($result === false)
18 | throw new \Exception(get_class().": ".self::$dbo->errorInfo()[2]);
19 | self::createRoute("/", "\\Controller\\HomeController", 50);
20 | self::createRoute("/:category", "\\Controller\\CategoryController", 50);
21 | self::createRoute("/:category/:product", "\\Controller\\ProductController", 50);
22 | self::createRoute("/:product", "\\Controller\\ProductController", 60);
23 | return true;
24 | }
25 |
26 | private function createRoute($category, $controller, $order)
27 | {
28 | $cms = new self();
29 | $cms->shurl = $category;
30 | $cms->controller = $controller;
31 | $cms->order = $order;
32 | $cms->save();
33 | }
34 | }
35 |