Skip to content

Commit

Permalink
Fixed PHP 8 compatibility issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mahagr committed Jan 7, 2021
1 parent dd79615 commit 7836c86
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 37 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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() %}
<p>
{{ module.content }}
{{ module.content|raw }}
</p>
{% 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.
Expand Down
12 changes: 7 additions & 5 deletions classes/GravConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{

}

/**
Expand All @@ -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 = [];
Expand Down
2 changes: 1 addition & 1 deletion classes/GravTNTSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
17 changes: 8 additions & 9 deletions cli/TNTSearchIndexerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@
*/
class TNTSearchIndexerCommand extends ConsoleCommand
{
/**
* @var array
*/
/** @var array */
protected $options = [];
/**
* @var array
*/
/** @var array */
protected $colors = [
'DEBUG' => 'green',
'INFO' => 'cyan',
Expand All @@ -33,7 +29,7 @@ class TNTSearchIndexerCommand extends ConsoleCommand
/**
* @return void
*/
protected function configure()
protected function configure(): void
{
$this
->setName('index')
Expand All @@ -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);
Expand All @@ -82,6 +79,8 @@ protected function serve()
$this->output->writeln('');
$this->output->writeln('Indexed in ' . $end . 's');
}

return 0;
}

/**
Expand Down
35 changes: 15 additions & 20 deletions cli/TNTSearchQueryCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,9 @@
*/
class TNTSearchQueryCommand extends ConsoleCommand
{
/**
* @var array
*/
/** @var array */
protected $options = [];

/**
* @var array
*/
/** @var array */
protected $colors = [
'DEBUG' => 'green',
'INFO' => 'cyan',
Expand Down Expand Up @@ -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;
}
}

1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"require": {
"php": ">=7.1.3",
"ext-json": "*",
"ext-pdo": "*",
"teamtnt/tntsearch": "^2.0"
},
"autoload": {
Expand Down

0 comments on commit 7836c86

Please sign in to comment.