芝麻web文件管理V1.00
编辑当前文件:/home2/sdektunc/airport-back/vendor/yiisoft/yii2/db/conditions/LikeConditionBuilder.php
* @since 2.0.14 */ class LikeConditionBuilder implements ExpressionBuilderInterface { use ExpressionBuilderTrait; /** * @var array map of chars to their replacements in LIKE conditions. * By default it's configured to escape `%`, `_` and `\` with `\`. */ protected $escapingReplacements = [ '%' => '\%', '_' => '\_', '\\' => '\\\\', ]; /** * @var string|null character used to escape special characters in LIKE conditions. * By default it's assumed to be `\`. */ protected $escapeCharacter; /** * Method builds the raw SQL from the $expression that will not be additionally * escaped or quoted. * * @param ExpressionInterface|LikeCondition $expression the expression to be built. * @param array $params the binding parameters. * @return string the raw SQL that will not be additionally escaped or quoted. */ public function build(ExpressionInterface $expression, array &$params = []) { $operator = strtoupper($expression->getOperator()); $column = $expression->getColumn(); $values = $expression->getValue(); $escape = $expression->getEscapingReplacements(); if ($escape === null || $escape === []) { $escape = $this->escapingReplacements; } list($andor, $not, $operator) = $this->parseOperator($operator); if (!is_array($values)) { $values = [$values]; } if (empty($values)) { return $not ? '' : '0=1'; } if ($column instanceof ExpressionInterface) { $column = $this->queryBuilder->buildExpression($column, $params); } elseif (is_string($column) && strpos($column, '(') === false) { $column = $this->queryBuilder->db->quoteColumnName($column); } $escapeSql = $this->getEscapeSql(); $parts = []; foreach ($values as $value) { if ($value instanceof ExpressionInterface) { $phName = $this->queryBuilder->buildExpression($value, $params); } else { $phName = $this->queryBuilder->bindParam(empty($escape) ? $value : ('%' . strtr((string)$value, $escape) . '%'), $params); } $parts[] = "{$column} {$operator} {$phName}{$escapeSql}"; } return implode($andor, $parts); } /** * @return string */ private function getEscapeSql() { if ($this->escapeCharacter !== null) { return " ESCAPE '{$this->escapeCharacter}'"; } return ''; } /** * @param string $operator * @return array */ protected function parseOperator($operator) { if (!preg_match('/^(AND |OR |)(((NOT |))I?LIKE)/', $operator, $matches)) { throw new InvalidArgumentException("Invalid operator '$operator'."); } $andor = ' ' . (!empty($matches[1]) ? $matches[1] : 'AND '); $not = !empty($matches[3]); $operator = $matches[2]; return [$andor, $not, $operator]; } }