You are here

public static function CRM_Utils_Type::mysqlOrderByCallback in CiviCRM Entity 8.3

preg_replace_callback for MysqlOrderBy escape.

File

tests/src/Type.php, line 505

Class

CRM_Utils_Type
@package CRM @copyright CiviCRM LLC (c) 2004-2017

Code

public static function mysqlOrderByCallback($matches) {
  $output = '';
  $matches = str_replace('`', '', $matches);

  // Table name.
  if (isset($matches[1]) && $matches[1]) {
    $output .= '`' . $matches[1] . '`.';
  }

  // Column name.
  if (isset($matches[2]) && $matches[2]) {
    $output .= '`' . $matches[2] . '`';
  }

  // Sort order.
  if (isset($matches[3]) && $matches[3]) {
    $output .= ' ' . $matches[3];
  }
  return $output;
}