Skip to content

Commit d33e498

Browse files
committed
v3: Support for Silverstripe 6
1 parent 4171ad4 commit d33e498

32 files changed

+146
-129
lines changed

_config/service.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
Name: discoverer-service
3+
---
4+
SilverStripe\Core\Injector\Injector:
5+
SilverStripe\Discoverer\Service\SearchService:
6+
constructor:
7+
indexPrefix: '`SS_ENVIRONMENT_TYPE`'

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
"Querying"
2222
],
2323
"require": {
24-
"php": "^8.1",
25-
"silverstripe/framework": "^5.2"
24+
"php": "^8.3",
25+
"silverstripe/framework": "^6"
2626
},
2727
"require-dev": {
28-
"phpunit/phpunit": "^9.5",
29-
"slevomat/coding-standard": "^8.8"
28+
"phpunit/phpunit": "^11.3",
29+
"slevomat/coding-standard": "~8.18.0"
3030
},
3131
"autoload": {
3232
"psr-4": {

docs/detailed-result-handling.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ simple methods available that you can access anywhere.
2121
* `getRecords()`: A `PaginatedList` of `Record` objects that were returned by the search service based on your `Query`.
2222
* `getFacets`: An `ArrayList` of `Facet` objects that were returned by the search service based on your `Query`.
2323

24-
The `Results` class is also a `ViewableData` object, so these methods can be access in your template with `$isSuccess`,
24+
The `Results` class is also a `ModelData` object, so these methods can be access in your template with `$isSuccess`,
2525
`$Records`, and `$Facets`.
2626

2727
## `Record` class
2828

29-
The `Record` class is a simple `ViewableData` class, and the purpose of it is to provide you with access to the fields
29+
The `Record` class is a simple `ModelData` class, and the purpose of it is to provide you with access to the fields
3030
that are returned by your search service, and to make those fields available to you in (EG) Silverstripe templates.
3131

3232
**Note:** A `Record` is not assumed to have a linked `DataObject`. The recommendation would be for you to index all of

phpcs.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
<file>src</file>
66
<file>tests</file>
77

8+
<!-- Don't sniff test classes, because they include PHP attributes that cause Slevomat to throw errors -->
9+
<exclude-pattern>./tests/*</exclude-pattern>
810
<!-- Don't sniff third party libraries -->
911
<exclude-pattern>./vendor/*</exclude-pattern>
1012
<exclude-pattern>*/thirdparty/*</exclude-pattern>
@@ -146,6 +148,8 @@
146148
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification"/>
147149
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification"/>
148150
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingTraversableTypeHintSpecification"/>
151+
<!-- Leave the order up to us to decide -->
152+
<exclude name="SlevomatCodingStandard.Classes.ClassStructure.IncorrectGroupOrder"/>
149153
</rule>
150154

151155
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">

phpunit.xml.dist

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true">
3-
<testsuites>
4-
<testsuite name="Default">
5-
<directory>tests</directory>
6-
</testsuite>
7-
</testsuites>
8-
<filter>
9-
<whitelist addUncoveredFilesFromWhitelist="true">
10-
<directory suffix=".php">src/</directory>
11-
<exclude>
12-
<directory suffix=".php">tests/</directory>
13-
</exclude>
14-
</whitelist>
15-
</filter>
1+
<?xml version="1.0"?>
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
bootstrap="vendor/silverstripe/framework/tests/bootstrap.php"
5+
colors="true"
6+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd"
7+
cacheDirectory=".phpunit.cache"
8+
>
9+
<testsuite name="Default">
10+
<directory>tests</directory>
11+
</testsuite>
12+
<source>
13+
<include>
14+
<directory suffix=".php">tests</directory>
15+
</include>
16+
</source>
1617
</phpunit>

src/Analytics/AnalyticsData.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,29 @@
33
namespace SilverStripe\Discoverer\Analytics;
44

55
use SilverStripe\Core\Injector\Injectable;
6-
use SilverStripe\View\ViewableData;
6+
use SilverStripe\Model\ModelData;
77

8-
class AnalyticsData extends ViewableData
8+
class AnalyticsData extends ModelData
99
{
1010

1111
use Injectable;
1212

13-
private ?string $engineName = null;
13+
private ?string $indexName = null;
1414

1515
private ?string $queryString = null;
1616

1717
private mixed $documentId = null;
1818

1919
private mixed $requestId = null;
2020

21-
public function getEngineName(): ?string
21+
public function getIndexName(): ?string
2222
{
23-
return $this->engineName;
23+
return $this->indexName;
2424
}
2525

26-
public function setEngineName(?string $engineName): AnalyticsData
26+
public function setIndexName(?string $indexName): AnalyticsData
2727
{
28-
$this->engineName = $engineName;
28+
$this->indexName = $indexName;
2929

3030
return $this;
3131
}
@@ -66,17 +66,17 @@ public function setRequestId(mixed $requestId): AnalyticsData
6666
return $this;
6767
}
6868

69-
public function forTemplate(): ?string
69+
public function forTemplate(): string
7070
{
7171
$data = [];
7272

73-
$engineName = $this->getEngineName();
73+
$indexName = $this->getIndexName();
7474
$query = $this->getQueryString();
7575
$documentId = $this->getDocumentId();
7676
$requestId = $this->getRequestId();
7777

78-
if ($engineName) {
79-
$data['engineName'] = $engineName;
78+
if ($indexName) {
79+
$data['indexName'] = $indexName;
8080
}
8181

8282
if ($query) {
@@ -92,7 +92,7 @@ public function forTemplate(): ?string
9292
}
9393

9494
if (!$data) {
95-
return null;
95+
return '';
9696
}
9797

9898
$query = [

src/Analytics/AnalyticsMiddleware.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class AnalyticsMiddleware implements HTTPMiddleware
1818
use Configurable;
1919
use Injectable;
2020

21-
public const ENV_ANALYTICS_ENABLED = 'SEARCH_ANALYTICS_ENABLED';
21+
public const string ENV_ANALYTICS_ENABLED = 'SEARCH_ANALYTICS_ENABLED';
2222

2323
private ?LoggerInterface $logger = null;
2424

@@ -58,7 +58,7 @@ public function process(HTTPRequest $request, callable $delegate): mixed
5858
$analyticsData->setQueryString($data['queryString'] ?? null);
5959
$analyticsData->setRequestId($data['requestId'] ?? null);
6060
$analyticsData->setDocumentId($data['documentId'] ?? null);
61-
$analyticsData->setEngineName($data['engineName'] ?? null);
61+
$analyticsData->setIndexName($data['indexName'] ?? null);
6262

6363
$service = SearchService::create();
6464
$service->processAnalytics($analyticsData);

src/Query/Facet/Facet.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ class Facet
1414

1515
use Injectable;
1616

17-
public const TYPE_VALUE = 'VALUE';
18-
public const TYPE_RANGE = 'RANGE';
17+
public const string TYPE_VALUE = 'VALUE';
18+
public const string TYPE_RANGE = 'RANGE';
1919

20-
public const TYPES = [
20+
public const array TYPES = [
2121
self::TYPE_VALUE,
2222
self::TYPE_RANGE,
2323
];

src/Query/Filter/Criteria.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ class Criteria implements Clause
2121

2222
use Injectable;
2323

24-
public const CONJUNCTION_AND = 'AND';
25-
public const CONJUNCTION_OR = 'OR';
24+
public const string CONJUNCTION_AND = 'AND';
25+
public const string CONJUNCTION_OR = 'OR';
2626

27-
public const CONJUNCTIONS = [
27+
public const array CONJUNCTIONS = [
2828
self::CONJUNCTION_AND,
2929
self::CONJUNCTION_OR,
3030
];

src/Query/Filter/Criterion.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ class Criterion implements Clause
1616

1717
use Injectable;
1818

19-
public const EQUAL = 'EQUAL';
20-
public const NOT_EQUAL = 'NOT_EQUAL';
21-
public const GREATER_EQUAL = 'GREATER_EQUAL';
22-
public const GREATER_THAN = 'GREATER_THAN';
23-
public const LESS_EQUAL = 'LESS_EQUAL';
24-
public const LESS_THAN = 'LESS_THAN';
25-
public const IN = 'IN';
26-
public const NOT_IN = 'NOT_IN';
27-
public const IS_NULL = 'IS_NULL';
28-
public const IS_NOT_NULL = 'IS_NOT_NULL';
29-
public const RANGE = 'RANGE';
30-
31-
public const COMPARISONS = [
19+
public const string EQUAL = 'EQUAL';
20+
public const string NOT_EQUAL = 'NOT_EQUAL';
21+
public const string GREATER_EQUAL = 'GREATER_EQUAL';
22+
public const string GREATER_THAN = 'GREATER_THAN';
23+
public const string LESS_EQUAL = 'LESS_EQUAL';
24+
public const string LESS_THAN = 'LESS_THAN';
25+
public const string IN = 'IN';
26+
public const string NOT_IN = 'NOT_IN';
27+
public const string IS_NULL = 'IS_NULL';
28+
public const string IS_NOT_NULL = 'IS_NOT_NULL';
29+
public const string RANGE = 'RANGE';
30+
31+
public const array COMPARISONS = [
3232
self::EQUAL,
3333
self::NOT_EQUAL,
3434
self::GREATER_EQUAL,
@@ -42,7 +42,7 @@ class Criterion implements Clause
4242
self::RANGE,
4343
];
4444

45-
public const NULL_COMPARISONS = [
45+
public const array NULL_COMPARISONS = [
4646
self::IS_NULL,
4747
self::IS_NOT_NULL,
4848
];

0 commit comments

Comments
 (0)