Quotes given value with apostrophes or quotation marks

@param mixed $value         The value to quote
@param bool  $useApostrophe (optional) If is set to true, apostrophes are used. Otherwise - quotation marks.
@return string
425463
public static function quoteValue($value, $useApostrophe = true)
    {
        if (is_string($value)) {
            $quotes = '"';

            if ($useApostrophe) {
                $quotes = '\'';
            }

            $value = sprintf('%s%s%s', $quotes, $value, $quotes);
        }

        return $value;
    }
1329805
public function quoteValue($value)
    {
        if ($value === null) {
            return 'NULL';
        }

        if (is_numeric($value)) {
            return $value;
        }

        if ($value === false) {
            return 0;
        }

        if (empty($value)) {
            return '\'\'';
        }

        if (is_array($value)) {
            $values = array_unique($value);
            foreach ($values as $key => $value) {
                $values[$key] = $value === null ? 'NULL' : $this->_adapter->quoteValue($value);
            }

            return $values = implode(', ', $values);
        }

        return $this->_adapter->quoteValue($value);
    }
793598
protected static function highlightBacktickQuote($value)
    {
        if (self::is_cli()) {
            return self::$cli_backtick_quote . $value . "\x1b[0m";
        } else {
            return '<span ' . self::$backtick_quote_attributes . '>' . $value . '</span>';
        }
    }
145758
public function quote($value, $type = null): string
    {
        if (null === $value) {
            return 'NULL';
        }

        $resource = $this->getResource(); // forces connecting if not connected yet
        if (null !== $type) {
            return "'" . pg_escape_string($resource, $this->getTypeConverter($type)->output($value)) . "'";
        } else {
            return "'" . pg_escape_string(
                $resource,
                $this->getTypeConverterFactory()
                    ->getConverterForPHPValue($value)
                    ->output($value)
            ) . "'";
        }
    }
141402
public static function getCompleteUseStatement(string $useName, string $useAlias = null): string
    {
        $use = $useName;
        if (null !== $useAlias && $useAlias !== '') {
            $use .= ' as '.$useAlias;
        }

        return $use;
    }
447983
public final function quote($value, $paramType = \PDO::PARAM_STR)
    {
        //łączy jeśli niepołączony
        if (!$this->_connected) {
            $this->connect();
        }
        //dla szczególnych typów: null int i bool nie opakowuje
        switch (gettype($value)) {
            case 'NULL':
                return 'NULL';
            case 'integer':
                return intval($value);
            case 'boolean':
                return $value ? 'true' : 'false';
        }
        //quote z PDO
        return $this->_downstreamPdo->quote($value, $paramType);
    }
406340
public function asCode($value)
    {
        $topLevel = true;
        if (func_num_args() > 1 && false === func_get_arg(1)) {
            $topLevel = false;
        }

        $inlineList = false;
        if (func_num_args() > 2) {
            $inlineList = func_get_arg(2);
        }

        if ($value instanceof Annotation) {
            $value = (string) $value;
        } elseif (is_bool($value)) {
            $value = $value ? 'true' : 'false';
        } elseif (is_string($value)) {
            $value = '"'.$value.'"';
        } elseif (is_array($value)) {
            $tmp = array();
            $useKey = !$this->isKeysNumeric($value);
            foreach ($value as $k => $v) {
                // skip null value
                if (null === $v) {
                    continue;
                }
                $v = $this->asCode($v, false, true);
                if (false === $topLevel) {
                    $k = sprintf('"%s"', $k);
                }

                $tmp[] = $useKey ? sprintf("%s%s%s", $k, ($inlineList ? ':' : '='), $v) : $v;
            }
            $multiline = $this->getOption('multiline') && count($value) > 1;
            $value = implode($multiline ? ",\n" : ', ', $tmp).($multiline ? "\n" : '');
            if ($topLevel) {
                $value = sprintf('(%s)', $value);
            } else {
                $value = sprintf('{%s}', $value);
            }
            if ($multiline) {
                $value = $this->wrapLines($value, 1);
            }
        }

        return $value;
    }
717635
public static function quote($value, $empty = 'NULL')
    {
        if (is_array($value)) return '(' . join(', ', array_map(array(get_class(), 'quote'), $value)) . ')';

        if (is_null($value)) return $empty;
        if (is_bool($value)) return $value ? 'TRUE' : 'FALSE';
        if (is_int($value) || is_float($value)) return (string)$value;
        return '"' . strtr((string)$value, array('\\' => '\\\\', "\0" => '\\0', "\r" => '\\r', "\n" => '\\n', '"' => '\\"')) . '"';
    }
