Skip to content

Commit

Permalink
API Add ValidationInterface to DataObject
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Dec 16, 2024
1 parent dc973c6 commit d033258
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
8 changes: 3 additions & 5 deletions src/ORM/DataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Core\Resettable;
use SilverStripe\Core\Validation\ValidationException;
use SilverStripe\Core\Validation\ValidationInterface;
use SilverStripe\Core\Validation\ValidationResult;
use SilverStripe\Dev\Debug;
use SilverStripe\Dev\Deprecation;
Expand Down Expand Up @@ -111,7 +112,7 @@
* @property string $Created Date and time of DataObject creation.
* @property string $ObsoleteClassName If ClassName no longer exists this will be set to the legacy value
*/
class DataObject extends ModelData implements DataObjectInterface, i18nEntityProvider, Resettable
class DataObject extends ModelData implements DataObjectInterface, i18nEntityProvider, Resettable, ValidationInterface
{
/**
* Human-readable singular name.
Expand Down Expand Up @@ -1252,11 +1253,8 @@ public function forceChange()
*
* It is expected that you call validate() in your own application to test that an object is valid before
* attempting a write, and respond appropriately if it isn't.
*
* @see {@link ValidationResult}
* @return ValidationResult
*/
public function validate()
public function validate(): ValidationResult
{
$result = ValidationResult::create();
// Call DBField::validate() on every DBField
Expand Down
3 changes: 2 additions & 1 deletion src/Security/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use SilverStripe\ORM\Hierarchy\Hierarchy;
use SilverStripe\ORM\ManyManyList;
use SilverStripe\ORM\UnsavedRelationList;
use SilverStripe\Core\Validation\ValidationResult;

/**
* A security group.
Expand Down Expand Up @@ -504,7 +505,7 @@ public function setCode($val)
$this->setField('Code', Convert::raw2url($val));
}

public function validate()
public function validate(): ValidationResult
{
$result = parent::validate();

Expand Down
2 changes: 1 addition & 1 deletion src/Security/Member.php
Original file line number Diff line number Diff line change
Expand Up @@ -1618,7 +1618,7 @@ public function canDelete($member = null)
/**
* Validate this member object.
*/
public function validate()
public function validate(): ValidationResult
{
// If validation is disabled, skip this step
if (!DataObject::config()->uninherited('validation_enabled')) {
Expand Down
3 changes: 2 additions & 1 deletion src/Security/PermissionRoleCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use SilverStripe\ORM\DataObject;
use SilverStripe\Security\PermissionRole;
use SilverStripe\Core\Validation\ValidationResult;

/**
* A PermissionRoleCode represents a single permission code assigned to a {@link PermissionRole}.
Expand All @@ -30,7 +31,7 @@ class PermissionRoleCode extends DataObject
"Code" => true,
];

public function validate()
public function validate(): ValidationResult
{
$result = parent::validate();

Expand Down
2 changes: 1 addition & 1 deletion tests/php/ORM/DataObjectTest/ValidatedObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ValidatedObject extends DataObject implements TestOnly
'Name' => 'Varchar(50)'
];

public function validate()
public function validate(): ValidationResult
{
$result = ValidationResult::create();
if (empty($this->Name)) {
Expand Down

0 comments on commit d033258

Please sign in to comment.