API make DataObject::validate public

This commit is contained in:
Damian Mooyman 2015-06-17 15:51:30 +12:00
parent 0103b076c3
commit 55170a0b74
9 changed files with 12 additions and 12 deletions

View File

@ -917,7 +917,7 @@ class File extends DataObject {
return $labels; return $labels;
} }
protected function validate() { public function validate() {
if($this->config()->apply_restrictions_to_admin || !Permission::check('ADMIN')) { if($this->config()->apply_restrictions_to_admin || !Permission::check('ADMIN')) {
// Extension validation // Extension validation
// TODO Merge this with Upload_Validator // TODO Merge this with Upload_Validator

View File

@ -326,7 +326,7 @@ class Folder extends File {
} }
} }
protected function validate() { public function validate() {
return new ValidationResult(true); return new ValidationResult(true);
} }

View File

@ -919,7 +919,7 @@ class FormField extends RequestHandler {
* Validation method each {@link FormField} subclass should implement, * Validation method each {@link FormField} subclass should implement,
* determining whether the field is valid or not based on the value. * determining whether the field is valid or not based on the value.
* *
* @param Validator $validator * @param Validator
* @return boolean * @return boolean
*/ */
public function validate($validator) { public function validate($validator) {

View File

@ -1063,7 +1063,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
* @see {@link ValidationResult} * @see {@link ValidationResult}
* @return ValidationResult * @return ValidationResult
*/ */
protected function validate() { public function validate() {
$result = ValidationResult::create(); $result = ValidationResult::create();
$this->extend('validate', $result); $this->extend('validate', $result);
return $result; return $result;
@ -1075,7 +1075,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
* @return ValidationResult * @return ValidationResult
*/ */
public function doValidate() { public function doValidate() {
// validate will be public in 4.0 Deprecation::notice('5.0', 'Use validate');
return $this->validate(); return $this->validate();
} }

View File

@ -336,7 +336,7 @@ class Group extends DataObject {
$this->setField("Code", Convert::raw2url($val)); $this->setField("Code", Convert::raw2url($val));
} }
protected function validate() { public function validate() {
$result = parent::validate(); $result = parent::validate();
// Check if the new group hierarchy would add certain "privileged permissions", // Check if the new group hierarchy would add certain "privileged permissions",

View File

@ -1487,7 +1487,7 @@ class Member extends DataObject implements TemplateGlobalProvider {
/** /**
* Validate this member object. * Validate this member object.
*/ */
protected function validate() { public function validate() {
$valid = parent::validate(); $valid = parent::validate();
if(!$this->ID || $this->isChanged('Password')) { if(!$this->ID || $this->isChanged('Password')) {

View File

@ -20,7 +20,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

@ -103,18 +103,18 @@ class FileTest extends SapphireTest {
// Invalid ext // Invalid ext
$file->Name = 'asdf.php'; $file->Name = 'asdf.php';
$v = $file->doValidate(); $v = $file->validate();
$this->assertFalse($v->valid()); $this->assertFalse($v->valid());
$this->assertContains('Extension is not allowed', $v->message()); $this->assertContains('Extension is not allowed', $v->message());
// Valid ext // Valid ext
$file->Name = 'asdf.txt'; $file->Name = 'asdf.txt';
$v = $file->doValidate(); $v = $file->validate();
$this->assertTrue($v->valid()); $this->assertTrue($v->valid());
// Capital extension is valid as well // Capital extension is valid as well
$file->Name = 'asdf.TXT'; $file->Name = 'asdf.TXT';
$v = $file->doValidate(); $v = $file->validate();
$this->assertTrue($v->valid()); $this->assertTrue($v->valid());
Config::inst()->remove('File', 'allowed_extensions'); Config::inst()->remove('File', 'allowed_extensions');

View File

@ -1821,7 +1821,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 {