vendor/propel/propel/src/Propel/Runtime/ActiveQuery/Criterion/LikeCriterion.php line 18

Open in your IDE?
  1. <?php
  2. /**
  3.  * MIT License. This file is part of the Propel package.
  4.  * For the full copyright and license information, please view the LICENSE
  5.  * file that was distributed with this source code.
  6.  */
  7. namespace Propel\Runtime\ActiveQuery\Criterion;
  8. use Propel\Runtime\ActiveQuery\Criteria;
  9. use Propel\Runtime\Adapter\Pdo\PgsqlAdapter;
  10. /**
  11.  * Specialized Criterion used for LIKE expressions
  12.  * e.g. table.column LIKE ? or table.column NOT LIKE ? (or ILIKE for Postgres)
  13.  */
  14. class LikeCriterion extends AbstractCriterion
  15. {
  16.     /**
  17.      * @var bool
  18.      */
  19.     protected $ignoreStringCase false;
  20.     /**
  21.      * Create a new instance.
  22.      *
  23.      * @param \Propel\Runtime\ActiveQuery\Criteria $outer The outer class (this is an "inner" class).
  24.      * @param string $column ignored
  25.      * @param string $value The condition to be added to the query string
  26.      * @param string $comparison One of Criteria::LIKE and Criteria::NOT_LIKE
  27.      */
  28.     public function __construct(Criteria $outer$column$value$comparison Criteria::LIKE)
  29.     {
  30.         parent::__construct($outer$column$value$comparison);
  31.     }
  32.     /**
  33.      * Sets ignore case.
  34.      *
  35.      * @param bool $b True if case should be ignored.
  36.      *
  37.      * @return $this A modified Criterion object.
  38.      */
  39.     public function setIgnoreCase($b)
  40.     {
  41.         $this->ignoreStringCase = (bool)$b;
  42.         return $this;
  43.     }
  44.     /**
  45.      * Is ignore case on or off?
  46.      *
  47.      * @return bool True if case is ignored.
  48.      */
  49.     public function isIgnoreCase()
  50.     {
  51.         return $this->ignoreStringCase;
  52.     }
  53.     /**
  54.      * Appends a Prepared Statement representation of the Criterion onto the buffer
  55.      *
  56.      * @param string $sb The string that will receive the Prepared Statement
  57.      * @param array $params A list to which Prepared Statement parameters will be appended
  58.      *
  59.      * @return void
  60.      */
  61.     protected function appendPsForUniqueClauseTo(&$sb, array &$params)
  62.     {
  63.         $field = ($this->table === null) ? $this->column $this->table '.' $this->column;
  64.         $db $this->getAdapter();
  65.         // If selection is case insensitive use ILIKE for PostgreSQL or SQL
  66.         // UPPER() function on column name for other databases.
  67.         if ($this->ignoreStringCase) {
  68.             if ($db instanceof PgsqlAdapter) {
  69.                 if ($this->comparison === Criteria::LIKE) {
  70.                     $this->comparison Criteria::ILIKE;
  71.                 } elseif ($this->comparison === Criteria::NOT_LIKE) {
  72.                     $this->comparison Criteria::NOT_ILIKE;
  73.                 }
  74.             } else {
  75.                 $field $db->ignoreCase($field);
  76.             }
  77.         }
  78.         $params[] = ['table' => $this->realtable'column' => $this->column'value' => $this->value];
  79.         $sb .= $field $this->comparison;
  80.         // If selection is case insensitive use SQL UPPER() function
  81.         // on criteria or, if Postgres we are using ILIKE, so not necessary.
  82.         if ($this->ignoreStringCase && !($db instanceof PgsqlAdapter)) {
  83.             $sb .= $db->ignoreCase(':p' count($params));
  84.         } else {
  85.             $sb .= ':p' count($params);
  86.         }
  87.     }
  88. }