From 6fc9db6f0e87fe935ccb46daff880158453ad04b Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Thu, 19 Dec 2013 16:27:54 +1300 Subject: [PATCH] API DataObject::validate() visibility changed to public (issue #1659) DataObject::validate() is currently set to protected, but this means you can't call validate() from outside the context of itself unless you overload the method to use a public visibility and then call parent::validate() As it would turn out, most classes that overload this method already set the visibility to public, so it would make sense the parent matches that as well. --- docs/en/changelogs/3.2.0.md | 19 ++++++++++++++++++- model/DataObject.php | 2 +- security/PermissionRoleCode.php | 2 +- tests/model/DataObjectTest.php | 2 +- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/docs/en/changelogs/3.2.0.md b/docs/en/changelogs/3.2.0.md index 0300a06f4..941e0d089 100644 --- a/docs/en/changelogs/3.2.0.md +++ b/docs/en/changelogs/3.2.0.md @@ -3,7 +3,24 @@ ## Overview * Minimum PHP version raised to 5.3.3 + * DataObject::validate() method visibility changed to public ## Changelog -### Bugfixes \ No newline at end of file +### DataObject::validate() method visibility changed to public + +The visibility of `DataObject::validate()` has been changed from `protected` to `public`. + +Any existing classes that currently set this as `protected` should be changed like in +this example: + + ::php + class MyDataClass extends DataObject { + ... + public function validate() { + ... + } + ... + } + +### Bugfixes diff --git a/model/DataObject.php b/model/DataObject.php index b01621d14..04d06634c 100644 --- a/model/DataObject.php +++ b/model/DataObject.php @@ -1015,7 +1015,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity * * @return A {@link ValidationResult} object */ - protected function validate() { + public function validate() { $result = ValidationResult::create(); $this->extend('validate', $result); return $result; diff --git a/security/PermissionRoleCode.php b/security/PermissionRoleCode.php index ffd911839..eac50f061 100644 --- a/security/PermissionRoleCode.php +++ b/security/PermissionRoleCode.php @@ -14,7 +14,7 @@ class PermissionRoleCode extends DataObject { "Role" => "PermissionRole", ); - protected function validate() { + public function validate() { $result = parent::validate(); // Check that new code doesn't increase privileges, unless an admin is editing. diff --git a/tests/model/DataObjectTest.php b/tests/model/DataObjectTest.php index 7f5688a40..f02b35cb1 100644 --- a/tests/model/DataObjectTest.php +++ b/tests/model/DataObjectTest.php @@ -1304,7 +1304,7 @@ class DataObjectTest_ValidatedObject extends DataObject implements TestOnly { 'Name' => 'Varchar(50)' ); - protected function validate() { + public function validate() { if(!empty($this->Name)) { return new ValidationResult(); } else {