ecom
E-commerce cms
 All Data Structures Namespaces Files Functions Variables Pages
Meta.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Entity;
4 
5 class Meta extends ModelBase
6 {
7  private $entity;
8 
9  protected function install()
10  {
11  $dbPrefix = $this->getDbPrefix();
12  $result = self::$dbo->exec("CREATE TABLE IF NOT EXISTS `{$dbPrefix}meta` (
13  `entity_id` INTEGER(11) UNSIGNED NOT NULL,
14  `entityType` VARCHAR(32) NOT NULL,
15  `lang` VARCHAR(8) NULL,
16  `key` VARCHAR(64) NOT NULL,
17  `value` TEXT NULL,
18  UNIQUE(`entity_id`, `entityType`, `lang`)
19  )");
20  if ($result === false)
21  throw new \Exception(get_class().": ".self::$dbo->errorInfo()[2]);
22  return true;
23  }
24 
25  public function __get($key)
26  {
27  if ($key == "entity")
28  return $this->entity;
29  return parent::__get($key);
30  }
31 
32  public function __set($key, $value)
33  {
34  if ($key == "entity")
35  {
36  parent::__set("entityId", $value->id);
37  parent::__set("entityType", get_class($value));
38  return $value;
39  }
40  else if ($key == "entityId" || $key == "entityType")
41  throw new \Exception("Cannot access private field {$key}");
42  return parent::__set($key, $value);
43  }
44 }
45 
install()
Definition: Meta.php:9
__get($key)
Definition: Meta.php:25
__set($key, $value)
Definition: Meta.php:32