From 9468157b50fa764bd52051b5d81ac09d80906c47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 6 Jan 2015 21:15:16 +0100 Subject: [PATCH] fix recompose function + doc --- Search/AbstractSearch.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Search/AbstractSearch.php b/Search/AbstractSearch.php index b77c90163..61d787e34 100644 --- a/Search/AbstractSearch.php +++ b/Search/AbstractSearch.php @@ -36,6 +36,7 @@ use Chill\MainBundle\Search\ParsingException; abstract class AbstractSearch implements SearchInterface { /** + * parse string expected to be a date and transform to a DateTime object * * @param type $string * @return \DateTime @@ -53,11 +54,21 @@ abstract class AbstractSearch implements SearchInterface } - protected function recomposePattern(array $terms, array $supportedTerms, $domain = '') + /** + * recompose a pattern, retaining only supported terms + * + * the outputted string should be used to show users their search + * + * @param array $terms + * @param array $supportedTerms + * @param string $domain if your domain is NULL, you should set NULL. You should set used domain instead + * @return string + */ + protected function recomposePattern(array $terms, array $supportedTerms, $domain = NULL) { $recomposed = ''; - if ($domain !== '') + if ($domain !== NULL) { $recomposed .= '@'.$domain.' '; } @@ -73,6 +84,11 @@ abstract class AbstractSearch implements SearchInterface $recomposed .= ' '.$terms['_default']; } + //strip first character if empty + if (mb_strcut($recomposed, 0, 1) === ' '){ + $recomposed = mb_strcut($recomposed, 1); + } + return $recomposed; } } \ No newline at end of file