/** * Quote an identifier and an optional alias. * * @param string|array|Zend_Db_Expr $ident The identifier or expression. * @param string $alias An optional alias. * @param boolean $auto If true, heed the AUTO_QUOTE_IDENTIFIERS config option. * @param string $as The string to add between the identifier/expression and the alias. * @return string The quoted identifier and alias. */ protected function _quoteIdentifierAs($ident, $alias = null, $auto = false, $as = ' AS ') { if ($ident instanceof Zend_Db_Expr) { $quoted = $ident->__toString(); } elseif ($ident instanceof Zend_Db_Select) { $quoted = '(' . $ident->assemble() . ')'; } else { if (is_string($ident)) { $ident = explode('.', $ident); } if (is_array($ident)) { $segments = array(); foreach ($ident as $segment) { if ($segment instanceof Zend_Db_Expr) { $segments[] = $segment->__toString(); } else { $segments[] = $this->_quoteIdentifier($segment, $auto); } } if ($alias !== null && end($ident) == $alias) { $alias = null; } $quoted = implode('.', $segments); } else { $quoted = $this->_quoteIdentifier($ident, $auto); } } if ($alias !== null) { $quoted .= $as . $this->_quoteIdentifier($alias, $auto); } return $quoted; }