Merge pull request #2278 from RoyalPulp/patch-1

PHP7.2 compatibility
This commit is contained in:
Robbie Averill 2018-09-27 12:30:18 +02:00 committed by GitHub
commit a75990ef8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 23 deletions

View File

@ -33,6 +33,7 @@ before_script:
- composer self-update || true - composer self-update || true
- phpenv rehash - phpenv rehash
- phpenv config-rm xdebug.ini - phpenv config-rm xdebug.ini
- echo 'memory_limit = 2048M' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
- git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support - git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support
- "if [ \"$BEHAT_TEST\" = \"\" ]; then php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss; fi" - "if [ \"$BEHAT_TEST\" = \"\" ]; then php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss; fi"
- "if [ \"$BEHAT_TEST\" = \"1\" ]; then php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss --require silverstripe/behat-extension; fi" - "if [ \"$BEHAT_TEST\" = \"1\" ]; then php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss --require silverstripe/behat-extension; fi"

View File

@ -131,12 +131,12 @@ class SearchForm extends Form {
$keywords = $data['Search']; $keywords = $data['Search'];
$andProcessor = create_function('$matches',' $andProcessor = function ($matches) {
return " +" . $matches[2] . " +" . $matches[4] . " "; return ' +' . $matches[2] . ' +' . $matches[4] . ' ';
'); };
$notProcessor = create_function('$matches', ' $notProcessor = function ($matches) {
return " -" . $matches[3]; return ' -' . $matches[3];
'); };
$keywords = preg_replace_callback('/()("[^()"]+")( and )("[^"()]+")()/i', $andProcessor, $keywords); $keywords = preg_replace_callback('/()("[^()"]+")( and )("[^"()]+")()/i', $andProcessor, $keywords);
$keywords = preg_replace_callback('/(^| )([^() ]+)( and )([^ ()]+)( |$)/i', $andProcessor, $keywords); $keywords = preg_replace_callback('/(^| )([^() ]+)( and )([^ ()]+)( |$)/i', $andProcessor, $keywords);
@ -173,23 +173,31 @@ class SearchForm extends Form {
return $results; return $results;
} }
protected function addStarsToKeywords($keywords) { protected function addStarsToKeywords($keywords)
if(!trim($keywords)) return ""; {
// Add * to each keyword if (!trim($keywords)) {
$splitWords = preg_split("/ +/" , trim($keywords)); return "";
while(list($i,$word) = each($splitWords)) { }
if($word[0] == '"') { // Add * to each keyword
while(list($i,$subword) = each($splitWords)) { $splitWords = preg_split("/ +/", trim($keywords));
$word .= ' ' . $subword; $newWords = array();
if(substr($subword,-1) == '"') break; for ($i = 0; $i < count($splitWords); $i++) {
} $word = $splitWords[$i];
} else { if ($word[0] === '"') {
$word .= '*'; while (++$i < count($splitWords)) {
} $subword = $splitWords[$i];
$newWords[] = $word; $word .= ' ' . $subword;
} if (substr($subword, -1) === '"') {
return implode(" ", $newWords); break;
} }
}
} else {
$word .= '*';
}
$newWords[] = $word;
}
return implode(" ", $newWords);
}
/** /**
* Get the search query for display in a "You searched for ..." sentence. * Get the search query for display in a "You searched for ..." sentence.