Escape identifier (column, table) with backticks.

@see: http://dev.mysql.com/doc/refman/5.0/en/identifiers.html

@param string $identifier Identifier name

@return string Quoted identifier
18446
public function quoteName(string $identifier): string
    {
        $identifier = trim($identifier);
        $separators = [' AS ', ' ', '.'];
        foreach ($separators as $sep) {
            $pos = strripos($identifier, $sep);
            if ($pos) {
                return $this->quoteNameWithSeparator($identifier, $sep, $pos);
            }
        }

        return $this->quoteIdentifier($identifier);
    }
1254040
public function quoteIdentifier($identifier)
    {
        $identifier = trim($identifier);

        if ($identifier === '*') {
            return '*';
        }

        if ($identifier === '') {
            return '';
        }

        // string
        if (preg_match('/^[\w-]+$/', $identifier)) {
            return $this->startQuote . $identifier . $this->endQuote;
        }

        // string.string
        if (preg_match('/^[\w-]+\.[^ \*]*$/', $identifier)) {
            $items = explode('.', $identifier);

            return $this->startQuote . implode($this->endQuote . '.' . $this->startQuote, $items) . $this->endQuote;
        }

        // string.*
        if (preg_match('/^[\w-]+\.\*$/', $identifier)) {
            return $this->startQuote . str_replace('.*', $this->endQuote . '.*', $identifier);
        }

        return $identifier;
    }
1071554
public function quoteByFields(array $identifiers): array
    {
        foreach ($identifiers as $key => $identifier) {
            if ($identifier instanceof RawExp) {
                $identifiers[$key] = $identifier->getValue();
                continue;
            }
            // table.id ASC
            if (preg_match('/^([\w-\.]+)(\s)*(.*)$/', $identifier, $match)) {
                $identifiers[$key] = $this->quoteName($match[1]) . $match[2] . $match[3];
                continue;
            }
            $identifiers[$key] = $this->quoteName($identifier);
        }

        return $identifiers;
    }
446668
public function quoteIdentifier($identifier)
    {
        $identifier = trim($identifier);

        if ($identifier === '*' || $identifier === '') {
            return $identifier;
        }

        // string
        if (preg_match('/^[\w-]+$/u', $identifier)) {
            return $this->_startQuote . $identifier . $this->_endQuote;
        }

        // string.string
        if (preg_match('/^[\w-]+\.[^ \*]*$/u', $identifier)) {
            $items = explode('.', $identifier);

            return $this->_startQuote . implode($this->_endQuote . '.' . $this->_startQuote, $items) . $this->_endQuote;
        }

        // string.*
        if (preg_match('/^[\w-]+\.\*$/u', $identifier)) {
            return $this->_startQuote . str_replace('.*', $this->_endQuote . '.*', $identifier);
        }

        // Functions
        if (preg_match('/^([\w-]+)\((.*)\)$/', $identifier, $matches)) {
            return $matches[1] . '(' . $this->quoteIdentifier($matches[2]) . ')';
        }

        // Alias.field AS thing
        if (preg_match('/^([\w-]+(\.[\w\s-]+|\(.*\))*)\s+AS\s*([\w-]+)$/ui', $identifier, $matches)) {
            return $this->quoteIdentifier($matches[1]) . ' AS ' . $this->quoteIdentifier($matches[3]);
        }

        // string.string with spaces
        if (preg_match('/^([\w-]+\.[\w][\w\s\-]*[\w])(.*)/u', $identifier, $matches)) {
            $items = explode('.', $matches[1]);
            $field = implode($this->_endQuote . '.' . $this->_startQuote, $items);

            return $this->_startQuote . $field . $this->_endQuote . $matches[2];
        }

        if (preg_match('/^[\w_\s-]*[\w_-]+/u', $identifier)) {
            return $this->_startQuote . $identifier . $this->_endQuote;
        }

        return $identifier;
    }
1294956
public function findByIdentifier( $identifier )
    {

        $identifier = explode('.', $identifier);

        if( count( $identifier) < 2 ) {
            throw new \InvalidArgumentException("yeah, not a table.column level identifier");
        }

        $columnName = array_pop( $identifier );
        $tableName = implode('.',$identifier );

        $table = new Query( <<<SQL
SELECT
    a.attrelid::text || '.' || a.attnum AS key
FROM
    pg_attribute AS a
WHERE
    a.attrelid = quote_ident(%tableName:%)::regclass::oid AND
    attname = %columnName:% AND
    a.attnum > 0
SQL
,
            array(
                'tableName' => $tableName,
                'columnName' => $columnName,
            )
        );

        try {
            $columnKey = $this->db->query( $table )->fetch( Result::FETCH_SINGLE );
        } catch( \Exception $e ) {
            return null;
        }

        return $this->find( $columnKey );

    }
