table = &$table; $this->setKeys($keys); $this->setReferencedTable($referencedTable); $this->setReferencedCols($referencedCols); } /** * @param mixed $keys */ public function setKeys($keys){ $this->keys = (array)$keys; } /** * @param mixed $referencedTable */ public function setReferencedTable($referencedTable){ $this->referencedTable = $referencedTable; } /** * @param mixed $referencedCols */ public function setReferencedCols($referencedCols){ $this->referencedCols = (array)$referencedCols; } /** * @param string $onDelete */ public function setOnDelete($onDelete){ if( in_array($onDelete, self::ACTIONS_DELETE) ){ $this->onDelete = $onDelete; }else{ trigger_error(sprintf(self::ERROR_ACTION_NOT_SUPPORTED, $onDelete)); } } /** * @param string $onUpdate */ public function setOnUpdate($onUpdate){ if( in_array($onUpdate, self::ACTIONS_UPDATE) ){ $this->onUpdate = $onUpdate; }else{ trigger_error(sprintf(self::ERROR_ACTION_NOT_SUPPORTED, $onUpdate)); } } /** * @return array */ public function getKeys(){ return $this->keys; } /** * @return string */ public function getReferencedTable(){ return $this->referencedTable; } /** * @return array */ public function getReferencedCols(){ return $this->referencedCols; } /** * @return string */ public function getOnDelete(){ return $this->onDelete; } /** * @return string */ public function getOnUpdate(){ return $this->onUpdate; } /** * get a constraint name for this table. * This can either be used to generate unique constraint names for foreign keys in parent tables * or generate a "part" of a name. e.g. for db-Query all constraints of this table (ignore columns) * by "LIKE" selecting "information_schema" * -> To get a certain constraint or generate a unique constraint, ALL params are required! * @return string */ public function getConstraintName(){ $constraintName = 'fk_' . $this->table->name; if(!empty($this->getKeys())){ $constraintName .= '___' . implode('__', $this->getKeys()); if(!empty($this->getReferencedTable())){ $constraintName .= '___' . $this->getReferencedTable(); if(!empty($this->getReferencedCols())){ $constraintName .= '___' . implode('__', $this->getReferencedCols()); } } } return $constraintName; } /** * checks if constraint is valid * -> all required members must be set! * @return bool */ public function isValid(){ $valid = false; if( !empty($this->getKeys()) && !empty($this->getReferencedTable()) && !empty($this->getReferencedCols()) ){ $valid = true; } return $valid; } }