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.
This commit is contained in:
Sean Harvey 2013-12-19 16:27:54 +13:00
parent d5179adb01
commit 6fc9db6f0e
4 changed files with 21 additions and 4 deletions

View File

@ -3,7 +3,24 @@
## Overview ## Overview
* Minimum PHP version raised to 5.3.3 * Minimum PHP version raised to 5.3.3
* DataObject::validate() method visibility changed to public
## Changelog ## Changelog
### 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 ### Bugfixes

View File

@ -1015,7 +1015,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
* *
* @return A {@link ValidationResult} object * @return A {@link ValidationResult} object
*/ */
protected function validate() { public function validate() {
$result = ValidationResult::create(); $result = ValidationResult::create();
$this->extend('validate', $result); $this->extend('validate', $result);
return $result; return $result;

View File

@ -14,7 +14,7 @@ class PermissionRoleCode extends DataObject {
"Role" => "PermissionRole", "Role" => "PermissionRole",
); );
protected function validate() { public function validate() {
$result = parent::validate(); $result = parent::validate();
// Check that new code doesn't increase privileges, unless an admin is editing. // Check that new code doesn't increase privileges, unless an admin is editing.

View File

@ -1304,7 +1304,7 @@ class DataObjectTest_ValidatedObject extends DataObject implements TestOnly {
'Name' => 'Varchar(50)' 'Name' => 'Varchar(50)'
); );
protected function validate() { public function validate() {
if(!empty($this->Name)) { if(!empty($this->Name)) {
return new ValidationResult(); return new ValidationResult();
} else { } else {