Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
33.33% |
1 / 3 |
CRAP | |
35.29% |
6 / 17 |
| Meta | |
0.00% |
0 / 1 |
|
33.33% |
1 / 3 |
25.34 | |
35.29% |
6 / 17 |
| install | |
100.00% |
1 / 1 |
2 | |
100.00% |
6 / 6 |
|||
| __get | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 3 |
|||
| __set | |
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 8 |
|||
| <?php | |
| namespace Entity; | |
| class Meta extends ModelBase | |
| { | |
| private $entity; | |
| protected function install() | |
| { | |
| $dbPrefix = $this->getDbPrefix(); | |
| $result = self::$dbo->exec("CREATE TABLE IF NOT EXISTS `{$dbPrefix}meta` ( | |
| `entity_id` INTEGER(11) UNSIGNED NOT NULL, | |
| `entityType` VARCHAR(32) NOT NULL, | |
| `lang` VARCHAR(8) NULL, | |
| `key` VARCHAR(64) NOT NULL, | |
| `value` TEXT NULL, | |
| UNIQUE(`entity_id`, `entityType`, `lang`) | |
| )"); | |
| if ($result === false) | |
| throw new \Exception(get_class().": ".self::$dbo->errorInfo()[2]); | |
| return true; | |
| } | |
| public function __get($key) | |
| { | |
| if ($key == "entity") | |
| return $this->entity; | |
| return parent::__get($key); | |
| } | |
| public function __set($key, $value) | |
| { | |
| if ($key == "entity") | |
| { | |
| parent::__set("entityId", $value->id); | |
| parent::__set("entityType", get_class($value)); | |
| return $value; | |
| } | |
| else if ($key == "entityId" || $key == "entityType") | |
| throw new \Exception("Cannot access private field {$key}"); | |
| return parent::__set($key, $value); | |
| } | |
| } | |