MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
AbstractAsset.php
Ir para a documentação deste ficheiro.
1<?php
2/*
3 * $Id$
4 *
5 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16 *
17 * This software consists of voluntary contributions made by many individuals
18 * and is licensed under the LGPL. For more information, see
19 * <http://www.doctrine-project.org>.
20 */
21
23
25
38abstract class AbstractAsset
39{
43 protected $_name;
44
45 protected $_quoted = false;
46
52 protected function _setName($name)
53 {
54 if (strlen($name)) {
55 // TODO: find more elegant way to solve this issue.
56 if ($name[0] == '`') {
57 $this->_quoted = true;
58 $name = trim($name, '`');
59 } else if ($name[0] == '"') {
60 $this->_quoted = true;
61 $name = trim($name, '"');
62 }
63 }
64 $this->_name = $name;
65 }
66
72 public function getName()
73 {
74 return $this->_name;
75 }
76
84 public function getQuotedName(AbstractPlatform $platform)
85 {
86 return ($this->_quoted) ? $platform->quoteIdentifier($this->_name) : $this->_name;
87 }
88
101 protected function _generateIdentifierName($columnNames, $postfix='', $maxSize=30)
102 {
103 $columnCount = count($columnNames);
104 $postfixLen = strlen($postfix);
105 $parts = array_map(function($columnName) use($columnCount, $postfixLen, $maxSize) {
106 return substr($columnName, -floor(($maxSize-$postfixLen)/$columnCount - 1));
107 }, $columnNames);
108 $parts[] = $postfix;
109
110 $identifier = trim(implode("_", $parts), '_');
111 // using implicit schema support of DB2 and Postgres there might be dots in the auto-generated
112 // identifier names which can easily be replaced by underscores.
113 $identifier = str_replace(".", "_", $identifier);
114
115 if (is_numeric(substr($identifier, 0, 1))) {
116 $identifier = "i" . substr($identifier, 0, strlen($identifier)-1);
117 }
118
119 return $identifier;
120 }
121}
_generateIdentifierName($columnNames, $postfix='', $maxSize=30)
getQuotedName(AbstractPlatform $platform)