torrentpier-lts/library/Zend/Db/Sql/Ddl/Constraint/AbstractConstraint.php

131 lines
2.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\Constraint;
abstract class AbstractConstraint implements ConstraintInterface
{
2023-04-01 09:03:34 +03:00
/**
* @var string
*/
protected $columnSpecification = ' (%s)';
/**
* @var string
*/
protected $namedSpecification = 'CONSTRAINT %s ';
/**
* @var string
*/
protected $specification = '';
/**
* @var string
*/
protected $name = '';
/**
* @var array
*/
protected $columns = array();
/**
* @param null|string|array $columns
2023-04-01 09:03:34 +03:00
* @param null|string $name
*/
public function __construct($columns = null, $name = null)
{
if ($columns) {
$this->setColumns($columns);
}
$this->setName($name);
}
/**
* @param string $name
* @return self
*/
public function setName($name)
{
$this->name = (string) $name;
return $this;
}
/**
* @return string
*/
2023-04-01 09:03:34 +03:00
public function getName()
{
2023-04-01 09:03:34 +03:00
return $this->name;
}
/**
* @param null|string|array $columns
* @return self
*/
public function setColumns($columns)
{
2023-04-01 09:03:34 +03:00
$this->columns = (array) $columns;
return $this;
}
/**
* @param string $column
* @return self
*/
public function addColumn($column)
{
$this->columns[] = $column;
return $this;
}
/**
2023-04-01 09:03:34 +03:00
* {@inheritDoc}
*/
public function getColumns()
{
return $this->columns;
}
2023-04-01 09:03:34 +03:00
/**
* {@inheritDoc}
*/
public function getExpressionData()
{
$colCount = count($this->columns);
$newSpecTypes = array();
$values = array();
$newSpec = '';
if ($this->name) {
$newSpec .= $this->namedSpecification;
$values[] = $this->name;
$newSpecTypes[] = self::TYPE_IDENTIFIER;
}
$newSpec .= $this->specification;
if ($colCount) {
$values = array_merge($values, $this->columns);
$newSpecParts = array_fill(0, $colCount, '%s');
$newSpecTypes = array_merge($newSpecTypes, array_fill(0, $colCount, self::TYPE_IDENTIFIER));
$newSpec .= sprintf($this->columnSpecification, implode(', ', $newSpecParts));
}
return array(array(
$newSpec,
$values,
$newSpecTypes,
));
}
}