This file is indexed.

/usr/share/php/propel/query/ModelCriterion.php is in php-propel-runtime 1.6.9-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
<?php

/**
 * This file is part of the Propel package.
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @license    MIT License
 */

/**
 * This is an "inner" class that describes an object in the criteria.
 *
 * @author     Francois
 * @version    $Revision$
 * @package    propel.runtime.query
 */
class ModelCriterion extends Criterion
{
    protected $clause = '';

    /**
     * Create a new instance.
     *
     * @param Criteria  $parent      The outer class (this is an "inner" class).
     * @param ColumnMap $column      A Column object to help escaping the value
     * @param mixed     $value
     * @param string    $comparison, among ModelCriteria::MODEL_CLAUSE
     * @param string    $clause      A simple pseudo-SQL clause, e.g. 'foo.BAR LIKE ?'
     */
    public function __construct(Criteria $outer, $column, $value = null, $comparison = ModelCriteria::MODEL_CLAUSE, $clause, $type = null)
    {
        $this->value = $value;
        if ($column instanceof ColumnMap) {
            $this->column = $column->getName();
            $this->table = $column->getTable()->getName();
        } else {
            $dotPos = strrpos($column,'.');
            if ($dotPos === false) {
                // no dot => aliased column
                $this->table = null;
                $this->column = $column;
            } else {
                $this->table = substr($column, 0, $dotPos);
                $this->column = substr($column, $dotPos+1, strlen($column));
            }
        }
        $this->comparison = ($comparison === null ? Criteria::EQUAL : $comparison);
        $this->clause = $clause;
        $this->type = $type;
        $this->init($outer);
    }

    public function getClause()
    {
        return $this->clause;
    }

    /**
     * Figure out which MocelCriterion method to use
     * to build the prepared statement and parameters using to the Criterion comparison
     * and call it to append the prepared statement and the parameters of the current clause.
     * For performance reasons, this method tests the cases of parent::dispatchPsHandling()
     * first, and that is not possible through inheritance ; that's why the parent
     * code is duplicated here.
     *
     * @param      string &$sb The string that will receive the Prepared Statement
     * @param array $params A list to which Prepared Statement parameters will be appended
     */
    protected function dispatchPsHandling(&$sb, array &$params)
    {
        switch ($this->comparison) {
            case Criteria::CUSTOM:
                // custom expression with no parameter binding
                $this->appendCustomToPs($sb, $params);
                break;
            case Criteria::IN:
            case Criteria::NOT_IN:
                // table.column IN (?, ?) or table.column NOT IN (?, ?)
                $this->appendInToPs($sb, $params);
                break;
            case Criteria::LIKE:
            case Criteria::NOT_LIKE:
            case Criteria::ILIKE:
            case Criteria::NOT_ILIKE:
                // table.column LIKE ? or table.column NOT LIKE ?  (or ILIKE for Postgres)
                $this->appendLikeToPs($sb, $params);
                break;
            case ModelCriteria::MODEL_CLAUSE:
                // regular model clause, e.g. 'book.TITLE = ?'
                $this->appendModelClauseToPs($sb, $params);
                break;
            case ModelCriteria::MODEL_CLAUSE_LIKE:
                // regular model clause, e.g. 'book.TITLE = ?'
                $this->appendModelClauseLikeToPs($sb, $params);
                break;
            case ModelCriteria::MODEL_CLAUSE_SEVERAL:
                // Ternary model clause, e.G 'book.ID BETWEEN ? AND ?'
                $this->appendModelClauseSeveralToPs($sb, $params);
                break;
            case ModelCriteria::MODEL_CLAUSE_ARRAY:
                // IN or NOT IN model clause, e.g. 'book.TITLE NOT IN ?'
                $this->appendModelClauseArrayToPs($sb, $params);
                break;
            case ModelCriteria::MODEL_CLAUSE_RAW:
                // raw model clause, with type, e.g. 'foobar = ?'
                $this->appendModelClauseRawToPs($sb, $params);
                break;
            default:
                // table.column = ? or table.column >= ? etc. (traditional expressions, the default)
                $this->appendBasicToPs($sb, $params);

        }
    }

    /**
     * Appends a Prepared Statement representation of the ModelCriterion onto the buffer
     * For regular model clauses, e.g. 'book.TITLE = ?'
     *
     * @param      string &$sb The string that will receive the Prepared Statement
     * @param array $params A list to which Prepared Statement parameters will be appended
     */
    public function appendModelClauseToPs(&$sb, array &$params)
    {
        if ($this->value !== null) {
            $params[] = array('table' => $this->realtable, 'column' => $this->column, 'value' => $this->value);
            $sb .= str_replace('?', ':p'.count($params), $this->clause);
        } else {
            $sb .= $this->clause;
        }
    }

    /**
     * Appends a Prepared Statement representation of the ModelCriterion onto the buffer
     * For LIKE model clauses, e.g. 'book.TITLE LIKE ?'
     * Handles case insensitivity for VARCHAR columns
     *
     * @param      string &$sb The string that will receive the Prepared Statement
     * @param array $params A list to which Prepared Statement parameters will be appended
     */
    public function appendModelClauseLikeToPs(&$sb, array &$params)
    {
        // LIKE is case insensitive in mySQL and SQLite, but not in PostGres
        // If the column is case insensitive, use ILIKE / NOT ILIKE instead of LIKE / NOT LIKE
        if ($this->ignoreStringCase && $this->getDb() instanceof DBPostgres) {
            $this->clause = preg_replace('/LIKE \?$/i', 'ILIKE ?', $this->clause);
        }
        $this->appendModelClauseToPs($sb, $params);
    }

