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:
authordiosmosis <benakamoorthi@fastmail.fm>2014-08-20 12:13:04 +0400
committerdiosmosis <benakamoorthi@fastmail.fm>2014-08-20 12:21:07 +0400
commit34904e642034d10b728b429dcb213344a0157e74 (patch)
treeec2b732fe86e4720c328b13bc75e3d54949edc7c /plugins/ImageGraph
parentca0bdf191bf1ab85525169242cbfef754855dfec (diff)
Refactor factory methods into base Factory type for ease of testing.
Diffstat (limited to 'plugins/ImageGraph')
-rw-r--r--plugins/ImageGraph/StaticGraph.php34
1 files changed, 13 insertions, 21 deletions
diff --git a/plugins/ImageGraph/StaticGraph.php b/plugins/ImageGraph/StaticGraph.php
index e98b8bda28..8adef6e411 100644
--- a/plugins/ImageGraph/StaticGraph.php
+++ b/plugins/ImageGraph/StaticGraph.php
@@ -14,6 +14,7 @@ use pData;
use pImage;
use Piwik\Piwik;
use Piwik\SettingsPiwik;
+use Piwik\Factory;
require_once PIWIK_INCLUDE_PATH . "/libs/pChart2.1.3/class/pDraw.class.php";
require_once PIWIK_INCLUDE_PATH . "/libs/pChart2.1.3/class/pImage.class.php";
@@ -23,7 +24,7 @@ require_once PIWIK_INCLUDE_PATH . "/libs/pChart2.1.3/class/pData.class.php";
* The StaticGraph abstract class is used as a base class for different types of static graphs.
*
*/
-abstract class StaticGraph
+abstract class StaticGraph extends Factory
{
const GRAPH_TYPE_BASIC_LINE = "evolution";
const GRAPH_TYPE_VERTICAL_BAR = "verticalBar";
@@ -72,28 +73,19 @@ abstract class StaticGraph
abstract public function renderGraph();
- /**
- * Return the StaticGraph according to the static graph type $graphType
- *
- * @throws Exception If the static graph type is unknown
- * @param string $graphType
- * @return \Piwik\Plugins\ImageGraph\StaticGraph
- */
- public static function factory($graphType)
+ protected static function getClassNameFromClassId($graphType)
{
- if (isset(self::$availableStaticGraphTypes[$graphType])) {
+ $className = self::$availableStaticGraphTypes[$graphType];
+ $className = __NAMESPACE__ . "\\StaticGraph\\" . $className;
+ return new $className;
+ }
- $className = self::$availableStaticGraphTypes[$graphType];
- $className = __NAMESPACE__ . "\\StaticGraph\\" . $className;
- return new $className;
- } else {
- throw new Exception(
- Piwik::translate(
- 'General_ExceptionInvalidStaticGraphType',
- array($graphType, implode(', ', self::getAvailableStaticGraphTypes()))
- )
- );
- }
+ protected static function getInvalidClassIdExceptionMessage($graphType)
+ {
+ return Piwik::translate(
+ 'General_ExceptionInvalidStaticGraphType',
+ array($graphType, implode(', ', self::getAvailableStaticGraphTypes()))
+ );
}
public static function getAvailableStaticGraphTypes()