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
<?php
namespace Entity;
class Cms extends ModelBase
{
    protected function install()
    {
        $dbPrefix = $this->getDbPrefix();
        $result = self::$dbo->exec("CREATE TABLE IF NOT EXISTS `{$dbPrefix}cms` (
            `id` INTEGER(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
            `shurl` VARCHAR(255) NOT NULL,
            `controller` VARCHAR(255) NOT NULL,
            `order` INTEGER UNSIGNED NOT NULL DEFAULT 0,
            UNIQUE(`shurl`)
        )");
        if ($result === false)
            throw new \Exception(get_class().": ".self::$dbo->errorInfo()[2]);
        self::createRoute("/", "\\Controller\\HomeController", 50);
        self::createRoute("/:category", "\\Controller\\CategoryController", 50);
        self::createRoute("/:category/:product", "\\Controller\\ProductController", 50);
        self::createRoute("/:product", "\\Controller\\ProductController", 60);
        return true;
    }
    private function createRoute($category, $controller, $order)
    {
        $cms = new self();
        $cms->shurl = $category;
        $cms->controller = $controller;
        $cms->order = $order;
        $cms->save();
    }
}