* @copyright 2010-2014 Justin Swanhart and André Rothe * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) * @version SVN: $Id: TableBracketExpressionBuilder.php 928 2014-01-08 13:01:57Z phosco@gmx.de $ * */ require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php'; require_once dirname(__FILE__) . '/ColumnDefinitionBuilder.php'; require_once dirname(__FILE__) . '/PrimaryKeyBuilder.php'; require_once dirname(__FILE__) . '/ForeignKeyBuilder.php'; require_once dirname(__FILE__) . '/CheckBuilder.php'; require_once dirname(__FILE__) . '/LikeExpressionBuilder.php'; require_once dirname(__FILE__) . '/../utils/ExpressionType.php'; /** * This class implements the builder for the table expressions * within the create definitions of CREATE TABLE. * You can overwrite all functions to achieve another handling. * * @author André Rothe * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) * */ class TableBracketExpressionBuilder { protected function buildColDef($parsed) { $builder = new ColumnDefinitionBuilder(); return $builder->build($parsed); } protected function buildPrimaryKey($parsed) { $builder = new PrimaryKeyBuilder(); return $builder->build($parsed); } protected function buildForeignKey($parsed) { $builder = new ForeignKeyBuilder(); return $builder->build($parsed); } protected function buildCheck($parsed) { $builder = new CheckBuilder(); return $builder->build($parsed); } protected function buildLikeExpression($parsed) { $builder = new LikeExpressionBuilder(); return $builder->build($parsed); } public function build($parsed) { if ($parsed['expr_type'] !== ExpressionType::BRACKET_EXPRESSION) { return ""; } $sql = ""; foreach ($parsed['sub_tree'] as $k => $v) { $len = strlen($sql); $sql .= $this->buildColDef($v); $sql .= $this->buildPrimaryKey($v); $sql .= $this->buildCheck($v); $sql .= $this->buildLikeExpression($v); $sql .= $this->buildForeignKey($v); if ($len == strlen($sql)) { throw new UnableToCreateSQLException('CREATE TABLE create-def expression subtree', $k, $v, 'expr_type'); } $sql .= ", "; } $sql = " (" . substr($sql, 0, -2) . ")"; return $sql; } } ?>