/**
  * Stuff that only needs to be done once.  Builds regular expressions and sorts the reserved words.
  */
 protected static function init()
 {
     if (self::$init) {
         return;
     }
     // Sort reserved word list from longest word to shortest, 3x faster than usort
     $reservedMap = array_combine(self::$reserved, array_map('strlen', self::$reserved));
     arsort($reservedMap);
     self::$reserved = array_keys($reservedMap);
     // Set up regular expressions
     self::$regex_boundaries = '(' . implode('|', array_map(array(__CLASS__, 'quote_regex'), self::$boundaries)) . ')';
     self::$regex_reserved = '(' . implode('|', array_map(array(__CLASS__, 'quote_regex'), self::$reserved)) . ')';
     self::$regex_reserved_toplevel = str_replace(' ', '\\s+', '(' . implode('|', array_map(array(__CLASS__, 'quote_regex'), self::$reserved_toplevel)) . ')');
     self::$regex_reserved_newline = str_replace(' ', '\\s+', '(' . implode('|', array_map(array(__CLASS__, 'quote_regex'), self::$reserved_newline)) . ')');
     self::$regex_function = '(' . implode('|', array_map(array(__CLASS__, 'quote_regex'), self::$functions)) . ')';
     self::$init = true;
 }
Example #2
0
 /**
  * Stuff that only needs to be done once.  Builds regular expressions and sorts the reserved words.
  */
 protected static function init()
 {
     if (self::$init) {
         return;
     }
     // Sort reserved word list from longest word to shortest
     usort(self::$reserved, array('SqlFormatter', 'sortLength'));
     // Set up regular expressions
     self::$regex_boundaries = '(' . implode('|', array_map(array('SqlFormatter', 'quote_regex'), self::$boundaries)) . ')';
     self::$regex_reserved = '(' . implode('|', array_map(array('SqlFormatter', 'quote_regex'), self::$reserved)) . ')';
     self::$regex_reserved_toplevel = str_replace(' ', '\\s+', '(' . implode('|', array_map(array('SqlFormatter', 'quote_regex'), self::$reserved_toplevel)) . ')');
     self::$regex_reserved_newline = str_replace(' ', '\\s+', '(' . implode('|', array_map(array('SqlFormatter', 'quote_regex'), self::$reserved_newline)) . ')');
     self::$regex_function = '(' . implode('|', array_map(array('SqlFormatter', 'quote_regex'), self::$functions)) . ')';
     self::$init = true;
 }