Skip to content

Commit 92f94e1

Browse files
committed
Add support for CMS 6
1 parent e86ead4 commit 92f94e1

12 files changed

+49
-30
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This module allows Silverstripe CMS ORM data to be encrypted before being stored
1212

1313

1414
## Requirements
15-
* SilverStripe CMS 5.0
15+
* SilverStripe CMS 6.0
1616

1717
## Installation
1818
Install via Composer:
@@ -32,7 +32,7 @@ For development environments you can set this in your `.env` e.g:
3232
ENCRYPT_AT_REST_KEY="{generated defuse key}"
3333
```
3434

35-
For more information view SilverStripe [Environment Management](https://docs.silverstripe.org/en/4/getting_started/environment_management/).
35+
For more information view SilverStripe [Environment Management](https://docs.silverstripe.org/en/6/getting_started/environment_management/).
3636

3737
## Usage
3838

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
"source": "https://github.com/madmatt/silverstripe-encrypt-at-rest"
1717
},
1818
"require": {
19-
"php": "^8.0",
20-
"silverstripe/framework": "^5",
19+
"php": "^8.3",
20+
"silverstripe/framework": "^6",
2121
"defuse/php-encryption": "^2.2"
2222
},
2323
"require-dev": {
24-
"phpunit/phpunit": "^9.6"
24+
"phpunit/phpunit": "^11.3"
2525
},
2626
"autoload": {
2727
"psr-4": {

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/silverstripe/cms/tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
33
<coverage includeUncoveredFiles="true">
44
<include>
55
<directory suffix=".php">src/</directory>

src/Extension/DecryptDataObjectFieldsExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Madmatt\EncryptAtRest\Extension;
44

5-
use SilverStripe\ORM\DataExtension;
5+
use SilverStripe\Core\Extension;
66
use SilverStripe\Core\Config\Config;
77
use SilverStripe\Core\Injector\Injector;
88
use SilverStripe\ORM\DataObject;
@@ -18,7 +18,7 @@
1818
* @package EncryptAtRest\Extension
1919
* @property DecryptDataObjectFieldsExtension|DataObject $owner
2020
*/
21-
class DecryptDataObjectFieldsExtension extends DataExtension
21+
class DecryptDataObjectFieldsExtension extends Extension
2222
{
2323
/**
2424
* During hydration of an existing DataObject retrieved from the database, this extension method will be called. We

src/FieldType/EncryptedDatetime.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Exception;
66
use Madmatt\EncryptAtRest\Traits\EncryptedFieldGetValueTrait;
77
use SilverStripe\Core\Injector\Injector;
8+
use SilverStripe\Model\ModelData;
89
use SilverStripe\ORM\DB;
910
use SilverStripe\ORM\FieldType\DBDatetime;
1011
use Madmatt\EncryptAtRest\AtRestCryptoService;
@@ -32,7 +33,7 @@ public function __construct($name = null, $options = [])
3233
$this->service = Injector::inst()->get(AtRestCryptoService::class);
3334
}
3435

35-
public function setValue($value, $record = null, $markChanged = true)
36+
public function setValue(mixed $value, null|array|ModelData $record = null, bool $markChanged = true): static
3637
{
3738
if (is_array($record) && array_key_exists($this->name, $record) && $value === null) {
3839
$this->value = $record[$this->name];
@@ -42,6 +43,8 @@ public function setValue($value, $record = null, $markChanged = true)
4243
} else {
4344
$this->value = $value;
4445
}
46+
47+
return $this;
4548
}
4649

4750
public function getDecryptedValue(string $value = '')
@@ -58,7 +61,7 @@ public function getDecryptedValue(string $value = '')
5861
return $value;
5962
}
6063

61-
public function requireField()
64+
public function requireField(): void
6265
{
6366
$values = array(
6467
'type' => 'text',
@@ -72,7 +75,7 @@ public function requireField()
7275
DB::require_field($this->tableName, $this->name, $values);
7376
}
7477

75-
public function prepValueForDB($value)
78+
public function prepValueForDB(mixed $value): mixed
7679
{
7780
$value = parent::prepValueForDB($value);
7881
$ciphertext = $this->service->encrypt($value);

src/FieldType/EncryptedDecimal.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Exception;
66
use Madmatt\EncryptAtRest\Traits\EncryptedFieldGetValueTrait;
77
use SilverStripe\Core\Injector\Injector;
8+
use SilverStripe\Model\ModelData;
89
use SilverStripe\ORM\DB;
910
use SilverStripe\ORM\FieldType\DBDecimal;
1011
use Madmatt\EncryptAtRest\AtRestCryptoService;
@@ -31,7 +32,7 @@ public function __construct($name = null, $wholeSize = 9, $decimalSize = 2, $def
3132
$this->service = Injector::inst()->get(AtRestCryptoService::class);
3233
}
3334

34-
public function setValue($value, $record = null, $markChanged = true)
35+
public function setValue(mixed $value, null|array|ModelData $record = null, bool $markChanged = true): static
3536
{
3637
if (is_array($record) && array_key_exists($this->name, $record) && $value === null) {
3738
$this->value = $record[$this->name];
@@ -41,6 +42,8 @@ public function setValue($value, $record = null, $markChanged = true)
4142
} else {
4243
$this->value = $value;
4344
}
45+
46+
return $this;
4447
}
4548

4649
public function getDecryptedValue(string $value = '')
@@ -57,7 +60,7 @@ public function getDecryptedValue(string $value = '')
5760
return (float)$value;
5861
}
5962

60-
public function requireField()
63+
public function requireField(): void
6164
{
6265
$values = array(
6366
'type' => 'text',
@@ -71,7 +74,7 @@ public function requireField()
7174
DB::require_field($this->tableName, $this->name, $values);
7275
}
7376

74-
public function prepValueForDB($value)
77+
public function prepValueForDB(mixed $value): array|float|int|null
7578
{
7679
$value = parent::prepValueForDB($value);
7780
$ciphertext = $this->service->encrypt($value);

src/FieldType/EncryptedEnum.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
use Exception;
66
use Madmatt\EncryptAtRest\Traits\EncryptedFieldGetValueTrait;
77
use SilverStripe\Core\Injector\Injector;
8+
use SilverStripe\Model\ModelData;
89
use SilverStripe\ORM\DB;
910
use SilverStripe\ORM\FieldType\DBEnum;
10-
use SilverStripe\ORM\ArrayLib;
11+
use SilverStripe\Core\ArrayLib;
1112
use Madmatt\EncryptAtRest\AtRestCryptoService;
1213

1314
/**
@@ -32,7 +33,7 @@ public function __construct($name = null, $enum = null, $default = 0, $options =
3233
$this->service = Injector::inst()->get(AtRestCryptoService::class);
3334
}
3435

35-
public function setValue($value, $record = null, $markChanged = true)
36+
public function setValue(mixed $value, null|array|ModelData $record = null, bool $markChanged = true): static
3637
{
3738
if (is_array($record) && array_key_exists($this->name, $record) && $value === null) {
3839
$this->value = $record[$this->name];
@@ -42,6 +43,8 @@ public function setValue($value, $record = null, $markChanged = true)
4243
} else {
4344
$this->value = $value;
4445
}
46+
47+
return $this;
4548
}
4649

4750
public function getDecryptedValue(string $value = '')
@@ -58,7 +61,7 @@ public function getDecryptedValue(string $value = '')
5861
return $value;
5962
}
6063

61-
public function requireField()
64+
public function requireField(): void
6265
{
6366
$values = array(
6467
'type' => 'text',
@@ -72,7 +75,7 @@ public function requireField()
7275
DB::require_field($this->tableName, $this->name, $values);
7376
}
7477

75-
public function prepValueForDB($value)
78+
public function prepValueForDB(mixed $value): array|string|null
7679
{
7780
$value = parent::prepValueForDB($value);
7881
$ciphertext = $this->service->encrypt($value);
@@ -88,7 +91,8 @@ public function prepValueForDB($value)
8891
*
8992
* @return array
9093
*/
91-
public function enumValues($hasEmpty = true) {
94+
public function enumValues(bool $hasEmpty = false): array
95+
{
9296
$this->enum = array();
9397
return ($hasEmpty)
9498
? array_merge(array('' => ''), ArrayLib::valuekey($this->enum))

src/FieldType/EncryptedInt.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Exception;
66
use Madmatt\EncryptAtRest\Traits\EncryptedFieldGetValueTrait;
77
use SilverStripe\Core\Injector\Injector;
8+
use SilverStripe\Model\ModelData;
89
use SilverStripe\ORM\DB;
910
use SilverStripe\ORM\FieldType\DBInt;
1011
use Madmatt\EncryptAtRest\AtRestCryptoService;
@@ -31,7 +32,7 @@ public function __construct($name = null, $defaultVal = 0)
3132
$this->service = Injector::inst()->get(AtRestCryptoService::class);
3233
}
3334

34-
public function setValue($value, $record = null, $markChanged = true)
35+
public function setValue(mixed $value, null|array|ModelData $record = null, bool $markChanged = true): static
3536
{
3637
if (is_array($record) && array_key_exists($this->name, $record) && $value === null) {
3738
$this->value = $record[$this->name];
@@ -41,6 +42,8 @@ public function setValue($value, $record = null, $markChanged = true)
4142
} else {
4243
$this->value = $value;
4344
}
45+
46+
return $this;
4447
}
4548

4649
public function getDecryptedValue(string $value = '')
@@ -57,7 +60,7 @@ public function getDecryptedValue(string $value = '')
5760
return $value;
5861
}
5962

60-
public function requireField()
63+
public function requireField(): void
6164
{
6265
$values = array(
6366
'type' => 'text',
@@ -71,7 +74,7 @@ public function requireField()
7174
DB::require_field($this->tableName, $this->name, $values);
7275
}
7376

74-
public function prepValueForDB($value)
77+
public function prepValueForDB(mixed $value): array|int|null
7578
{
7679
$value = parent::prepValueForDB($value);
7780
$ciphertext = $this->service->encrypt($value);

src/FieldType/EncryptedText.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Exception;
66
use Madmatt\EncryptAtRest\Traits\EncryptedFieldGetValueTrait;
77
use SilverStripe\Core\Injector\Injector;
8+
use SilverStripe\Model\ModelData;
89
use SilverStripe\ORM\DB;
910
use SilverStripe\ORM\FieldType\DBText;
1011
use Madmatt\EncryptAtRest\AtRestCryptoService;
@@ -24,7 +25,7 @@ public function __construct($name = null, $options = [])
2425
$this->service = Injector::inst()->get(AtRestCryptoService::class);
2526
}
2627

27-
public function setValue($value, $record = null, $markChanged = true)
28+
public function setValue(mixed $value, null|array|ModelData $record = null, bool $markChanged = true): static
2829
{
2930
if (is_array($record) && array_key_exists($this->name, $record) && $value === null) {
3031
$this->value = $record[$this->name];
@@ -34,6 +35,8 @@ public function setValue($value, $record = null, $markChanged = true)
3435
} else {
3536
$this->value = $value;
3637
}
38+
39+
return $this;
3740
}
3841

3942
public function getDecryptedValue(string $value = '')
@@ -50,7 +53,7 @@ public function getDecryptedValue(string $value = '')
5053
return $value;
5154
}
5255

53-
public function requireField()
56+
public function requireField(): void
5457
{
5558
$values = array(
5659
'type' => 'text',
@@ -64,7 +67,7 @@ public function requireField()
6467
DB::require_field($this->tableName, $this->name, $values);
6568
}
6669

67-
public function prepValueForDB($value)
70+
public function prepValueForDB(mixed $value): array|string|null
6871
{
6972
$value = parent::prepValueForDB($value);
7073
$ciphertext = $this->service->encrypt($value);

src/FieldType/EncryptedVarchar.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Madmatt\EncryptAtRest\AtRestCryptoService;
77
use Madmatt\EncryptAtRest\Traits\EncryptedFieldGetValueTrait;
88
use SilverStripe\Core\Injector\Injector;
9+
use SilverStripe\Model\ModelData;
910
use SilverStripe\ORM\DB;
1011
use SilverStripe\ORM\FieldType\DBVarchar;
1112

@@ -32,7 +33,7 @@ public function __construct($name = null, $size = 255, $options = array())
3233
$this->service = Injector::inst()->get(AtRestCryptoService::class);
3334
}
3435

35-
public function setValue($value, $record = null, $markChanged = true)
36+
public function setValue(mixed $value, null|array|ModelData $record = null, bool $markChanged = true): static
3637
{
3738
if (is_array($record) && array_key_exists($this->name, $record) && $value === null) {
3839
$this->value = $record[$this->name];
@@ -42,6 +43,8 @@ public function setValue($value, $record = null, $markChanged = true)
4243
} else {
4344
$this->value = $value;
4445
}
46+
47+
return $this;
4548
}
4649

4750
public function getDecryptedValue(string $value = '')
@@ -58,7 +61,7 @@ public function getDecryptedValue(string $value = '')
5861
return $value;
5962
}
6063

61-
public function requireField()
64+
public function requireField(): void
6265
{
6366
$values = array(
6467
'type' => 'text',
@@ -72,7 +75,7 @@ public function requireField()
7275
DB::require_field($this->tableName, $this->name, $values);
7376
}
7477

75-
public function prepValueForDB($value)
78+
public function prepValueForDB(mixed $value): array|string|null
7679
{
7780
$value = parent::prepValueForDB($value);
7881
$ciphertext = $this->service->encrypt($value);

0 commit comments

Comments
 (0)