Files
pathfinder/app/Db/Sql/Mysql/Column.php
Mark Friedrich cf553b7c20 - Upgraded "[_Cortex_](https://github.com/ikkez/f3-cortex)" PHP dependency to current dev-master
- Fixed "Deprecation" warning on Composer `1.10.5`, closed #951
2020-04-16 18:20:35 +02:00

76 lines
2.2 KiB
PHP

<?php
namespace Exodus4D\Pathfinder\Db\Sql\Mysql;
use DB\SQL;
class Column extends SQL\Column {
/**
* missing table name error
*/
const ERROR_TABLE_NAME_MISSING = 'Table name missing for FOREIGN KEY in `%s`';
/**
* drop constraint from this column
* @param Constraint $constraint
*/
public function dropConstraint(Constraint $constraint){
$this->table->dropConstraint($constraint);
}
/**
* add constraint to this column
* @param Constraint $constraint
*/
public function addConstraint(Constraint $constraint){
$this->table->addConstraint($constraint);
}
/**
* @param Constraint $constraint
* @return mixed
*/
public function constraintExists(Constraint $constraint){
return $this->table->constraintExists($constraint);
}
/**
* get a new column based constraint
* $constraintData['table'] => referenceTable name (required)
* $constraintData['id'] => referenceColumns (optional) default: ['id']
* $constraintData['on-delete'] => ON DELETE action (optional) default: see \DB\SQL\MySQL\Constraint const
* $constraintData['on-update'] => ON UPDATE action (optional) default: see \DB\SQL\MySQL\Constraint const
*
* @param array $constraintData
* @return Constraint
*/
public function newConstraint($constraintData){
$constraint = null;
if(isset($constraintData['table'])){
if(isset($constraintData['column'])){
$constraintData['column'] = (array)$constraintData['column'];
}else{
$constraintData['column'] = ['id'];
}
$constraint = new Constraint($this->table, $this->name, $constraintData['table'], $constraintData['column']);
if(isset($constraintData['on-delete'])){
$constraint->setOnDelete($constraintData['on-delete']);
}
if(isset($constraintData['on-update'])){
$constraint->setOnUpdate($constraintData['on-update']);
}
}else{
trigger_error(sprintf(self::ERROR_TABLE_NAME_MISSING, $this->table->name . '->' . $this->name));
}
return $constraint;
}
}