From bf6655a534a6775d30cafa67bd801276bda1d98d Mon Sep 17 00:00:00 2001 From: polo Date: Tue, 13 Aug 2024 23:45:21 +0200 Subject: =?UTF-8?q?VERSION=200.2=20doctrine=20ORM=20et=20entit=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../doctrine/dbal/src/Schema/UniqueConstraint.php | 152 +++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 vendor/doctrine/dbal/src/Schema/UniqueConstraint.php (limited to 'vendor/doctrine/dbal/src/Schema/UniqueConstraint.php') diff --git a/vendor/doctrine/dbal/src/Schema/UniqueConstraint.php b/vendor/doctrine/dbal/src/Schema/UniqueConstraint.php new file mode 100644 index 0000000..a33d446 --- /dev/null +++ b/vendor/doctrine/dbal/src/Schema/UniqueConstraint.php @@ -0,0 +1,152 @@ + + */ + protected array $columns = []; + + /** + * Platform specific flags + * + * @var array + */ + protected array $flags = []; + + /** + * @param array $columns + * @param array $flags + * @param array $options + */ + public function __construct( + string $name, + array $columns, + array $flags = [], + private readonly array $options = [], + ) { + $this->_setName($name); + + foreach ($columns as $column) { + $this->addColumn($column); + } + + foreach ($flags as $flag) { + $this->addFlag($flag); + } + } + + /** + * Returns the names of the referencing table columns the constraint is associated with. + * + * @return list + */ + public function getColumns(): array + { + return array_keys($this->columns); + } + + /** + * Returns the quoted representation of the column names the constraint is associated with. + * + * But only if they were defined with one or a column name + * is a keyword reserved by the platform. + * Otherwise, the plain unquoted value as inserted is returned. + * + * @param AbstractPlatform $platform The platform to use for quotation. + * + * @return list + */ + public function getQuotedColumns(AbstractPlatform $platform): array + { + $columns = []; + + foreach ($this->columns as $column) { + $columns[] = $column->getQuotedName($platform); + } + + return $columns; + } + + /** @return array */ + public function getUnquotedColumns(): array + { + return array_map($this->trimQuotes(...), $this->getColumns()); + } + + /** + * Returns platform specific flags for unique constraint. + * + * @return array + */ + public function getFlags(): array + { + return array_keys($this->flags); + } + + /** + * Adds flag for a unique constraint that translates to platform specific handling. + * + * @return $this + * + * @example $uniqueConstraint->addFlag('CLUSTERED') + */ + public function addFlag(string $flag): self + { + $this->flags[strtolower($flag)] = true; + + return $this; + } + + /** + * Does this unique constraint have a specific flag? + */ + public function hasFlag(string $flag): bool + { + return isset($this->flags[strtolower($flag)]); + } + + /** + * Removes a flag. + */ + public function removeFlag(string $flag): void + { + unset($this->flags[strtolower($flag)]); + } + + public function hasOption(string $name): bool + { + return isset($this->options[strtolower($name)]); + } + + public function getOption(string $name): mixed + { + return $this->options[strtolower($name)]; + } + + /** @return array */ + public function getOptions(): array + { + return $this->options; + } + + protected function addColumn(string $column): void + { + $this->columns[$column] = new Identifier($column); + } +} -- cgit v1.2.3