torrentpier-lts/library/Zend/Db/Sql/Ddl/CreateTable.php

208 lines
4.7 KiB
PHP
Raw Normal View History

<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
2023-04-01 09:03:34 +03:00
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Sql\Ddl;
use Zend\Db\Adapter\Platform\PlatformInterface;
use Zend\Db\Sql\AbstractSql;
class CreateTable extends AbstractSql implements SqlInterface
{
const COLUMNS = 'columns';
const CONSTRAINTS = 'constraints';
const TABLE = 'table';
/**
2023-04-01 09:03:34 +03:00
* @var Column\ColumnInterface[]
*/
protected $columns = array();
/**
2023-04-01 09:03:34 +03:00
* @var string[]
*/
protected $constraints = array();
/**
* @var bool
*/
protected $isTemporary = false;
/**
2023-04-01 09:03:34 +03:00
* {@inheritDoc}
*/
protected $specifications = array(
self::TABLE => 'CREATE %1$sTABLE %2$s (',
self::COLUMNS => array(
"\n %1\$s" => array(
array(1 => '%1$s', 'combinedby' => ",\n ")
)
),
2023-04-01 09:03:34 +03:00
'combinedBy' => ",",
self::CONSTRAINTS => array(
"\n %1\$s" => array(
array(1 => '%1$s', 'combinedby' => ",\n ")
)
),
2023-04-01 09:03:34 +03:00
'statementEnd' => '%1$s',
);
/**
* @var string
*/
protected $table = '';
/**
* @param string $table
* @param bool $isTemporary
*/
public function __construct($table = '', $isTemporary = false)
{
$this->table = $table;
$this->setTemporary($isTemporary);
}
/**
* @param bool $temporary
* @return self
*/
public function setTemporary($temporary)
{
$this->isTemporary = (bool) $temporary;
return $this;
}
/**
* @return bool
*/
public function isTemporary()
{
return $this->isTemporary;
}
/**
* @param string $name
* @return self
*/
public function setTable($name)
{
$this->table = $name;
return $this;
}
/**
* @param Column\ColumnInterface $column
* @return self
*/
public function addColumn(Column\ColumnInterface $column)
{
$this->columns[] = $column;
return $this;
}
/**
* @param Constraint\ConstraintInterface $constraint
* @return self
*/
public function addConstraint(Constraint\ConstraintInterface $constraint)
{
$this->constraints[] = $constraint;
return $this;
}
/**
* @param string|null $key
* @return array
*/
public function getRawState($key = null)
{
$rawState = array(
self::COLUMNS => $this->columns,
self::CONSTRAINTS => $this->constraints,
self::TABLE => $this->table,
);
return (isset($key) && array_key_exists($key, $rawState)) ? $rawState[$key] : $rawState;
}
/**
2023-04-01 09:03:34 +03:00
* @param PlatformInterface $adapterPlatform
*
* @return string[]
*/
2023-04-01 09:03:34 +03:00
protected function processTable(PlatformInterface $adapterPlatform = null)
{
2023-04-01 09:03:34 +03:00
return array(
$this->isTemporary ? 'TEMPORARY ' : '',
$adapterPlatform->quoteIdentifier($this->table),
);
}
2023-04-01 09:03:34 +03:00
/**
* @param PlatformInterface $adapterPlatform
*
* @return string[][]|null
*/
protected function processColumns(PlatformInterface $adapterPlatform = null)
{
if (! $this->columns) {
return;
}
2023-04-01 09:03:34 +03:00
$sqls = array();
2023-04-01 09:03:34 +03:00
foreach ($this->columns as $column) {
$sqls[] = $this->processExpression($column, $adapterPlatform);
}
2023-04-01 09:03:34 +03:00
return array($sqls);
}
2023-04-01 09:03:34 +03:00
/**
* @param PlatformInterface $adapterPlatform
*
* @return array|string
*/
protected function processCombinedby(PlatformInterface $adapterPlatform = null)
{
2023-04-01 09:03:34 +03:00
if ($this->constraints && $this->columns) {
return $this->specifications['combinedBy'];
}
}
2023-04-01 09:03:34 +03:00
/**
* @param PlatformInterface $adapterPlatform
*
* @return string[][]|null
*/
protected function processConstraints(PlatformInterface $adapterPlatform = null)
{
2023-04-01 09:03:34 +03:00
if (!$this->constraints) {
return;
}
$sqls = array();
2023-04-01 09:03:34 +03:00
foreach ($this->constraints as $constraint) {
2023-04-01 09:03:34 +03:00
$sqls[] = $this->processExpression($constraint, $adapterPlatform);
}
2023-04-01 09:03:34 +03:00
return array($sqls);
}
2023-04-01 09:03:34 +03:00
/**
* @param PlatformInterface $adapterPlatform
*
* @return string[]
*/
protected function processStatementEnd(PlatformInterface $adapterPlatform = null)
{
return array("\n)");
}
}