From 55fda28f9b524caf93fc9dbd92d700faee9a6c6e Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Tue, 27 Sep 2022 10:19:41 +1300 Subject: [PATCH] API Don't publicly expose extension hook methods --- src/Dev/Validation/DatabaseAdminExtension.php | 2 +- src/ORM/DataExtension.php | 44 +++++++++---------- src/ORM/Hierarchy/Hierarchy.php | 2 +- .../ControllerExtension.php | 4 +- tests/php/Core/ObjectTest/ExtendTest1.php | 2 +- tests/php/Core/ObjectTest/ExtendTest2.php | 2 +- tests/php/Core/ObjectTest/ExtendTest3.php | 2 +- .../FormFactoryTest/ControllerExtension.php | 4 +- .../php/Forms/FormFieldTest/TestExtension.php | 2 +- .../FormScaffolderTest/ArticleExtension.php | 2 +- .../GridFieldTest/StadiumExtension.php | 2 +- .../CMSFieldsBaseExtension.php | 2 +- .../php/ORM/DataExtensionTest/Extension1.php | 6 +-- .../php/ORM/DataExtensionTest/Extension2.php | 6 +-- .../php/ORM/DataObjectTest/Team_Extension.php | 2 +- .../MemberTest/AlwaysFailExtension.php | 2 +- .../EditingAllowedDeletingDeniedExtension.php | 6 +-- .../ExtendedChangePasswordExtension.php | 2 +- .../Security/MemberTest/FieldsExtension.php | 2 +- .../SurnameMustMatchFirstNameExtension.php | 2 +- .../MemberTest/ViewingAllowedExtension.php | 2 +- .../MemberTest/ViewingDeniedExtension.php | 2 +- 22 files changed, 51 insertions(+), 51 deletions(-) diff --git a/src/Dev/Validation/DatabaseAdminExtension.php b/src/Dev/Validation/DatabaseAdminExtension.php index e8abf24df80..7d0e6a344b5 100644 --- a/src/Dev/Validation/DatabaseAdminExtension.php +++ b/src/Dev/Validation/DatabaseAdminExtension.php @@ -21,7 +21,7 @@ class DatabaseAdminExtension extends Extension * @param bool $testMode * @throws ReflectionException */ - public function onAfterBuild(bool $quiet, bool $populate, bool $testMode): void + protected function onAfterBuild(bool $quiet, bool $populate, bool $testMode): void { $service = RelationValidationService::singleton(); diff --git a/src/ORM/DataExtension.php b/src/ORM/DataExtension.php index ea4cbabff00..dd8630c6ced 100644 --- a/src/ORM/DataExtension.php +++ b/src/ORM/DataExtension.php @@ -32,7 +32,7 @@ public static function unload_extra_statics($class, $extension) * @param ValidationResult $validationResult Local validation result * @throws ValidationException */ - public function validate(ValidationResult $validationResult) + protected function validate(ValidationResult $validationResult) { } @@ -42,7 +42,7 @@ public function validate(ValidationResult $validationResult) * @param SQLSelect $query Query to augment. * @param DataQuery $dataQuery Container DataQuery for this SQLSelect */ - public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) + protected function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) { } @@ -52,7 +52,7 @@ public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) * When duplicating a table's structure, remember to duplicate the create options * as well. See {@link Versioned->augmentDatabase} for an example. */ - public function augmentDatabase() + protected function augmentDatabase() { } @@ -61,7 +61,7 @@ public function augmentDatabase() * * @param array $manipulation Array of operations to augment. */ - public function augmentWrite(&$manipulation) + protected function augmentWrite(&$manipulation) { } @@ -70,7 +70,7 @@ public function augmentWrite(&$manipulation) * * See {@link DataObject::onBeforeWrite()} for context. */ - public function onBeforeWrite() + protected function onBeforeWrite() { } @@ -79,7 +79,7 @@ public function onBeforeWrite() * * See {@link DataObject::onAfterWrite()} for context. */ - public function onAfterWrite() + protected function onAfterWrite() { } @@ -88,7 +88,7 @@ public function onAfterWrite() * * See {@link DataObject::onBeforeDelete()} for context. */ - public function onBeforeDelete() + protected function onBeforeDelete() { } @@ -97,7 +97,7 @@ public function onBeforeDelete() * * See {@link DataObject::onAfterDelete()} for context. */ - public function onAfterDelete() + protected function onAfterDelete() { } @@ -106,7 +106,7 @@ public function onAfterDelete() * * See {@link DataObject::requireDefaultRecords()} for context. */ - public function requireDefaultRecords() + protected function requireDefaultRecords() { } @@ -115,7 +115,7 @@ public function requireDefaultRecords() * * See {@link DataObject::populateDefaults()} for context. */ - public function populateDefaults() + protected function populateDefaults() { } @@ -124,7 +124,7 @@ public function populateDefaults() * * See {@link DataObject::onAfterBuild()} for context. */ - public function onAfterBuild() + protected function onAfterBuild() { } @@ -138,7 +138,7 @@ public function onAfterBuild() * @param Member $member * @return bool|null */ - public function can($member) + protected function can($member) { } @@ -152,7 +152,7 @@ public function can($member) * @param Member $member * @return bool|null */ - public function canEdit($member) + protected function canEdit($member) { } @@ -166,7 +166,7 @@ public function canEdit($member) * @param Member $member * @return bool|null */ - public function canDelete($member) + protected function canDelete($member) { } @@ -180,7 +180,7 @@ public function canDelete($member) * @param Member $member * @return bool|null */ - public function canCreate($member) + protected function canCreate($member) { } @@ -195,7 +195,7 @@ public function canCreate($member) * @return array Returns a map where the keys are db, has_one, etc, and * the values are additional fields/relations to be defined. */ - public function extraStatics($class = null, $extension = null) + protected function extraStatics($class = null, $extension = null) { return []; } @@ -213,7 +213,7 @@ public function extraStatics($class = null, $extension = null) * * @param FieldList $fields FieldList with a contained TabSet */ - public function updateCMSFields(FieldList $fields) + protected function updateCMSFields(FieldList $fields) { } @@ -224,7 +224,7 @@ public function updateCMSFields(FieldList $fields) * * @param CompositeValidator $compositeValidator */ - public function updateCMSCompositeValidator(CompositeValidator $compositeValidator): void + protected function updateCMSCompositeValidator(CompositeValidator $compositeValidator): void { } @@ -236,7 +236,7 @@ public function updateCMSCompositeValidator(CompositeValidator $compositeValidat * * @param FieldList $fields FieldList without TabSet nesting */ - public function updateFrontEndFields(FieldList $fields) + protected function updateFrontEndFields(FieldList $fields) { } @@ -246,7 +246,7 @@ public function updateFrontEndFields(FieldList $fields) * * @param FieldList $actions FieldList */ - public function updateCMSActions(FieldList $actions) + protected function updateCMSActions(FieldList $actions) { } @@ -258,7 +258,7 @@ public function updateCMSActions(FieldList $actions) * * @param array $fields Array of field names */ - public function updateSummaryFields(&$fields) + protected function updateSummaryFields(&$fields) { $summary_fields = Config::inst()->get(static::class, 'summary_fields'); if ($summary_fields) { @@ -281,7 +281,7 @@ public function updateSummaryFields(&$fields) * * @param array $labels Array of field labels */ - public function updateFieldLabels(&$labels) + protected function updateFieldLabels(&$labels) { $field_labels = Config::inst()->get(static::class, 'field_labels'); if ($field_labels) { diff --git a/src/ORM/Hierarchy/Hierarchy.php b/src/ORM/Hierarchy/Hierarchy.php index e1c4bb42fd5..2e523befad7 100644 --- a/src/ORM/Hierarchy/Hierarchy.php +++ b/src/ORM/Hierarchy/Hierarchy.php @@ -116,7 +116,7 @@ public static function get_extra_config($class, $extension, $args) * * @param ValidationResult $validationResult */ - public function validate(ValidationResult $validationResult) + protected function validate(ValidationResult $validationResult) { // The object is new, won't be looping. /** @var DataObject|Hierarchy $owner */ diff --git a/tests/php/Control/RequestHandlingTest/ControllerExtension.php b/tests/php/Control/RequestHandlingTest/ControllerExtension.php index 44c849a5118..0ec56f68551 100644 --- a/tests/php/Control/RequestHandlingTest/ControllerExtension.php +++ b/tests/php/Control/RequestHandlingTest/ControllerExtension.php @@ -25,7 +25,7 @@ public function extendedMethod() /** * Called whenever there is an HTTP error */ - public function onBeforeHTTPError() + protected function onBeforeHTTPError() { self::$called_error = true; } @@ -33,7 +33,7 @@ public function onBeforeHTTPError() /** * Called whenever there is an 404 error */ - public function onBeforeHTTPError404() + protected function onBeforeHTTPError404() { self::$called_404_error = true; } diff --git a/tests/php/Core/ObjectTest/ExtendTest1.php b/tests/php/Core/ObjectTest/ExtendTest1.php index b33ce847657..49695a3e57b 100644 --- a/tests/php/Core/ObjectTest/ExtendTest1.php +++ b/tests/php/Core/ObjectTest/ExtendTest1.php @@ -7,7 +7,7 @@ class ExtendTest1 extends Extension implements TestOnly { - public function extendableMethod(&$argument = null) + protected function extendableMethod(&$argument = null) { if ($argument) { $argument = 'modified'; diff --git a/tests/php/Core/ObjectTest/ExtendTest2.php b/tests/php/Core/ObjectTest/ExtendTest2.php index 78326d76afc..0007aea10e4 100644 --- a/tests/php/Core/ObjectTest/ExtendTest2.php +++ b/tests/php/Core/ObjectTest/ExtendTest2.php @@ -15,7 +15,7 @@ public function __construct() $this->constructorArgs = func_get_args(); } - public function extendableMethod($argument = null) + protected function extendableMethod($argument = null) { $args = implode(',', array_filter(func_get_args())); return "ExtendTest2($args)"; diff --git a/tests/php/Core/ObjectTest/ExtendTest3.php b/tests/php/Core/ObjectTest/ExtendTest3.php index d4d0c66e41a..31aafb64176 100644 --- a/tests/php/Core/ObjectTest/ExtendTest3.php +++ b/tests/php/Core/ObjectTest/ExtendTest3.php @@ -15,7 +15,7 @@ public function __construct() $this->constructorArgs = func_get_args(); } - public function extendableMethod($argument = null) + protected function extendableMethod($argument = null) { return "ExtendTest3($argument)"; } diff --git a/tests/php/Forms/FormFactoryTest/ControllerExtension.php b/tests/php/Forms/FormFactoryTest/ControllerExtension.php index 49ba30dfec7..984261b4fea 100644 --- a/tests/php/Forms/FormFactoryTest/ControllerExtension.php +++ b/tests/php/Forms/FormFactoryTest/ControllerExtension.php @@ -35,7 +35,7 @@ class ControllerExtension extends Extension * @param string $name * @param array $context */ - public function updateFormActions(FieldList &$actions, Controller $controller, $name, $context = []) + protected function updateFormActions(FieldList &$actions, Controller $controller, $name, $context = []) { // Add publish button if record is versioned if (empty($context['Record'])) { @@ -56,7 +56,7 @@ public function updateFormActions(FieldList &$actions, Controller $controller, $ * @param string $name * @param array $context */ - public function updateFormFields(FieldList &$fields, Controller $controller, $name, $context = []) + protected function updateFormFields(FieldList &$fields, Controller $controller, $name, $context = []) { // Add preview link if (empty($context['Record'])) { diff --git a/tests/php/Forms/FormFieldTest/TestExtension.php b/tests/php/Forms/FormFieldTest/TestExtension.php index 2cd126acd2d..13baa5a9d3b 100644 --- a/tests/php/Forms/FormFieldTest/TestExtension.php +++ b/tests/php/Forms/FormFieldTest/TestExtension.php @@ -8,7 +8,7 @@ class TestExtension extends Extension implements TestOnly { - public function updateAttributes(&$attrs) + protected function updateAttributes(&$attrs) { $attrs['extended'] = true; } diff --git a/tests/php/Forms/FormScaffolderTest/ArticleExtension.php b/tests/php/Forms/FormScaffolderTest/ArticleExtension.php index fcb01658e9b..d8ff910d8dd 100644 --- a/tests/php/Forms/FormScaffolderTest/ArticleExtension.php +++ b/tests/php/Forms/FormScaffolderTest/ArticleExtension.php @@ -13,7 +13,7 @@ class ArticleExtension extends DataExtension implements TestOnly 'ExtendedField' => 'Varchar' ]; - public function updateCMSFields(FieldList $fields) + protected function updateCMSFields(FieldList $fields) { $fields->addFieldToTab( 'Root.Main', diff --git a/tests/php/Forms/GridField/GridFieldTest/StadiumExtension.php b/tests/php/Forms/GridField/GridFieldTest/StadiumExtension.php index 90bba94719c..c441478c7e8 100644 --- a/tests/php/Forms/GridField/GridFieldTest/StadiumExtension.php +++ b/tests/php/Forms/GridField/GridFieldTest/StadiumExtension.php @@ -9,7 +9,7 @@ class StadiumExtension extends DataExtension implements TestOnly { - public function updateSearchableFields(&$fields) + protected function updateSearchableFields(&$fields) { $fields['Type']['filter'] = new FulltextFilter(); } diff --git a/tests/php/ORM/DataExtensionTest/CMSFieldsBaseExtension.php b/tests/php/ORM/DataExtensionTest/CMSFieldsBaseExtension.php index 1b36a1527f3..44b3c1fae2b 100644 --- a/tests/php/ORM/DataExtensionTest/CMSFieldsBaseExtension.php +++ b/tests/php/ORM/DataExtensionTest/CMSFieldsBaseExtension.php @@ -17,7 +17,7 @@ class CMSFieldsBaseExtension extends DataExtension implements TestOnly 'ExtendedFieldRemove' => 'Varchar(255)' ]; - public function updateCMSFields(FieldList $fields) + protected function updateCMSFields(FieldList $fields) { $fields->addFieldToTab('Root.Test', new TextField('ExtendedFieldRemove')); $fields->addFieldToTab('Root.Test', new TextField('ExtendedFieldKeep')); diff --git a/tests/php/ORM/DataExtensionTest/Extension1.php b/tests/php/ORM/DataExtensionTest/Extension1.php index 010e3a863e2..1b9fb62ae20 100644 --- a/tests/php/ORM/DataExtensionTest/Extension1.php +++ b/tests/php/ORM/DataExtensionTest/Extension1.php @@ -8,17 +8,17 @@ class Extension1 extends DataExtension implements TestOnly { - public function canOne($member = null) + protected function canOne($member = null) { return true; } - public function canTwo($member = null) + protected function canTwo($member = null) { return false; } - public function canThree($member = null) + protected function canThree($member = null) { } } diff --git a/tests/php/ORM/DataExtensionTest/Extension2.php b/tests/php/ORM/DataExtensionTest/Extension2.php index c37e37d13a0..10f964a0f0c 100644 --- a/tests/php/ORM/DataExtensionTest/Extension2.php +++ b/tests/php/ORM/DataExtensionTest/Extension2.php @@ -8,17 +8,17 @@ class Extension2 extends DataExtension implements TestOnly { - public function canOne($member = null) + protected function canOne($member = null) { return true; } - public function canTwo($member = null) + protected function canTwo($member = null) { return true; } - public function canThree($member = null) + protected function canThree($member = null) { } } diff --git a/tests/php/ORM/DataObjectTest/Team_Extension.php b/tests/php/ORM/DataObjectTest/Team_Extension.php index 1129b61f023..1dbb44d6251 100644 --- a/tests/php/ORM/DataObjectTest/Team_Extension.php +++ b/tests/php/ORM/DataObjectTest/Team_Extension.php @@ -24,7 +24,7 @@ public function getExtendedDynamicField() return "extended dynamic field"; } - public function augmentHydrateFields() + protected function augmentHydrateFields() { return [ 'CustomHydratedField' => true, diff --git a/tests/php/Security/MemberTest/AlwaysFailExtension.php b/tests/php/Security/MemberTest/AlwaysFailExtension.php index db018880ff3..fab76a4f01e 100644 --- a/tests/php/Security/MemberTest/AlwaysFailExtension.php +++ b/tests/php/Security/MemberTest/AlwaysFailExtension.php @@ -10,7 +10,7 @@ */ class AlwaysFailExtension extends DataExtension implements TestOnly { - public function updatePHP($data, $form) + protected function updatePHP($data, $form) { return false; } diff --git a/tests/php/Security/MemberTest/EditingAllowedDeletingDeniedExtension.php b/tests/php/Security/MemberTest/EditingAllowedDeletingDeniedExtension.php index ac61a60ca15..6afd5185a04 100644 --- a/tests/php/Security/MemberTest/EditingAllowedDeletingDeniedExtension.php +++ b/tests/php/Security/MemberTest/EditingAllowedDeletingDeniedExtension.php @@ -8,17 +8,17 @@ class EditingAllowedDeletingDeniedExtension extends DataExtension implements TestOnly { - public function canView($member = null) + protected function canView($member = null) { return true; } - public function canEdit($member = null) + protected function canEdit($member = null) { return true; } - public function canDelete($member = null) + protected function canDelete($member = null) { return false; } diff --git a/tests/php/Security/MemberTest/ExtendedChangePasswordExtension.php b/tests/php/Security/MemberTest/ExtendedChangePasswordExtension.php index fb25e467b21..20542633e70 100644 --- a/tests/php/Security/MemberTest/ExtendedChangePasswordExtension.php +++ b/tests/php/Security/MemberTest/ExtendedChangePasswordExtension.php @@ -11,7 +11,7 @@ */ class ExtendedChangePasswordExtension extends DataExtension implements TestOnly { - public function onBeforeChangePassword($newPassword, $valid) + protected function onBeforeChangePassword($newPassword, $valid) { $valid->addError('Extension failed to handle Mary changing her password'); } diff --git a/tests/php/Security/MemberTest/FieldsExtension.php b/tests/php/Security/MemberTest/FieldsExtension.php index 5c228434e36..425c83f7140 100644 --- a/tests/php/Security/MemberTest/FieldsExtension.php +++ b/tests/php/Security/MemberTest/FieldsExtension.php @@ -9,7 +9,7 @@ class FieldsExtension extends DataExtension implements TestOnly { - public function updateCMSFields(FieldList $fields) + protected function updateCMSFields(FieldList $fields) { $fields->addFieldToTab('Root.Main', new TextField('TestMemberField', 'Test')); } diff --git a/tests/php/Security/MemberTest/SurnameMustMatchFirstNameExtension.php b/tests/php/Security/MemberTest/SurnameMustMatchFirstNameExtension.php index 720d482f47c..7f0a4a1de63 100644 --- a/tests/php/Security/MemberTest/SurnameMustMatchFirstNameExtension.php +++ b/tests/php/Security/MemberTest/SurnameMustMatchFirstNameExtension.php @@ -10,7 +10,7 @@ */ class SurnameMustMatchFirstNameExtension extends DataExtension implements TestOnly { - public function updatePHP($data, $form) + protected function updatePHP($data, $form) { return $data['FirstName'] == $data['Surname']; } diff --git a/tests/php/Security/MemberTest/ViewingAllowedExtension.php b/tests/php/Security/MemberTest/ViewingAllowedExtension.php index e941dd472e0..b71ccbfae92 100644 --- a/tests/php/Security/MemberTest/ViewingAllowedExtension.php +++ b/tests/php/Security/MemberTest/ViewingAllowedExtension.php @@ -8,7 +8,7 @@ class ViewingAllowedExtension extends DataExtension implements TestOnly { - public function canView($member = null) + protected function canView($member = null) { return true; } diff --git a/tests/php/Security/MemberTest/ViewingDeniedExtension.php b/tests/php/Security/MemberTest/ViewingDeniedExtension.php index 82089daaaf4..35ef55db174 100644 --- a/tests/php/Security/MemberTest/ViewingDeniedExtension.php +++ b/tests/php/Security/MemberTest/ViewingDeniedExtension.php @@ -8,7 +8,7 @@ class ViewingDeniedExtension extends DataExtension implements TestOnly { - public function canView($member = null) + protected function canView($member = null) { return false; }