Exception
2 years ago
Visitor
9 months ago
AbstractAsset.php
2 years ago
AbstractSchemaManager.php
9 months ago
Column.php
2 years ago
ColumnDiff.php
2 years ago
Comparator.php
2 years ago
Constraint.php
2 years ago
DB2SchemaManager.php
2 years ago
DefaultSchemaManagerFactory.php
2 years ago
ForeignKeyConstraint.php
9 months ago
Identifier.php
2 years ago
Index.php
2 years ago
LegacySchemaManagerFactory.php
2 years ago
MySQLSchemaManager.php
9 months ago
OracleSchemaManager.php
2 years ago
PostgreSQLSchemaManager.php
9 months ago
SQLServerSchemaManager.php
9 months ago
Schema.php
2 years ago
SchemaConfig.php
2 years ago
SchemaDiff.php
2 years ago
SchemaException.php
2 years ago
SchemaManagerFactory.php
2 years ago
Sequence.php
2 years ago
SqliteSchemaManager.php
8 months ago
Table.php
2 years ago
TableDiff.php
2 years ago
UniqueConstraint.php
2 years ago
View.php
2 years ago
AbstractAsset.php
95 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Doctrine\DBAL\Schema; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Doctrine\DBAL\Platforms\AbstractPlatform; |
| 5 | use MailPoetVendor\Doctrine\Deprecations\Deprecation; |
| 6 | use function array_map; |
| 7 | use function crc32; |
| 8 | use function dechex; |
| 9 | use function explode; |
| 10 | use function implode; |
| 11 | use function str_replace; |
| 12 | use function strpos; |
| 13 | use function strtolower; |
| 14 | use function strtoupper; |
| 15 | use function substr; |
| 16 | abstract class AbstractAsset |
| 17 | { |
| 18 | protected $_name = ''; |
| 19 | protected $_namespace; |
| 20 | protected $_quoted = \false; |
| 21 | protected function _setName($name) |
| 22 | { |
| 23 | if ($this->isIdentifierQuoted($name)) { |
| 24 | $this->_quoted = \true; |
| 25 | $name = $this->trimQuotes($name); |
| 26 | } |
| 27 | if (strpos($name, '.') !== \false) { |
| 28 | $parts = explode('.', $name); |
| 29 | $this->_namespace = $parts[0]; |
| 30 | $name = $parts[1]; |
| 31 | } |
| 32 | $this->_name = $name; |
| 33 | } |
| 34 | public function isInDefaultNamespace($defaultNamespaceName) |
| 35 | { |
| 36 | return $this->_namespace === $defaultNamespaceName || $this->_namespace === null; |
| 37 | } |
| 38 | public function getNamespaceName() |
| 39 | { |
| 40 | return $this->_namespace; |
| 41 | } |
| 42 | public function getShortestName($defaultNamespaceName) |
| 43 | { |
| 44 | $shortestName = $this->getName(); |
| 45 | if ($this->_namespace === $defaultNamespaceName) { |
| 46 | $shortestName = $this->_name; |
| 47 | } |
| 48 | return strtolower($shortestName); |
| 49 | } |
| 50 | public function getFullQualifiedName($defaultNamespaceName) |
| 51 | { |
| 52 | Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4814', 'AbstractAsset::getFullQualifiedName() is deprecated.' . ' Use AbstractAsset::getNamespaceName() and ::getName() instead.'); |
| 53 | $name = $this->getName(); |
| 54 | if ($this->_namespace === null) { |
| 55 | $name = $defaultNamespaceName . '.' . $name; |
| 56 | } |
| 57 | return strtolower($name); |
| 58 | } |
| 59 | public function isQuoted() |
| 60 | { |
| 61 | return $this->_quoted; |
| 62 | } |
| 63 | protected function isIdentifierQuoted($identifier) |
| 64 | { |
| 65 | return isset($identifier[0]) && ($identifier[0] === '`' || $identifier[0] === '"' || $identifier[0] === '['); |
| 66 | } |
| 67 | protected function trimQuotes($identifier) |
| 68 | { |
| 69 | return str_replace(['`', '"', '[', ']'], '', $identifier); |
| 70 | } |
| 71 | public function getName() |
| 72 | { |
| 73 | if ($this->_namespace !== null) { |
| 74 | return $this->_namespace . '.' . $this->_name; |
| 75 | } |
| 76 | return $this->_name; |
| 77 | } |
| 78 | public function getQuotedName(AbstractPlatform $platform) |
| 79 | { |
| 80 | $keywords = $platform->getReservedKeywordsList(); |
| 81 | $parts = explode('.', $this->getName()); |
| 82 | foreach ($parts as $k => $v) { |
| 83 | $parts[$k] = $this->_quoted || $keywords->isKeyword($v) ? $platform->quoteIdentifier($v) : $v; |
| 84 | } |
| 85 | return implode('.', $parts); |
| 86 | } |
| 87 | protected function _generateIdentifierName($columnNames, $prefix = '', $maxSize = 30) |
| 88 | { |
| 89 | $hash = implode('', array_map(static function ($column) : string { |
| 90 | return dechex(crc32($column)); |
| 91 | }, $columnNames)); |
| 92 | return strtoupper(substr($prefix . '_' . $hash, 0, $maxSize)); |
| 93 | } |
| 94 | } |
| 95 |