From 7836c86e194af3454fafab9ca0d717813bf3525e Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Thu, 7 Jan 2021 19:34:40 +0200 Subject: [PATCH] Fixed PHP 8 compatibility issues --- CHANGELOG.md | 1 + README.md | 4 ++-- classes/GravConnector.php | 12 ++++++----- classes/GravTNTSearch.php | 2 +- cli/TNTSearchIndexerCommand.php | 17 ++++++++-------- cli/TNTSearchQueryCommand.php | 35 ++++++++++++++------------------- composer.json | 1 + 7 files changed, 35 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2d0697..9ec47f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ 1. [](#bugfix) * Fixed `query` truncation when containing a hash (`#`) and preventing proper search results [#110](https://github.com/trilbymedia/grav-plugin-tntsearch/pull/110) + * Fixed PHP 8 compatibility issues # v3.3.0 ## 12/02/2020 diff --git a/README.md b/README.md index 6e6da8d..64ec31a 100644 --- a/README.md +++ b/README.md @@ -236,11 +236,11 @@ For example, say we have a homepage that is built from a few modular sub-pages w ```twig {% for module in page.collection() %}

- {{ module.content }} + {{ module.content|raw }}

{% endfor %} -{{ page.content }} +{{ page.content|raw }} ``` As you can see this simply ensures the module pages as defined in the page's collection are displayed, then the actual page content is displayed. diff --git a/classes/GravConnector.php b/classes/GravConnector.php index 4223af2..3ebc689 100644 --- a/classes/GravConnector.php +++ b/classes/GravConnector.php @@ -6,12 +6,12 @@ use Grav\Common\Yaml; use Grav\Common\Page\Page; use Grav\Plugin\TNTSearchPlugin; +use PDO; -class GravConnector extends \PDO +class GravConnector extends PDO { public function __construct() { - } /** @@ -23,11 +23,13 @@ public function getAttribute($attribute): bool return false; } - /** - * @param string $query + /*** + * @param string $statement + * @param int|null $fetch_style + * @param mixed ...$extra * @return GravResultObject */ - public function query($query) + public function query(string $statement, ?int $fetch_style = null, ...$extra): GravResultObject { $counter = 0; $results = []; diff --git a/classes/GravTNTSearch.php b/classes/GravTNTSearch.php index 3d1396a..f5a1082 100644 --- a/classes/GravTNTSearch.php +++ b/classes/GravTNTSearch.php @@ -208,7 +208,7 @@ public static function getCleanContent($page) } $content = strip_tags($content); - $content = preg_replace('/[ \t]+/', ' ', preg_replace('/\s*$^\s*/m', "\n", $content)); + $content = preg_replace(['/[ \t]+/', '/\s*$^\s*/m'], [' ', "\n"], $content) ?? $content; // Restore active page in Grav. unset($grav['page']); diff --git a/cli/TNTSearchIndexerCommand.php b/cli/TNTSearchIndexerCommand.php index 5dfd775..21c3c0b 100644 --- a/cli/TNTSearchIndexerCommand.php +++ b/cli/TNTSearchIndexerCommand.php @@ -12,13 +12,9 @@ */ class TNTSearchIndexerCommand extends ConsoleCommand { - /** - * @var array - */ + /** @var array */ protected $options = []; - /** - * @var array - */ + /** @var array */ protected $colors = [ 'DEBUG' => 'green', 'INFO' => 'cyan', @@ -33,7 +29,7 @@ class TNTSearchIndexerCommand extends ConsoleCommand /** * @return void */ - protected function configure() + protected function configure(): void { $this ->setName('index') @@ -54,10 +50,11 @@ protected function configure() } /** - * @return void + * @return int */ - protected function serve() + protected function serve(): int { + /** @var string|null $langCode */ $langCode = $this->input->getOption('language'); error_reporting(1); @@ -82,6 +79,8 @@ protected function serve() $this->output->writeln(''); $this->output->writeln('Indexed in ' . $end . 's'); } + + return 0; } /** diff --git a/cli/TNTSearchQueryCommand.php b/cli/TNTSearchQueryCommand.php index 11c46a9..45411c2 100644 --- a/cli/TNTSearchQueryCommand.php +++ b/cli/TNTSearchQueryCommand.php @@ -13,14 +13,9 @@ */ class TNTSearchQueryCommand extends ConsoleCommand { - /** - * @var array - */ + /** @var array */ protected $options = []; - - /** - * @var array - */ + /** @var array */ protected $colors = [ 'DEBUG' => 'green', 'INFO' => 'cyan', @@ -56,24 +51,24 @@ protected function configure() } /** - * @return void + * @return int */ - protected function serve() + protected function serve(): int { - $this->setLanguage($this->input->getOption('language')); - $this->initializePages(); + /** @var string|null $langCode */ + $langCode = $this->input->getOption('language'); + /** @var string $query */ + $query = $this->input->getArgument('query'); - $this->doQuery(); - $this->output->writeln(''); - } + $this->setLanguage($langCode); + $this->initializePages(); - /** - * @return void - */ - private function doQuery() - { $gtnt = TNTSearchPlugin::getSearchObjectType(['json' => true]); - print_r($gtnt->search($this->input->getArgument('query'))); + print_r($gtnt->search($query)); + + $this->output->newLine(); + + return 0; } } diff --git a/composer.json b/composer.json index a3dd8e9..9e84ab6 100644 --- a/composer.json +++ b/composer.json @@ -16,6 +16,7 @@ "require": { "php": ">=7.1.3", "ext-json": "*", + "ext-pdo": "*", "teamtnt/tntsearch": "^2.0" }, "autoload": {