private static function message($type, $str) { // Beanstream returns a completely insane error message format // on user errors: // // - Each error message is preceded by "<LI>", which could be // construed as an attempt to make an HTML list with each // error as an element, but there's no "</LI>", so I'm unsure // what it's actually for // - Each error is separated by "<br>", which is perhaps supposed // to put them each on their own line, but they're each supposed // to be a list item (see above), so why would this ever be necessary? // Plus if there's only one error it will be followed by a "<br>" anyway, // which is almost as degenerate as the fact that libpq puts CRLF at // the end of its error messages // // So even if returning HTML error messages to an API wasn't // completely abominable (having to run a weird recursive search // for text nodes using libxml on your error messages to get something // that can be portably/conveniently displayed in mediums other than // the browser is a good sign of degeneracy) the "HTML" (no closing <LI> // tag means it's not actually HTML, since HTML requires paired opening // and closing tags) makes no sense, therefore we sanitize it out. if ($type !== 'user') { return $str; } // Remove the <LI> tags $str = \CivicInfoBC\Regex::Replace('/<li>/ui', '', $str); // Remove the <br> tags and the white space around them // and replace with LF $str = \CivicInfoBC\Regex::Replace('/\\s*<br>\\s*/ui', "\n", $str); // Remove the trailing LF $str = \CivicInfoBC\Regex::Replace('/\\n$/u', '', $str); return $str; }