* @package Mammut\DB\Model */ class RefInfo extends \Mammut\StrictObject { /** * Database behaviour "ON x NO ACTION" */ const ACT_PREVENT = 'prevent'; /** * Database behaviour "ON x CASCADE" */ const ACT_CASCADE = 'cascade'; /** * Database behaviour "ON x SET NULL" */ const ACT_NULL = 'null'; /** * Database behaviour "ON x SET DEFAULT" */ const ACT_DEFAULT = 'default'; private $name = NULL; private $base; private $refTable; private $refColumns; private $update = self::ACT_PREVENT; private $delete = self::ACT_PREVENT; /** * Create a new RefInfo model. * * @param mixed $base * @param mixed $refTable * @param mixed $refColumns * @param string $update * a ACT_* constant * @param string $delete * a ACT_* constant * @param string $name * the reference name */ public function __construct($base, $refTable, $refColumns, $update = self::ACT_PREVENT, $delete = self::ACT_PREVENT, $name = NULL) { $this->name = $name; $this->base = $base; $this->refTable = $refTable; $this->refColumns = $refColumns; $this->setUpdate($update); $this->setDelete($delete); } /** * Checks if an action is a valid name * * @param string $a * the action name which should be checked * @return boolean true if known, false otherwise */ protected function validAction($a) { return in_array($a, [ self::ACT_PREVENT, self::ACT_CASCADE, self::ACT_NULL, self::ACT_DEFAULT ]); } public function getName() { return $this->name; } /** * * @return $this */ public function setName($name) { $this->name = $name; return $this; } public function getBase() { return $this->base; } /** * * @return $this */ public function setBase($base) { $this->base = $base; return $this; } public function getRefTable() { return $this->refTable; } /** * * @return $this */ public function setRefTable($refTable) { $this->refTable = $refTable; return $this; } public function getRefColumns() { return $this->refColumns; } /** * * @return $this */ public function setRefColumns($refColumns) { $this->refColumns = $refColumns; return $this; } public function getUpdate() { return $this->update; } /** * Defines the action that should be taken if the parent row is updated * * @param string $update * one of the ACT_* constants * @return $this */ public function setUpdate($update) { if(!$this->validAction($update)) throw new \InvalidArgumentException($update); $this->update = $update; return $this; } public function getDelete() { return $this->delete; } /** * Defines the action that should be taken if the parent row is deleted * * @param $delete string * one of the ACT_* constants * @return $this */ public function setDelete($delete) { if(!$this->validAction($delete)) throw new \InvalidArgumentException($delete); $this->delete = $delete; return $this; } }