463223
function quote($value)
  {
    if ($value === null)
      return 'null';

    assert (!is_object($value));

    if (is_bool($value))
      return (int) $value;

    // Protect digit sequences beginning with '0' (eg phone numbers)
    if (is_string($value) && substr($value, 0,1) == "0")
     return "'".$this->real_escape_string($value)."'";

    if (is_numeric($value))
      return $value;

    // Create comma separated lists for arrays.
    if (is_array($value))
    {
      $res = [];
      foreach ($value as $v)
      {
        if (is_array($v))
          $res[] = "(".$this->quote($v).")";
        else
          $res[] = $this->quote($v);
      }
      return implode(",",$res);
    }

    return "'".$this->real_escape_string($value)."'";
  }
1080561
private static function requiresSingleQuoting(string $value): bool
	{
		// Determines if a PHP value is entirely composed of a value that would
		// require single quoting in YAML.
		if (\in_array(\strtolower($value), ['null', '~', 'true', 'false', 'y', 'n', 'yes', 'no', 'on', 'off'], true)) {
			return true;
		}

		// Determines if the PHP value contains any single characters that would
		// cause it to require single quoting in YAML.
		return \preg_match('/[ \s \' " \: \{ \} \[ \] , & \* \# \?] | \A[ \- ? | < > = ! % @ ` ]/x', $value);
	}
1207227
public function quoteIdentifier($value)
    {
        if ($value instanceof Expr) {
            return $value->getValue();
        }

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

        $pieces = explode('.', $value);

        foreach ($pieces as $key => $piece) {
            $pieces[$key] = '`'.$piece.'`';
        }

        return implode('.', $pieces);
    }
2610
public function getStatement($usePlaceholders = true)
    {
        $statement = "";
        if ($this->isSelect()) {
            $statement = $this->getSelectStatement($usePlaceholders);
        } elseif ($this->isInsert()) {
            $statement = $this->getInsertStatement($usePlaceholders);
        } elseif ($this->isReplace()) {
            $statement = $this->getReplaceStatement($usePlaceholders);
        } elseif ($this->isUpdate()) {
            $statement = $this->getUpdateStatement($usePlaceholders);
        } elseif ($this->isDelete()) {
            $statement = $this->getDeleteStatement($usePlaceholders);
        }
        return $statement;
    }
663029
private function getSanitisedValue($value)
    {
        if ($this->beginsWithQuote($value)) {

            $quote = $value[0];

            $regexPattern = sprintf(
                '/^
                %1$s          # match a quote at the start of the value
                (             # capturing sub-pattern used
                 (?:          # we do not need to capture this
                  [^%1$s\\\\] # any character other than a quote or backslash
                  |\\\\\\\\   # or two backslashes together
                  |\\\\%1$s   # or an escaped quote e.g \"
                 )*           # as many characters that match the previous rules
                )             # end of the capturing sub-pattern
                %1$s          # and the closing quote
                .*$           # and discard any string after the closing quote
                /mx',
                $quote
            );

            $value = preg_replace($regexPattern, '$1', $value);
            $value = str_replace("\\$quote", $quote, $value);
            $value = str_replace('\\\\', '\\', $value);

            return $value;
        }

        $parts = explode(' #', $value, 2);
        $value = trim($parts[0]);

        if (preg_match('/\s+/', $value) > 0) {
            throw new InvalidArgumentException('DotEnv values containing spaces must be surrounded by quotes.');
        }

        return $value;
    }
492159
public function _quote($str)
	{
		// Check that the current value is a string,
		// and is not already quoted before quoting
		// that value, otherwise, return the original value
		return (
			\is_string($str)
			&& strpos($str, $this->escapeCharOpen) !== 0
			&& strrpos($str, $this->escapeCharClose) !== 0
		)
			? "{$this->escapeCharOpen}{$str}{$this->escapeCharClose}"
			: $str;

	}
154072
private function getInsertStatement($usePlaceholders = true)
    {
        $statement = "";

        if (!$this->isInsert()) {
            return $statement;
        }

        $statement .= $this->getInsertString();

        if ($this->isInto) {
            $statement .= " " . $this->getIntoString($usePlaceholders);
        } else {
            if ($this->set) {
                $statement .= " " . $this->getSetString($usePlaceholders);
            }
        }
        return $statement;
    }
249468
public function quoteIfNecessary($value)
    {
        if ($this->isNumber($value) || $this->isPlaceholder($value)) {
            return $value;
        }

        return $this->quote($value);
    }
226860
protected function _quoteIdentifier($value, $auto=false)
    {
        if ($auto === false || $this->_autoQuoteIdentifiers === true) {
            $q = $this->getQuoteIdentifierSymbol();
            return ($q . str_replace("$q", "$q$q", $value) . $q);
        }
        return $value;
    }