-<?php namespace BookStack\Entities\Tools;
+<?php
+
+namespace BookStack\Entities\Tools;
use Illuminate\Http\Request;
class SearchOptions
{
-
/**
* @var array
*/
/**
* Create a new instance from a search string.
*/
- public static function fromString(string $search): SearchOptions
+ public static function fromString(string $search): self
{
$decoded = static::decode($search);
- $instance = new static();
+ $instance = new SearchOptions();
foreach ($decoded as $type => $value) {
$instance->$type = $value;
}
+
return $instance;
}
* Will look for a classic string term and use that
* Otherwise we'll use the details from an advanced search form.
*/
- public static function fromRequest(Request $request): SearchOptions
+ public static function fromRequest(Request $request): self
{
if (!$request->has('search') && !$request->has('term')) {
return static::fromString('');
return static::fromString($request->get('term'));
}
- $instance = new static();
+ $instance = new SearchOptions();
$inputs = $request->only(['search', 'types', 'filters', 'exact', 'tags']);
$instance->searches = explode(' ', $inputs['search'] ?? []);
$instance->exacts = array_filter($inputs['exact'] ?? []);
if (isset($inputs['types']) && count($inputs['types']) < 4) {
$instance->filters['type'] = implode('|', $inputs['types']);
}
+
return $instance;
}
{
$terms = [
'searches' => [],
- 'exacts' => [],
- 'tags' => [],
- 'filters' => []
+ 'exacts' => [],
+ 'tags' => [],
+ 'filters' => [],
];
$patterns = [
- 'exacts' => '/"(.*?)"/',
- 'tags' => '/\[(.*?)\]/',
- 'filters' => '/\{(.*?)\}/'
+ 'exacts' => '/"(.*?)"/',
+ 'tags' => '/\[(.*?)\]/',
+ 'filters' => '/\{(.*?)\}/',
];
// Parse special terms
return $string;
}
-
-}
\ No newline at end of file
+}