    /**
     * Appends a Prepared Statement representation of the ModelCriterion onto the buffer
     * For ternary model clauses, e.G 'book.ID BETWEEN ? AND ?'
     *
     * @param      string &$sb The string that will receive the Prepared Statement
     * @param array $params A list to which Prepared Statement parameters will be appended
     *
     * @throws PropelException
     */
    public function appendModelClauseSeveralToPs(&$sb, array &$params)
    {
        $clause = $this->clause;
        foreach ((array) $this->value as $value) {
            if ($value === null) {
                // FIXME we eventually need to translate a BETWEEN to
                // something like WHERE (col < :p1 OR :p1 IS NULL) AND (col < :p2 OR :p2 IS NULL)
                // in order to support null values
                throw new PropelException('Null values are not supported inside BETWEEN clauses');
            }
            $params[] = array('table' => $this->realtable, 'column' => $this->column, 'value' => $value);
            $clause = self::strReplaceOnce('?', ':p'.count($params), $clause);
        }
        $sb .= $clause;
    }

    /**
     * Appends a Prepared Statement representation of the ModelCriterion onto the buffer
     * For IN or NOT IN model clauses, e.g. 'book.TITLE NOT IN ?'
     *
     * @param      string &$sb The string that will receive the Prepared Statement
     * @param array $params A list to which Prepared Statement parameters will be appended
     */
    public function appendModelClauseArrayToPs(&$sb, array &$params)
    {
        $_bindParams = array(); // the param names used in query building
        $_idxstart = count($params);
        $valuesLength = 0;
        foreach ( (array) $this->value as $value ) {
            $valuesLength++; // increment this first to correct for wanting bind params to start with :p1
            $params[] = array('table' => $this->realtable, 'column' => $this->column, 'value' => $value);
            $_bindParams[] = ':p'.($_idxstart + $valuesLength);
        }
        if ($valuesLength !== 0) {
            $sb .= str_replace('?', '(' . implode(',', $_bindParams) . ')', $this->clause);
        } else {
            $sb .= (stripos($this->clause, ' NOT IN ') === false) ? "1<>1" : "1=1";
        }
        unset ( $value, $valuesLength );
    }

    /**
     * Appends a Prepared Statement representation of the Criterion onto the buffer
     * For custom expressions with a typed binding, e.g. 'foobar = ?'
     *
     * @param      string &$sb The string that will receive the Prepared Statement
     * @param array $params A list to which Prepared Statement parameters will be appended
     *
     * @throws PropelException
     */
    protected function appendModelClauseRawToPs(&$sb, array &$params)
    {
        if (substr_count($this->clause, '?') != 1) {
            throw new PropelException(sprintf('Could not build SQL for expression "%s" because Criteria::RAW works only with a clause containing a single question mark placeholder', $this->column));
        }
        $params[] = array('table' => null, 'type' => $this->type, 'value' => $this->value);
        $sb .= str_replace('?', ':p' . count($params), $this->clause);
    }

    /**
     * This method checks another Criteria to see if they contain
     * the same attributes and hashtable entries.
     * @return boolean
     */
    public function equals($obj)
    {
        // TODO: optimize me with early outs
        if ($this === $obj) {
            return true;
        }

        if (($obj === null) || !($obj instanceof ModelCriterion)) {
            return false;
        }

        $crit = $obj;

        $isEquiv = ( ( ($this->table === null && $crit->getTable() === null)
            || ( $this->table !== null && $this->table === $crit->getTable() )
                          )
            && $this->clause === $crit->getClause()
            && $this->column === $crit->getColumn()
            && $this->comparison === $crit->getComparison());

        // check chained criterion

        $clausesLength = count($this->clauses);
        $isEquiv &= (count($crit->getClauses()) == $clausesLength);
        $critConjunctions = $crit->getConjunctions();
        $critClauses = $crit->getClauses();
        for ($i=0; $i < $clausesLength && $isEquiv; $i++) {
            $isEquiv &= ($this->conjunctions[$i] === $critConjunctions[$i]);
            $isEquiv &= ($this->clauses[$i] === $critClauses[$i]);
        }

        if ($isEquiv) {
            $isEquiv &= $this->value === $crit->getValue();
        }

        return $isEquiv;
    }

    /**
     * Returns a hash code value for the object.
     */
    public function hashCode()
    {
        $h = crc32(serialize($this->value)) ^ crc32($this->comparison) ^ crc32($this->clause);

        if ($this->table !== null) {
            $h ^= crc32($this->table);
        }

        if ($this->column !== null) {
            $h ^= crc32($this->column);
        }

        foreach ($this->clauses as $clause) {
            // TODO: i KNOW there is a php incompatibility with the following line
            // but i dont remember what it is, someone care to look it up and
            // replace it if it doesnt bother us?
            // $clause->appendPsTo($sb='',$params=array());
            $sb = '';
            $params = array();
            $clause->appendPsTo($sb,$params);
            $h ^= crc32(serialize(array($sb,$params)));
            unset ( $sb, $params );
        }

        return $h;
    }

    /**
     * Replace only once
     * taken from http://www.php.net/manual/en/function.str-replace.php
     *
     */
    protected static function strReplaceOnce($search, $replace, $subject)
    {
        $firstChar = strpos($subject, $search);
        if ($firstChar !== false) {
            $beforeStr = substr($subject,0,$firstChar);
            $afterStr = substr($subject, $firstChar + strlen($search));

            return $beforeStr.$replace.$afterStr;
        } else {
            return $subject;
        }
    }
}