本文整理汇总了PHP中ForeignKey::parse方法的典型用法代码示例。如果您正苦于以下问题:PHP ForeignKey::parse方法的具体用法?PHP ForeignKey::parse怎么用?PHP ForeignKey::parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ForeignKey
的用法示例。
在下文中一共展示了ForeignKey::parse方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
private function __construct($sql)
{
preg_match('/^CREATE TABLE (?<name>[^\\s\\(]+) \\((?<defs>.*)\\)\\s*$/is', $sql, $matches);
$this->m_name = $matches['name'];
$defs = array_map('trim', preg_split('/,[\\t ]*[\\r\\n]/', $matches['defs']));
$this->m_columns = [];
$this->m_foreign = [];
$this->m_unique = [];
$constraints = [];
foreach ($defs as $def) {
if (count($constraints) || ($matched = self::match('(?:CONSTRAINT|PRIMARY|UNIQUE|FOREIGN|CHECK)\\b', $def, $m))) {
if (isset($matched) && !$matched) {
throw new \Exception('Failed to parse start of constraint');
}
// table constraint
// check for optional constraint name
$constraintName = NULL;
if (self::match('CONSTRAINT (?<name>' . Column::R_NAME . ')', $def, $m)) {
$constraintName = $m['name'];
$def = ltrim(substr($def, strlen($m[0])));
}
if ($uniqueKey = UniqueKey::parse($constraintName, $def)) {
$this->m_unique[] = $uniqueKey;
} else {
if ($foreignKey = ForeignKey::parse($constraintName, $def)) {
$this->m_foreign[$foreignKey->localField()] = $foreignKey;
} else {
throw new \Exception('Failed to parse constraint');
}
}
} else {
$column = Column::parse($def);
$this->m_columns[$column->name()] = $column;
}
}
}