From 2bea1f390ffd33ce4b23204f3c227cda4caca505 Mon Sep 17 00:00:00 2001 From: Trismegiste Date: Fri, 10 May 2013 19:50:13 +0200 Subject: [PATCH] PSR-0 for Static Factory --- StaticFactory/FormatNumber.php | 8 ++++++++ StaticFactory/FormatString.php | 8 ++++++++ StaticFactory/Formatter.php | 8 ++++++++ StaticFactory/StaticFactory.php | 30 ++++++++++-------------------- 4 files changed, 34 insertions(+), 20 deletions(-) create mode 100644 StaticFactory/FormatNumber.php create mode 100644 StaticFactory/FormatString.php create mode 100644 StaticFactory/Formatter.php diff --git a/StaticFactory/FormatNumber.php b/StaticFactory/FormatNumber.php new file mode 100644 index 0000000..f7bf851 --- /dev/null +++ b/StaticFactory/FormatNumber.php @@ -0,0 +1,8 @@ + global => evil + * Note2: Cannot be subclassed or mock-uped or have multiple different instances */ -class FactoryMethod +class StaticFactory { + /** * the parametrized function to get create an instance * @@ -24,26 +27,13 @@ class FactoryMethod */ public static function factory($type) { - $className = 'Format' . ucfirst($type); - if ( ! class_exists($className)) { - throw new Exception('Missing format class.'); + $className = __NAMESPACE__ . '\Format' . ucfirst($type); + + if (!class_exists($className)) { + throw new \InvalidArgumentException('Missing format class.'); } return new $className(); } -} - -interface Formatter -{ } - -class FormatString implements Formatter -{ - -} - -class FormatNumber implements Formatter -{ - -}