486125
public function findOneByIdentifier($identifier) {
		$statement = $this->connection->prepare('SELECT * FROM objects WHERE __identifier__ = :identifier LIMIT 1');
		$statement->bindValue(':identifier', $identifier);

		return $statement->execute()->fetchArray(SQLITE3_ASSOC);
	}
1118187
public function quoteIdentifier($identifier)
    {
        $parts = explode(".", $identifier);
        if (count($parts) > 1) {
            return $this->quoteIdentifier($parts[0]) . '.' . $this->quoteIdentifier($parts[1]);
        }

        return '`' . str_replace('`', '``', $identifier) . '`';
    }
764959
public function offsetGet($identifier)
    {
        $keys = $this->_parseIdentifier($identifier);

        $result = $this->toArray();
        foreach($keys as $key)
        {
            if(is_array($result) && array_key_exists($key, $result)) {
                $result = $result[$key];
            } else {
                $result = null;
                break;
            }
        }

        return $result;
    }
1322163
public function quoteTable($table): string
	{
		$table = $this->prefixTable($table);

		// Finally, quote the table
		return $this->quoteIdent($table);
	}
214918
public static function convertStringToMachineSafe($identifier, array $filter = array(
    ' ' => '_',
    '-' => '_',
    '/' => '_',
    '[' => '_',
    ']' => '',
  )) {
    $identifier = str_replace(array_keys($filter), array_values($filter), $identifier);
    // Valid characters are:
    // - a-z (U+0030 - U+0039)
    // - A-Z (U+0041 - U+005A)
    // - the underscore (U+005F)
    // - 0-9 (U+0061 - U+007A)
    // - ISO 10646 characters U+00A1 and higher
    // We strip out any character not in the above list.
    $identifier = preg_replace(
      '/[^\x{0030}-\x{0039}\x{0041}-\x{005A}\x{005F}\x{0061}-\x{007A}\x{00A1}-\x{FFFF}]/u',
      '',
      $identifier);
    // Identifiers cannot start with a digit, two hyphens, or a hyphen followed
    // by a digit.
    $identifier = preg_replace(array(
      '/^[0-9]/',
      '/^(-[0-9])|^(--)/',
    ), array('_', '__'), $identifier);
    return strtolower($identifier);
  }
962793
protected static function _parseIdentifier($identifier)
    {
        $parts = array();
        $hash  = $identifier;

        // Validate the variable format
        if (strpos($identifier, '.') !== false) {
            // Split the variable name into it's parts
            $parts = explode('.', $identifier);

            // Validate the hash name
            $hash   = array_shift($parts);
        }

        $hash = strtoupper($hash);

        return array($hash, $parts);
    }
424211
public function escapeIdentifier(string $identifier): string
    {
        if ($identifier === '') {
            throw new \InvalidArgumentException('Identifier cannot be blank');
        }

        $escaper = function ($identifier) { return '`' . str_replace('`', '``', $identifier) . '`'; };
        $qualifiedIdentifiers = array_map($escaper, explode('.', $identifier));
        return implode('.', $qualifiedIdentifiers);
    }
26635
public function escape_table( &$query )
	{
		$table = $query->table;

		if ( is_array( $table ) )
		{
			reset($table); $table = key($table).' as '.$table[key($table)];
		}

		return $this->escape( $table );
	}
48966
public function addIdentifier($identifier)
    {
        if (!isset($this->identifiers[$identifier])) {
            $this->identifiers[$identifier] = $identifier;
        }

        return $this;
    }
381384
public static String quote(String identifier) {
        if (StringUtils.isEmpty(identifier)) {
            return identifier;
        }

        String res = identifier.trim();

        if (!res.startsWith("\"")) {
            res = "\"" + res;
        }

        if (!res.endsWith("\"")) {
            res = res + "\"";
        }

        return res;

    }
1051236
protected static function _identifier(AnServiceIdentifier $identifier)
    {
        $identifier = clone $identifier;

        if (!$identifier->name) {
            $identifier->name = AnInflector::singularize($identifier->package);
        }

        $identifier->type = 'com';
        $identifier->path = array('domain','entity');

        return $identifier;
    }
997142
public function identifier($identifier = null)
    {
        if (null === $identifier) {
            return $this->identifier;
        }

        $this->identifier = $identifier;
        return $this;
    }