Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

FIX: Update class properties to use late static binding

  • Loading branch information...
commit 25f0c051ff4105197eca54115c28896b09a69506 1 parent a0187dc
@wilr wilr authored
View
1  .gitignore
@@ -0,0 +1 @@
+.DS_Store
View
0  code/MultiFormObjectDecorator.php → code/extensions/MultiFormObjectDecorator.php
File renamed without changes
View
17 code/MultiForm.php → code/model/MultiForm.php
@@ -7,8 +7,9 @@
*
* CAUTION: If you're using controller permission control,
* you have to allow the following methods:
+ *
* <code>
- * static $allowed_actions = array('next','prev');
+ * private static $allowed_actions = array('next','prev');
* </code>
*
* @package multiform
@@ -120,13 +121,7 @@ public function __construct($controller, $name) {
$validator = null;
$applyValidation = true;
- // Check if the $_REQUEST action that user clicked is an exempt one
- // if the Config class is available, use that instead of get_static() which is deprecated in SS 3.x
- if(class_exists('Config')) {
- $actionNames = Config::inst()->get(get_class($this), 'actions_exempt_from_validation', Config::FIRST_SET);
- } else {
- $actionNames = Object::get_static(get_class($this),'actions_exempt_from_validation');
- }
+ $actionNames = static::$actions_exempt_from_validation;
if( $actionNames ) {
foreach( $actionNames as $exemptAction) {
@@ -180,7 +175,7 @@ public function getController() {
* @return MultiFormStep subclass
*/
public function getCurrentStep() {
- $startStepClass = $this->stat('start_step');
+ $startStepClass = static::$start_step;
// Check if there was a start step defined on the subclass of MultiForm
if(!isset($startStepClass)) user_error('MultiForm::init(): Please define a $startStep on ' . $this->class, E_USER_ERROR);
@@ -498,7 +493,7 @@ protected function save($data) {
$currentStep = $this->getCurrentStep();
if(is_array($data)) {
foreach($data as $field => $value) {
- if(in_array($field, $this->stat('ignored_fields'))) {
+ if(in_array($field, static::$ignored_fields)) {
unset($data[$field]);
}
}
@@ -557,7 +552,7 @@ public function setDisplayLink($link) {
public function getAllStepsLinear() {
$stepsFound = (class_exists('ArrayList')) ? new ArrayList() : new DataObjectSet();
- $firstStep = DataObject::get_one($this->stat('start_step'), "\"SessionID\" = {$this->session->ID}");
+ $firstStep = DataObject::get_one(static::$start_step, "\"SessionID\" = {$this->session->ID}");
$firstStep->LinkingMode = ($firstStep->ID == $this->getCurrentStep()->ID) ? 'current' : 'link';
$firstStep->setForm($this);
$stepsFound->push($firstStep);
View
136 code/MultiFormSession.php → code/model/MultiFormSession.php
@@ -1,68 +1,68 @@
-<?php
-
-/**
- * Serializes one or more {@link MultiFormStep}s into
- * a database object.
- *
- * MultiFormSession also stores the current step, so that
- * the {@link MultiForm} and {@link MultiFormStep} classes
- * know what the current step is.
- *
- * @package multiform
- */
-class MultiFormSession extends DataObject {
-
- static $db = array(
- 'Hash' => 'Varchar(40)', // cryptographic hash identification to this session
- 'IsComplete' => 'Boolean' // flag to determine if this session is marked completed
- );
-
- static $has_one = array(
- 'Submitter' => 'Member',
- 'CurrentStep' => 'MultiFormStep'
- );
-
- static $has_many = array(
- 'FormSteps' => 'MultiFormStep'
- );
-
- /**
- * Mark this session as completed.
- *
- * This sets the flag "IsComplete" to true,
- * and writes the session back.
- */
- public function markCompleted() {
- $this->IsComplete = 1;
- $this->write();
- }
-
- /**
- * These actions are performed when write() is called on this object.
- */
- public function onBeforeWrite() {
- // save submitter if a Member is logged in
- $currentMember = Member::currentUser();
- if(!$this->SubmitterID && $currentMember) $this->SubmitterID = $currentMember->ID;
-
- parent::onBeforeWrite();
- }
-
- /**
- * These actions are performed when delete() is called on this object.
- */
- public function onBeforeDelete() {
- // delete dependent form steps and relation
- $steps = $this->FormSteps();
- if($steps) foreach($steps as $step) {
- if($step && $step->exists()) {
- $steps->remove($step);
- $step->delete();
- $step->destroy();
- }
- }
-
- parent::onBeforeDelete();
- }
-
-}
+<?php
+
+/**
+ * Serializes one or more {@link MultiFormStep}s into
+ * a database object.
+ *
+ * MultiFormSession also stores the current step, so that
+ * the {@link MultiForm} and {@link MultiFormStep} classes
+ * know what the current step is.
+ *
+ * @package multiform
+ */
+class MultiFormSession extends DataObject {
+
+ private static $db = array(
+ 'Hash' => 'Varchar(40)', // cryptographic hash identification to this session
+ 'IsComplete' => 'Boolean' // flag to determine if this session is marked completed
+ );
+
+ private static $has_one = array(
+ 'Submitter' => 'Member',
+ 'CurrentStep' => 'MultiFormStep'
+ );
+
+ private static $has_many = array(
+ 'FormSteps' => 'MultiFormStep'
+ );
+
+ /**
+ * Mark this session as completed.
+ *
+ * This sets the flag "IsComplete" to true,
+ * and writes the session back.
+ */
+ public function markCompleted() {
+ $this->IsComplete = 1;
+ $this->write();
+ }
+
+ /**
+ * These actions are performed when write() is called on this object.
+ */
+ public function onBeforeWrite() {
+ // save submitter if a Member is logged in
+ $currentMember = Member::currentUser();
+ if(!$this->SubmitterID && $currentMember) $this->SubmitterID = $currentMember->ID;
+
+ parent::onBeforeWrite();
+ }
+
+ /**
+ * These actions are performed when delete() is called on this object.
+ */
+ public function onBeforeDelete() {
+ // delete dependent form steps and relation
+ $steps = $this->FormSteps();
+ if($steps) foreach($steps as $step) {
+ if($step && $step->exists()) {
+ $steps->remove($step);
+ $step->delete();
+ $step->destroy();
+ }
+ }
+
+ parent::onBeforeDelete();
+ }
+
+}
View
15 code/MultiFormStep.php → code/model/MultiFormStep.php
@@ -11,11 +11,11 @@
*/
class MultiFormStep extends DataObject {
- static $db = array(
+ private static $db = array(
'Data' => 'Text' // stores serialized maps with all session information
);
- static $has_one = array(
+ private static $has_one = array(
'Session' => 'MultiFormSession'
);
@@ -204,7 +204,7 @@ public function validateStep($data, $form) {
* @return String Classname of a {@link MultiFormStep} subclass
*/
public function getNextStep() {
- $nextSteps = $this->stat('next_steps');
+ $nextSteps = static::$next_steps;
// Check if next_steps have been implemented properly if not the final step
if(!$this->isFinalStep()) {
@@ -231,7 +231,8 @@ public function getNextStep() {
*/
public function getNextStepFromDatabase() {
if($this->SessionID && is_numeric($this->SessionID)) {
- $nextSteps = $this->stat('next_steps');
+ $nextSteps = static::$next_steps;
+
if(is_string($nextSteps)) {
return DataObject::get_one($nextSteps, "\"SessionID\" = {$this->SessionID}");
} elseif(is_array($nextSteps)) {
@@ -248,7 +249,7 @@ public function getNextStepFromDatabase() {
* @return string|array
*/
public function getNextSteps() {
- return $this->stat('next_steps');
+ return static::$next_steps;
}
/**
@@ -336,7 +337,7 @@ public function getForm() {
* @return boolean
*/
public function canGoBack() {
- return $this->stat('can_go_back');
+ return static::$can_go_back;
}
/**
@@ -346,7 +347,7 @@ public function canGoBack() {
* @return boolean
*/
public function isFinalStep() {
- return $this->stat('is_final_step');
+ return static::$is_final_step;
}
/**
View
0  code/MultiFormPurgeTask.php → code/tasks/MultiFormPurgeTask.php
File renamed without changes
View
2  tests/MultiFormTest.php
@@ -99,7 +99,7 @@ class MultiFormTest_Form extends MultiForm implements TestOnly {
public static $start_step = 'MultiFormTest_StepOne';
function getStartStep() {
- return $this->stat('start_step');
+ return self::$start_step;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.