Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormattab <matthieu.aubry@gmail.com>2015-07-01 14:20:58 +0300
committermattab <matthieu.aubry@gmail.com>2015-07-01 14:20:58 +0300
commit0a703d6133402db08d5d42758b488d548985baee (patch)
treeb856eaedfd2814973f12e267d975513b49fe3dc5 /core/Plugin/ViewDataTable.php
parent33c66ba872a12458efe47f2575fc13873eba926d (diff)
Display a meaningful & useful error message when setting viewDataTable parameters, rather than silently fail
Diffstat (limited to 'core/Plugin/ViewDataTable.php')
-rw-r--r--core/Plugin/ViewDataTable.php42
1 files changed, 42 insertions, 0 deletions
diff --git a/core/Plugin/ViewDataTable.php b/core/Plugin/ViewDataTable.php
index eb733265ff..6e190388b6 100644
--- a/core/Plugin/ViewDataTable.php
+++ b/core/Plugin/ViewDataTable.php
@@ -514,4 +514,46 @@ abstract class ViewDataTable implements ViewInterface
}
}
}
+
+ /**
+ * Display a meaningful error message when any invalid parameter is being set.
+ *
+ * @param $overrideParams
+ * @throws
+ */
+ public function throwWhenSettingNonOverridableParameter($overrideParams)
+ {
+ $nonOverridableParams = $this->getNonOverridableParams($overrideParams);
+ if(count($nonOverridableParams) > 0) {
+ throw new \Exception(sprintf(
+ "Setting parameters %s is not allowed. Please report this bug to the Piwik team.",
+ implode(" and ", $nonOverridableParams)
+ ));
+ }
+ }
+
+ /**
+ * @param $overrideParams
+ * @return array
+ */
+ public function getNonOverridableParams($overrideParams)
+ {
+ $paramsCannotBeOverridden = array();
+ foreach ($overrideParams as $paramName => $paramValue) {
+ if (property_exists($this->requestConfig, $paramName)) {
+ $allowedParams = $this->requestConfig->overridableProperties;
+ } elseif (property_exists($this->config, $paramName)) {
+ $allowedParams = $this->config->overridableProperties;
+ } else {
+ // setting Config.custom_parameters is always allowed
+ continue;
+ }
+
+ if (!in_array($paramName, $allowedParams)) {
+ $paramsCannotBeOverridden[] = $paramName;
+ }
+ }
+ return $paramsCannotBeOverridden;
+ }
+
}