Complex classes like DataQuery often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use DataQuery, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 14 | class DataQuery { |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var string |
||
| 18 | */ |
||
| 19 | protected $dataClass; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var SQLSelect |
||
| 23 | */ |
||
| 24 | protected $query; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Map of all field names to an array of conflicting column SQL |
||
| 28 | * |
||
| 29 | * E.g. |
||
| 30 | * array( |
||
| 31 | * 'Title' => array( |
||
| 32 | * '"MyTable"."Title"', |
||
| 33 | * '"AnotherTable"."Title"', |
||
| 34 | * ) |
||
| 35 | * ) |
||
| 36 | * |
||
| 37 | * @var array |
||
| 38 | */ |
||
| 39 | protected $collidingFields = array(); |
||
| 40 | |||
| 41 | private $queriedColumns = null; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var bool |
||
| 45 | */ |
||
| 46 | private $queryFinalised = false; |
||
| 47 | |||
| 48 | // TODO: replace subclass_access with this |
||
| 49 | protected $querySubclasses = true; |
||
| 50 | // TODO: replace restrictclasses with this |
||
| 51 | protected $filterByClassName = true; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Create a new DataQuery. |
||
| 55 | * |
||
| 56 | * @param string $dataClass The name of the DataObject class that you wish to query |
||
| 57 | */ |
||
| 58 | public function __construct($dataClass) { |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Clone this object |
||
| 65 | */ |
||
| 66 | public function __clone() { |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Return the {@link DataObject} class that is being queried. |
||
| 72 | * |
||
| 73 | * @return string |
||
| 74 | */ |
||
| 75 | public function dataClass() { |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Return the {@link SQLSelect} object that represents the current query; note that it will |
||
| 81 | * be a clone of the object. |
||
| 82 | * |
||
| 83 | * @return SQLSelect |
||
| 84 | */ |
||
| 85 | public function query() { |
||
| 88 | |||
| 89 | |||
| 90 | /** |
||
| 91 | * Remove a filter from the query |
||
| 92 | * |
||
| 93 | * @param string|array $fieldExpression The predicate of the condition to remove |
||
| 94 | * (ignoring parameters). The expression will be considered a match if it's |
||
| 95 | * contained within any other predicate. |
||
| 96 | * @return DataQuery Self reference |
||
| 97 | */ |
||
| 98 | public function removeFilterOn($fieldExpression) { |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Set up the simplest initial query |
||
| 142 | */ |
||
| 143 | protected function initialiseQuery() { |
||
| 164 | |||
| 165 | public function setQueriedColumns($queriedColumns) { |
||
| 168 | |||
| 169 | /** |
||
| 170 | * Ensure that the query is ready to execute. |
||
| 171 | * |
||
| 172 | * @param array|null $queriedColumns Any columns to filter the query by |
||
| 173 | * @return SQLSelect The finalised sql query |
||
| 174 | */ |
||
| 175 | public function getFinalisedQuery($queriedColumns = null) { |
||
| 176 | if(!$queriedColumns) { |
||
| 177 | $queriedColumns = $this->queriedColumns; |
||
| 178 | } |
||
| 179 | if($queriedColumns) { |
||
| 180 | $queriedColumns = array_merge($queriedColumns, array('Created', 'LastEdited', 'ClassName')); |
||
| 181 | } |
||
| 182 | |||
| 183 | $schema = DataObject::getSchema(); |
||
| 184 | $query = clone $this->query; |
||
| 185 | $baseDataClass = $schema->baseDataClass($this->dataClass()); |
||
| 186 | $baseIDColumn = $schema->sqlColumnForField($baseDataClass, 'ID'); |
||
| 187 | $ancestorClasses = ClassInfo::ancestry($this->dataClass(), true); |
||
| 188 | |||
| 189 | // Generate the list of tables to iterate over and the list of columns required |
||
| 190 | // by any existing where clauses. This second step is skipped if we're fetching |
||
| 191 | // the whole dataobject as any required columns will get selected regardless. |
||
| 192 | if($queriedColumns) { |
||
| 193 | // Specifying certain columns allows joining of child tables |
||
| 194 | $tableClasses = ClassInfo::dataClassesFor($this->dataClass); |
||
| 195 | |||
| 196 | // Ensure that any filtered columns are included in the selected columns |
||
| 197 | foreach ($query->getWhereParameterised($parameters) as $where) { |
||
| 198 | // Check for any columns in the form '"Column" = ?' or '"Table"."Column"' = ? |
||
| 199 | if(preg_match_all( |
||
| 200 | '/(?:"(?<table>[^"]+)"\.)?"(?<column>[^"]+)"(?:[^\.]|$)/', |
||
| 201 | $where, $matches, PREG_SET_ORDER |
||
| 202 | )) { |
||
| 203 | foreach($matches as $match) { |
||
| 204 | $column = $match['column']; |
||
| 205 | if (!in_array($column, $queriedColumns)) { |
||
| 206 | $queriedColumns[] = $column; |
||
| 207 | } |
||
| 208 | } |
||
| 209 | } |
||
| 210 | } |
||
| 211 | } else { |
||
| 212 | $tableClasses = $ancestorClasses; |
||
| 213 | } |
||
| 214 | |||
| 215 | // Iterate over the tables and check what we need to select from them. If any selects are made (or the table is |
||
| 216 | // required for a select) |
||
| 217 | foreach($tableClasses as $tableClass) { |
||
| 218 | |||
| 219 | // Determine explicit columns to select |
||
| 220 | $selectColumns = null; |
||
| 221 | if ($queriedColumns) { |
||
| 222 | // Restrict queried columns to that on the selected table |
||
| 223 | $tableFields = DataObject::database_fields($tableClass); |
||
| 224 | unset($tableFields['ID']); |
||
| 225 | $selectColumns = array_intersect($queriedColumns, array_keys($tableFields)); |
||
| 226 | } |
||
| 227 | |||
| 228 | // If this is a subclass without any explicitly requested columns, omit this from the query |
||
| 229 | if(!in_array($tableClass, $ancestorClasses) && empty($selectColumns)) { |
||
| 230 | continue; |
||
| 231 | } |
||
| 232 | |||
| 233 | // Select necessary columns (unless an explicitly empty array) |
||
| 234 | if($selectColumns !== array()) { |
||
| 235 | $this->selectColumnsFromTable($query, $tableClass, $selectColumns); |
||
| 236 | } |
||
| 237 | |||
| 238 | // Join if not the base table |
||
| 239 | if($tableClass !== $baseDataClass) { |
||
| 240 | $tableName = $schema->tableName($tableClass); |
||
| 241 | $query->addLeftJoin( |
||
| 242 | $tableName, |
||
| 243 | "\"{$tableName}\".\"ID\" = {$baseIDColumn}", |
||
| 244 | $tableName, |
||
| 245 | 10 |
||
| 246 | ); |
||
| 247 | } |
||
| 248 | } |
||
| 249 | |||
| 250 | // Resolve colliding fields |
||
| 251 | if($this->collidingFields) { |
||
|
|
|||
| 252 | foreach($this->collidingFields as $collisionField => $collisions) { |
||
| 253 | $caseClauses = array(); |
||
| 254 | foreach($collisions as $collision) { |
||
| 255 | if(preg_match('/^"(?<table>[^"]+)"\./', $collision, $matches)) { |
||
| 256 | $collisionTable = $matches['table']; |
||
| 257 | $collisionClass = $schema->tableClass($collisionTable); |
||
| 258 | if($collisionClass) { |
||
| 259 | $collisionClassColumn = $schema->sqlColumnForField($collisionClass, 'ClassName'); |
||
| 260 | $collisionClasses = ClassInfo::subclassesFor($collisionClass); |
||
| 261 | $collisionClassesSQL = implode(', ', Convert::raw2sql($collisionClasses, true)); |
||
| 262 | $caseClauses[] = "WHEN {$collisionClassColumn} IN ({$collisionClassesSQL}) THEN $collision"; |
||
| 263 | } |
||
| 264 | } else { |
||
| 265 | user_error("Bad collision item '$collision'", E_USER_WARNING); |
||
| 266 | } |
||
| 267 | } |
||
| 268 | $query->selectField("CASE " . implode( " ", $caseClauses) . " ELSE NULL END", $collisionField); |
||
| 269 | } |
||
| 270 | } |
||
| 271 | |||
| 272 | |||
| 273 | if($this->filterByClassName) { |
||
| 274 | // If querying the base class, don't bother filtering on class name |
||
| 275 | if($this->dataClass != $baseDataClass) { |
||
| 276 | // Get the ClassName values to filter to |
||
| 277 | $classNames = ClassInfo::subclassesFor($this->dataClass); |
||
| 278 | $classNamesPlaceholders = DB::placeholders($classNames); |
||
| 279 | $baseClassColumn = $schema->sqlColumnForField($baseDataClass, 'ClassName'); |
||
| 280 | $query->addWhere(array( |
||
| 281 | "{$baseClassColumn} IN ($classNamesPlaceholders)" => $classNames |
||
| 282 | )); |
||
| 283 | } |
||
| 284 | } |
||
| 285 | |||
| 286 | // Select ID |
||
| 287 | $query->selectField($baseIDColumn, "ID"); |
||
| 288 | |||
| 289 | // Select RecordClassName |
||
| 290 | $baseClassColumn = $schema->sqlColumnForField($baseDataClass, 'ClassName'); |
||
| 291 | $query->selectField(" |
||
| 292 | CASE WHEN {$baseClassColumn} IS NOT NULL THEN {$baseClassColumn} |
||
| 293 | ELSE ".Convert::raw2sql($baseDataClass, true)." END", |
||
| 294 | "RecordClassName" |
||
| 295 | ); |
||
| 296 | |||
| 297 | // TODO: Versioned, Translatable, SiteTreeSubsites, etc, could probably be better implemented as subclasses |
||
| 298 | // of DataQuery |
||
| 299 | |||
| 300 | $obj = Injector::inst()->get($this->dataClass); |
||
| 301 | $obj->extend('augmentSQL', $query, $this); |
||
| 302 | |||
| 303 | $this->ensureSelectContainsOrderbyColumns($query); |
||
| 304 | |||
| 305 | return $query; |
||
| 306 | } |
||
| 307 | |||
| 308 | /** |
||
| 309 | * Ensure that if a query has an order by clause, those columns are present in the select. |
||
| 310 | * |
||
| 311 | * @param SQLSelect $query |
||
| 312 | * @param array $originalSelect |
||
| 313 | * @return null |
||
| 314 | */ |
||
| 315 | protected function ensureSelectContainsOrderbyColumns($query, $originalSelect = array()) { |
||
| 375 | |||
| 376 | /** |
||
| 377 | * Execute the query and return the result as {@link SS_Query} object. |
||
| 378 | * |
||
| 379 | * @return SS_Query |
||
| 380 | */ |
||
| 381 | public function execute() { |
||
| 384 | |||
| 385 | /** |
||
| 386 | * Return this query's SQL |
||
| 387 | * |
||
| 388 | * @param array $parameters Out variable for parameters required for this query |
||
| 389 | * @return string The resulting SQL query (may be paramaterised) |
||
| 390 | */ |
||
| 391 | public function sql(&$parameters = array()) { |
||
| 394 | |||
| 395 | /** |
||
| 396 | * Return the number of records in this query. |
||
| 397 | * Note that this will issue a separate SELECT COUNT() query. |
||
| 398 | * |
||
| 399 | * @return int |
||
| 400 | */ |
||
| 401 | public function count() { |
||
| 405 | |||
| 406 | /** |
||
| 407 | * Return the maximum value of the given field in this DataList |
||
| 408 | * |
||
| 409 | * @param String $field Unquoted database column name. Will be ANSI quoted |
||
| 410 | * automatically so must not contain double quotes. |
||
| 411 | * @return string |
||
| 412 | */ |
||
| 413 | public function max($field) { |
||
| 416 | |||
| 417 | /** |
||
| 418 | * Return the minimum value of the given field in this DataList |
||
| 419 | * |
||
| 420 | * @param string $field Unquoted database column name. Will be ANSI quoted |
||
| 421 | * automatically so must not contain double quotes. |
||
| 422 | * @return string |
||
| 423 | */ |
||
| 424 | public function min($field) { |
||
| 427 | |||
| 428 | /** |
||
| 429 | * Return the average value of the given field in this DataList |
||
| 430 | * |
||
| 431 | * @param string $field Unquoted database column name. Will be ANSI quoted |
||
| 432 | * automatically so must not contain double quotes. |
||
| 433 | * @return string |
||
| 434 | */ |
||
| 435 | public function avg($field) { |
||
| 438 | |||
| 439 | /** |
||
| 440 | * Return the sum of the values of the given field in this DataList |
||
| 441 | * |
||
| 442 | * @param string $field Unquoted database column name. Will be ANSI quoted |
||
| 443 | * automatically so must not contain double quotes. |
||
| 444 | * @return string |
||
| 445 | */ |
||
| 446 | public function sum($field) { |
||
| 449 | |||
| 450 | /** |
||
| 451 | * Runs a raw aggregate expression. Please handle escaping yourself |
||
| 452 | * |
||
| 453 | * @param string $expression An aggregate expression, such as 'MAX("Balance")', or a set of them |
||
| 454 | * (as an escaped SQL statement) |
||
| 455 | * @return string |
||
| 456 | */ |
||
| 457 | public function aggregate($expression) { |
||
| 460 | |||
| 461 | /** |
||
| 462 | * Return the first row that would be returned by this full DataQuery |
||
| 463 | * Note that this will issue a separate SELECT ... LIMIT 1 query. |
||
| 464 | */ |
||
| 465 | public function firstRow() { |
||
| 468 | |||
| 469 | /** |
||
| 470 | * Return the last row that would be returned by this full DataQuery |
||
| 471 | * Note that this will issue a separate SELECT ... LIMIT query. |
||
| 472 | */ |
||
| 473 | public function lastRow() { |
||
| 476 | |||
| 477 | /** |
||
| 478 | * Update the SELECT clause of the query with the columns from the given table |
||
| 479 | * |
||
| 480 | * @param SQLSelect $query |
||
| 481 | * @param string $tableClass Class to select from |
||
| 482 | * @param array $columns |
||
| 483 | */ |
||
| 484 | protected function selectColumnsFromTable(SQLSelect &$query, $tableClass, $columns = null) { |
||
| 513 | |||
| 514 | /** |
||
| 515 | * Append a GROUP BY clause to this query. |
||
| 516 | * |
||
| 517 | * @param string $groupby Escaped SQL statement |
||
| 518 | * @return $this |
||
| 519 | */ |
||
| 520 | public function groupby($groupby) { |
||
| 524 | |||
| 525 | /** |
||
| 526 | * Append a HAVING clause to this query. |
||
| 527 | * |
||
| 528 | * @param string $having Escaped SQL statement |
||
| 529 | * @return $this |
||
| 530 | */ |
||
| 531 | public function having($having) { |
||
| 535 | |||
| 536 | /** |
||
| 537 | * Create a disjunctive subgroup. |
||
| 538 | * |
||
| 539 | * That is a subgroup joined by OR |
||
| 540 | * |
||
| 541 | * @return DataQuery_SubGroup |
||
| 542 | */ |
||
| 543 | public function disjunctiveGroup() { |
||
| 546 | |||
| 547 | /** |
||
| 548 | * Create a conjunctive subgroup |
||
| 549 | * |
||
| 550 | * That is a subgroup joined by AND |
||
| 551 | * |
||
| 552 | * @return DataQuery_SubGroup |
||
| 553 | */ |
||
| 554 | public function conjunctiveGroup() { |
||
| 557 | |||
| 558 | /** |
||
| 559 | * Adds a WHERE clause. |
||
| 560 | * |
||
| 561 | * @see SQLSelect::addWhere() for syntax examples, although DataQuery |
||
| 562 | * won't expand multiple arguments as SQLSelect does. |
||
| 563 | * |
||
| 564 | * @param string|array|SQLConditionGroup $filter Predicate(s) to set, as escaped SQL statements or |
||
| 565 | * paramaterised queries |
||
| 566 | * @return DataQuery |
||
| 567 | */ |
||
| 568 | public function where($filter) { |
||
| 574 | |||
| 575 | /** |
||
| 576 | * Append a WHERE with OR. |
||
| 577 | * |
||
| 578 | * @see SQLSelect::addWhere() for syntax examples, although DataQuery |
||
| 579 | * won't expand multiple method arguments as SQLSelect does. |
||
| 580 | * |
||
| 581 | * @param string|array|SQLConditionGroup $filter Predicate(s) to set, as escaped SQL statements or |
||
| 582 | * paramaterised queries |
||
| 583 | * @return DataQuery |
||
| 584 | */ |
||
| 585 | public function whereAny($filter) { |
||
| 591 | |||
| 592 | /** |
||
| 593 | * Set the ORDER BY clause of this query |
||
| 594 | * |
||
| 595 | * @see SQLSelect::orderby() |
||
| 596 | * |
||
| 597 | * @param String $sort Column to sort on (escaped SQL statement) |
||
| 598 | * @param String $direction Direction ("ASC" or "DESC", escaped SQL statement) |
||
| 599 | * @param Boolean $clear Clear existing values |
||
| 600 | * @return DataQuery |
||
| 601 | */ |
||
| 602 | public function sort($sort = null, $direction = null, $clear = true) { |
||
| 611 | |||
| 612 | /** |
||
| 613 | * Reverse order by clause |
||
| 614 | * |
||
| 615 | * @return DataQuery |
||
| 616 | */ |
||
| 617 | public function reverseSort() { |
||
| 621 | |||
| 622 | /** |
||
| 623 | * Set the limit of this query. |
||
| 624 | * |
||
| 625 | * @param int $limit |
||
| 626 | * @param int $offset |
||
| 627 | * @return $this |
||
| 628 | */ |
||
| 629 | public function limit($limit, $offset = 0) { |
||
| 633 | |||
| 634 | /** |
||
| 635 | * Set whether this query should be distinct or not. |
||
| 636 | * |
||
| 637 | * @param bool $value |
||
| 638 | * @return DataQuery |
||
| 639 | */ |
||
| 640 | public function distinct($value) { |
||
| 644 | |||
| 645 | /** |
||
| 646 | * Add an INNER JOIN clause to this query. |
||
| 647 | * |
||
| 648 | * @param String $table The unquoted table name to join to. |
||
| 649 | * @param String $onClause The filter for the join (escaped SQL statement) |
||
| 650 | * @param String $alias An optional alias name (unquoted) |
||
| 651 | * @param int $order A numerical index to control the order that joins are added to the query; lower order values |
||
| 652 | * will cause the query to appear first. The default is 20, and joins created automatically by the |
||
| 653 | * ORM have a value of 10. |
||
| 654 | * @param array $parameters Any additional parameters if the join is a parameterised subquery |
||
| 655 | * @return $this |
||
| 656 | */ |
||
| 657 | public function innerJoin($table, $onClause, $alias = null, $order = 20, $parameters = array()) { |
||
| 663 | |||
| 664 | /** |
||
| 665 | * Add a LEFT JOIN clause to this query. |
||
| 666 | * |
||
| 667 | * @param string $table The unquoted table to join to. |
||
| 668 | * @param string $onClause The filter for the join (escaped SQL statement). |
||
| 669 | * @param string $alias An optional alias name (unquoted) |
||
| 670 | * @param int $order A numerical index to control the order that joins are added to the query; lower order values |
||
| 671 | * will cause the query to appear first. The default is 20, and joins created automatically by the |
||
| 672 | * ORM have a value of 10. |
||
| 673 | * @param array $parameters Any additional parameters if the join is a parameterised subquery |
||
| 674 | * @return $this |
||
| 675 | */ |
||
| 676 | public function leftJoin($table, $onClause, $alias = null, $order = 20, $parameters = array()) { |
||
| 682 | |||
| 683 | /** |
||
| 684 | * Traverse the relationship fields, and add the table |
||
| 685 | * mappings to the query object state. This has to be called |
||
| 686 | * in any overloaded {@link SearchFilter->apply()} methods manually. |
||
| 687 | * |
||
| 688 | * @param string|array $relation The array/dot-syntax relation to follow |
||
| 689 | * @param bool $linearOnly Set to true to restrict to linear relations only. Set this |
||
| 690 | * if this relation will be used for sorting, and should not include duplicate rows. |
||
| 691 | * @return string The model class of the related item |
||
| 692 | */ |
||
| 693 | public function applyRelation($relation, $linearOnly = false) { |
||
| 740 | |||
| 741 | /** |
||
| 742 | * Join the given class to this query with the given key |
||
| 743 | * |
||
| 744 | * @param string $localClass Name of class that has the has_one to the joined class |
||
| 745 | * @param string $localField Name of the has_one relationship to joi |
||
| 746 | * @param string $foreignClass Class to join |
||
| 747 | */ |
||
| 748 | protected function joinHasOneRelation($localClass, $localField, $foreignClass) |
||
| 788 | |||
| 789 | /** |
||
| 790 | * Join the given has_many relation to this query. |
||
| 791 | * |
||
| 792 | * Doesn't work with polymorphic relationships |
||
| 793 | * |
||
| 794 | * @param string $localClass Name of class that has the has_many to the joined class |
||
| 795 | * @param string $localField Name of the has_many relationship to join |
||
| 796 | * @param string $foreignClass Class to join |
||
| 797 | */ |
||
| 798 | protected function joinHasManyRelation($localClass, $localField, $foreignClass) { |
||
| 841 | |||
| 842 | /** |
||
| 843 | * Join table via many_many relationship |
||
| 844 | * |
||
| 845 | * @param string $parentClass |
||
| 846 | * @param string $componentClass |
||
| 847 | * @param string $parentField |
||
| 848 | * @param string $componentField |
||
| 849 | * @param string $relationTable Name of relation table |
||
| 850 | */ |
||
| 851 | protected function joinManyManyRelationship($parentClass, $componentClass, $parentField, $componentField, $relationTable) { |
||
| 885 | |||
| 886 | /** |
||
| 887 | * Removes the result of query from this query. |
||
| 888 | * |
||
| 889 | * @param DataQuery $subtractQuery |
||
| 890 | * @param string $field |
||
| 891 | * @return $this |
||
| 892 | */ |
||
| 893 | public function subtract(DataQuery $subtractQuery, $field='ID') { |
||
| 904 | |||
| 905 | /** |
||
| 906 | * Select the given fields from the given table. |
||
| 907 | * |
||
| 908 | * @param string $table Unquoted table name (will be escaped automatically) |
||
| 909 | * @param array $fields Database column names (will be escaped automatically) |
||
| 910 | * @return $this |
||
| 911 | */ |
||
| 912 | public function selectFromTable($table, $fields) { |
||
| 921 | |||
| 922 | /** |
||
| 923 | * Query the given field column from the database and return as an array. |
||
| 924 | * |
||
| 925 | * @param string $field See {@link expressionForField()}. |
||
| 926 | * @return array List of column values for the specified column |
||
| 927 | */ |
||
| 928 | public function column($field = 'ID') { |
||
| 938 | |||
| 939 | /** |
||
| 940 | * @param String $field Select statement identifier, either the unquoted column name, |
||
| 941 | * the full composite SQL statement, or the alias set through {@link SQLSelect->selectField()}. |
||
| 942 | * @return String The expression used to query this field via this DataQuery |
||
| 943 | */ |
||
| 944 | protected function expressionForField($field) { |
||
| 960 | |||
| 961 | /** |
||
| 962 | * Select the given field expressions. |
||
| 963 | * |
||
| 964 | * @param $fieldExpression String The field to select (escaped SQL statement) |
||
| 965 | * @param $alias String The alias of that field (escaped SQL statement) |
||
| 966 | */ |
||
| 967 | public function selectField($fieldExpression, $alias = null) { |
||
| 970 | |||
| 971 | //// QUERY PARAMS |
||
| 972 | |||
| 973 | /** |
||
| 974 | * An arbitrary store of query parameters that can be used by decorators. |
||
| 975 | * @todo This will probably be made obsolete if we have subclasses of DataList and/or DataQuery. |
||
| 976 | */ |
||
| 977 | private $queryParams; |
||
| 978 | |||
| 979 | /** |
||
| 980 | * Set an arbitrary query parameter, that can be used by decorators to add additional meta-data to the query. |
||
| 981 | * It's expected that the $key will be namespaced, e.g, 'Versioned.stage' instead of just 'stage'. |
||
| 982 | * |
||
| 983 | * @param string $key |
||
| 984 | * @param string $value |
||
| 985 | * @return $this |
||
| 986 | */ |
||
| 987 | public function setQueryParam($key, $value) { |
||
| 991 | |||
| 992 | /** |
||
| 993 | * Set an arbitrary query parameter, that can be used by decorators to add additional meta-data to the query. |
||
| 994 | * |
||
| 995 | * @param string $key |
||
| 996 | * @return string |
||
| 997 | */ |
||
| 998 | public function getQueryParam($key) { |
||
| 1004 | |||
| 1005 | /** |
||
| 1006 | * Returns all query parameters |
||
| 1007 | * @return array query parameters array |
||
| 1008 | */ |
||
| 1009 | public function getQueryParams() { |
||
| 1012 | } |
||
| 1013 | |||
| 1070 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.