Christian Grobmeier wrote:
can we use LoggerReflectionUtils::createObject
instead of all those factory methods? Its duplicated code over all log4php,
so it makes sense to use it from one point.
Normally I would do something like this instead of using a separate factory method:

--- src/main/php/LoggerAppender.php    (revision 777996)
+++ src/main/php/LoggerAppender.php    (working copy)
@@ -108,7 +108,7 @@
        if(!empty($name)) {
            if(!isset($instances[$name])) {
                if(!empty($class)) {
-                    $appender = self::factory($name, $class);
+                    $appender = new $class($name);
                    if($appender !== null) {
                        $instances[$name] = $appender;
                        return $instances[$name];

Which is the fastest way ;)

But if you need to apply some more logic in order to create the instance either LoggerReflectionUtils::createObject() (as a general mechanism) or a specific implementation that deals with only LoggerAppender-specific stuff in LoggerAppender::factory() is valid options. Currently both implementations looks the same, but typically in this case you would like to limit which classes can be instantiated (only instanceof LoggerAppender) which is logic that resides in a LoggerAppender::factory() method.

Just some thoughts around this :)

Knut

Reply via email to