* @copyright 2010-2014 Justin Swanhart and André Rothe * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) * @version SVN: $Id$ * */ namespace PHPSQLParser\builders; use PHPSQLParser\exceptions\UnableToCreateSQLException; /** * This class implements the builder for the index options of a CREATE INDEX * statement. * 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 CreateIndexOptionsBuilder implements Builder { protected function buildIndexParser($parsed) { $builder = new IndexParserBuilder(); return $builder->build($parsed); } protected function buildIndexSize($parsed) { $builder = new IndexSizeBuilder(); return $builder->build($parsed); } protected function buildIndexType($parsed) { $builder = new IndexTypeBuilder(); return $builder->build($parsed); } protected function buildIndexComment($parsed) { $builder = new IndexCommentBuilder(); return $builder->build($parsed); } protected function buildIndexAlgorithm($parsed) { $builder = new IndexAlgorithmBuilder(); return $builder->build($parsed); } protected function buildIndexLock($parsed) { $builder = new IndexLockBuilder(); return $builder->build($parsed); } public function build(array $parsed) { if ($parsed['options'] === false) { return ''; } $sql = ''; foreach ($parsed['options'] as $k => $v) { $len = strlen($sql); $sql .= $this->buildIndexAlgorithm($v); $sql .= $this->buildIndexLock($v); $sql .= $this->buildIndexComment($v); $sql .= $this->buildIndexParser($v); $sql .= $this->buildIndexSize($v); $sql .= $this->buildIndexType($v); if ($len == strlen($sql)) { throw new UnableToCreateSQLException('CREATE INDEX options', $k, $v, 'expr_type'); } $sql .= ' '; } return ' ' . substr($sql, 0, -1); } } ?>