123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- <?php
-
-
- namespace Doctrine\DBAL\Schema;
-
- use Doctrine\DBAL\Platforms\AbstractPlatform;
-
-
- abstract class AbstractAsset
- {
-
-
- protected $_name;
-
-
-
- protected $_namespace;
-
-
-
- protected $_quoted = false;
-
-
-
- protected function _setName($name)
- {
- if ($this->isIdentifierQuoted($name)) {
- $this->_quoted = true;
- $name = $this->trimQuotes($name);
- }
- if (strpos($name, ".") !== false) {
- $parts = explode(".", $name);
- $this->_namespace = $parts[0];
- $name = $parts[1];
- }
- $this->_name = $name;
- }
-
-
-
- public function isInDefaultNamespace($defaultNamespaceName)
- {
- return $this->_namespace == $defaultNamespaceName || $this->_namespace === null;
- }
-
-
-
- public function getNamespaceName()
- {
- return $this->_namespace;
- }
-
-
-
- public function getShortestName($defaultNamespaceName)
- {
- $shortestName = $this->getName();
- if ($this->_namespace == $defaultNamespaceName) {
- $shortestName = $this->_name;
- }
- return strtolower($shortestName);
- }
-
-
-
- public function getFullQualifiedName($defaultNamespaceName)
- {
- $name = $this->getName();
- if ( ! $this->_namespace) {
- $name = $defaultNamespaceName . "." . $name;
- }
- return strtolower($name);
- }
-
-
-
- public function isQuoted()
- {
- return $this->_quoted;
- }
-
-
-
- protected function isIdentifierQuoted($identifier)
- {
- return (isset($identifier[0]) && ($identifier[0] == '`' || $identifier[0] == '"'));
- }
-
-
-
- protected function trimQuotes($identifier)
- {
- return str_replace(array('`', '"'), '', $identifier);
- }
-
-
-
- public function getName()
- {
- if ($this->_namespace) {
- return $this->_namespace . "." . $this->_name;
- }
- return $this->_name;
- }
-
-
-
- public function getQuotedName(AbstractPlatform $platform)
- {
- $keywords = $platform->getReservedKeywordsList();
- $parts = explode(".", $this->getName());
- foreach ($parts as $k => $v) {
- $parts[$k] = ($this->_quoted || $keywords->isKeyword($v)) ? $platform->quoteIdentifier($v) : $v;
- }
-
- return implode(".", $parts);
- }
-
-
-
- protected function _generateIdentifierName($columnNames, $prefix='', $maxSize=30)
- {
- $hash = implode("", array_map(function($column) {
- return dechex(crc32($column));
- }, $columnNames));
- return substr(strtoupper($prefix . "_" . $hash), 0, $maxSize);
- }
- }
|