From af99004549c12d20b28540fc719c4189daec14e8 Mon Sep 17 00:00:00 2001 From: Hendrik Schaper Date: Wed, 26 Sep 2018 12:26:54 +0200 Subject: [PATCH 1/3] PHP7.2 compatibility each() and create_function() are deprecated in PHP7.2 , -> I copied the code from the 4 branch - seems to work in my local environment --- code/search/SearchForm.php | 54 ++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/code/search/SearchForm.php b/code/search/SearchForm.php index 1e775b62..763d3e23 100644 --- a/code/search/SearchForm.php +++ b/code/search/SearchForm.php @@ -131,12 +131,12 @@ class SearchForm extends Form { $keywords = $data['Search']; - $andProcessor = create_function('$matches',' - return " +" . $matches[2] . " +" . $matches[4] . " "; - '); - $notProcessor = create_function('$matches', ' - return " -" . $matches[3]; - '); + $andProcessor = function ($matches) { + return ' +' . $matches[2] . ' +' . $matches[4] . ' '; + }; + $notProcessor = function ($matches) { + return ' -' . $matches[3]; + }; $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; } - protected function addStarsToKeywords($keywords) { - if(!trim($keywords)) return ""; - // Add * to each keyword - $splitWords = preg_split("/ +/" , trim($keywords)); - while(list($i,$word) = each($splitWords)) { - if($word[0] == '"') { - while(list($i,$subword) = each($splitWords)) { - $word .= ' ' . $subword; - if(substr($subword,-1) == '"') break; - } - } else { - $word .= '*'; - } - $newWords[] = $word; - } - return implode(" ", $newWords); - } + protected function addStarsToKeywords($keywords) + { + if (!trim($keywords)) { + return ""; + } + // Add * to each keyword + $splitWords = preg_split("/ +/", trim($keywords)); + $newWords = []; + for ($i = 0; $i < count($splitWords); $i++) { + $word = $splitWords[$i]; + if ($word[0] == '"') { + while (++$i < count($splitWords)) { + $subword = $splitWords[$i]; + $word .= ' ' . $subword; + if (substr($subword, -1) == '"') { + break; + } + } + } else { + $word .= '*'; + } + $newWords[] = $word; + } + return implode(" ", $newWords); + } /** * Get the search query for display in a "You searched for ..." sentence. From 31ee3eb0f34056b89a36272147fbc0924633f01c Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Thu, 27 Sep 2018 11:51:43 +0200 Subject: [PATCH 2/3] PHP 5.3 compatibility in array syntax and use strict comparison operators --- code/search/SearchForm.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/code/search/SearchForm.php b/code/search/SearchForm.php index 763d3e23..01b648ee 100644 --- a/code/search/SearchForm.php +++ b/code/search/SearchForm.php @@ -180,14 +180,14 @@ class SearchForm extends Form { } // Add * to each keyword $splitWords = preg_split("/ +/", trim($keywords)); - $newWords = []; + $newWords = array(); for ($i = 0; $i < count($splitWords); $i++) { $word = $splitWords[$i]; - if ($word[0] == '"') { + if ($word[0] === '"') { while (++$i < count($splitWords)) { $subword = $splitWords[$i]; $word .= ' ' . $subword; - if (substr($subword, -1) == '"') { + if (substr($subword, -1) === '"') { break; } } From 60ce733cfbf1d2bed0633629dd5f555c1ccd91af Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Thu, 27 Sep 2018 11:52:24 +0200 Subject: [PATCH 3/3] Increase memory limit in Travis builds --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 71f63bc7..611e2338 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,6 +33,7 @@ before_script: - composer self-update || true - phpenv rehash - 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 - "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"