Procházet zdrojové kódy

[REVIEW] CS fixes to Zend_Log::factory

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@19548 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew před 16 roky
rodič
revize
1b986d95fa

+ 15 - 16
library/Zend/Log.php

@@ -90,7 +90,7 @@ class Zend_Log
      * Factory to construct the logger and one or more writers
      * based on the configuration array
      *
-     * @param mixed Array or instance of Zend_Config
+     * @param  array|Zend_Config Array or instance of Zend_Config
      * @return Zend_Log
      */
     static public function factory($config = array())
@@ -108,9 +108,7 @@ class Zend_Log
         
         if (!is_array(current($config))) {
             $log->addWriter(current($config));
-
         } else {
-
             foreach($config as $writer) {
                 $log->addWriter($writer);
             }
@@ -123,14 +121,14 @@ class Zend_Log
     /**
      * Construct a writer object based on a configuration array
      *
-     * @param array $spec config array with writer spec
+     * @param  array $spec config array with writer spec
      * @return Zend_Log_Writer_Abstract
      */
     protected function _constructWriterFromConfig($config)
     {
         $writer = $this->_constructFromConfig('writer', $config, $this->_defaultWriterNamespace);
 
-        if (! $writer instanceof Zend_Log_Writer_Abstract) {
+        if (!$writer instanceof Zend_Log_Writer_Abstract) {
             require_once 'Zend/Log/Exception.php';
             throw new Zend_Log_Exception("{$writerName} does not extend Zend_Log_Writer_Abstract!");
         }
@@ -146,14 +144,14 @@ class Zend_Log
     /**
      * Construct filter object from configuration array or Zend_Config object
      *
-     * @param mixed $config Zend_Config or Array
+     * @param  array|Zend_Config $config Zend_Config or Array
      * @return Zend_Log_Filter_Interface
      */
     protected function _constructFilterFromConfig($config)
     {
         $filter = $this->_constructFromConfig('filter', $config, $this->_defaultFilterNamespace);
 
-        if (! $filter instanceof Zend_Log_Filter_Interface) {
+        if (!$filter instanceof Zend_Log_Filter_Interface) {
             require_once 'Zend/Log/Exception.php';
             throw new Zend_Log_Exception("{$filterName} does not implement Zend_Log_Filter_Interface");
         }
@@ -182,13 +180,15 @@ class Zend_Log
             );
         }
 
-        $params = isset($config[ $type .'Params' ]) ? $config[ $type .'Params' ] : array();
+        $params    = isset($config[ $type .'Params' ]) ? $config[ $type .'Params' ] : array();
         $className = $this->getClassName($config, $type, $namespace);
-        Zend_Loader::loadClass($className);
+        if (!class_exists($className)) {
+            require_once 'Zend/Loader.php';
+            Zend_Loader::loadClass($className);
+        }
 
         $reflection = new ReflectionClass($className);
-        if (!$reflection->implementsInterface('Zend_Log_FactoryInterface'))
-        {        
+        if (!$reflection->implementsInterface('Zend_Log_FactoryInterface')) {        
             throw new Zend_Log_Exception(
                 'Driver does not implement Zend_Log_FactoryInterface and can not be constructed from config.'
             );
@@ -393,15 +393,15 @@ class Zend_Log
      */
     public function addWriter($writer)
     {
-        if ( is_array($writer) || $writer instanceof  Zend_Config) {
+        if (is_array($writer) || $writer instanceof  Zend_Config) {
             $writer = $this->_constructWriterFromConfig($writer);
         }
 
-        if(! $writer instanceof Zend_Log_Writer_Abstract) {
+        if (!$writer instanceof Zend_Log_Writer_Abstract) {
             require_once 'Zend/Log/Exception.php';
             throw new Zend_Log_Exception(
-              'Writer must be an instance of Zend_Log_Writer_Abstract ' .
-              'or you should pass a configuration array'
+                'Writer must be an instance of Zend_Log_Writer_Abstract'
+                . ' or you should pass a configuration array'
             );
         }
 
@@ -418,5 +418,4 @@ class Zend_Log
     public function setEventItem($name, $value) {
         $this->_extras = array_merge($this->_extras, array($name => $value));
     }
-
 }

+ 2 - 3
library/Zend/Log/FactoryInterface.php

@@ -28,12 +28,11 @@
  */
 interface Zend_Log_FactoryInterface
 {
-    
     /**
      * Construct a Zend_Log driver
      * 
-     * @param mixed $config
+     * @param  array|Zen_Config $config
      * @return Zend_Log_FactoryInterface
      */
     static public function factory($config);
-}
+}

+ 9 - 3
library/Zend/Log/Filter/Abstract.php

@@ -20,6 +20,12 @@
  * @version    $Id$
  */
 
+/** @see Zend_Log_Filter_Interface */
+require_once 'Zend/Log/Filter/Interface.php';
+
+/** @see Zend_Log_FactoryInterface */
+require_once 'Zend/Log/FactoryInterface.php';
+
 /**
  * @category   Zend
  * @package    Zend_Log
@@ -34,9 +40,9 @@ abstract class Zend_Log_Filter_Abstract
     /**
      * Validate and optionally convert the config to array
      * 
-     * @exception Zend_Log_Exception
-     * @param mixed $config Zend_Config or Array
+     * @param  array|Zend_Config $config Zend_Config or Array
      * @return array
+     * @throws Zend_Log_Exception
      */
     static protected function _parseConfig($config)
     {
@@ -51,4 +57,4 @@ abstract class Zend_Log_Filter_Abstract
 
         return $config;
     }
-}
+}

+ 0 - 1
library/Zend/Log/Filter/Interface.php

@@ -37,5 +37,4 @@ interface Zend_Log_Filter_Interface
      * @return boolean            accepted?
      */
     public function accept($event);
-
 }

+ 3 - 4
library/Zend/Log/Filter/Message.php

@@ -56,14 +56,14 @@ class Zend_Log_Filter_Message extends Zend_Log_Filter_Abstract
     /**
      * Create a new instance of Zend_Log_Filter_Message
      * 
-     * @exception Zend_Log_Exception
-     * @param mixed $config
+     * @param  array|Zend_Config $config
      * @return Zend_Log_Filter_Message
+     * @throws Zend_Log_Exception
      */
     static public function factory($config) 
     {
         $config = self::_parseConfig($config);
-        $config = $config + array('regexp'=>NULL);
+        $config = $config + array('regexp' => null);
 
         return new self(
             $config['regexp']
@@ -80,5 +80,4 @@ class Zend_Log_Filter_Message extends Zend_Log_Filter_Abstract
     {
         return preg_match($this->_regexp, $event['message']) > 0;
     }
-
 }

+ 8 - 6
library/Zend/Log/Filter/Priority.php

@@ -20,8 +20,8 @@
  * @version    $Id$
  */
 
-/** Zend_Log_Filter_Interface */
-require_once 'Zend/Log/Filter/Interface.php';
+/** Zend_Log_Filter_Abstract */
+require_once 'Zend/Log/Filter/Abstract.php';
 
 /**
  * @category   Zend
@@ -65,14 +65,17 @@ class Zend_Log_Filter_Priority extends Zend_Log_Filter_Abstract
     /**
      * Create a new instance of Zend_Log_Filter_Priority
      * 
-     * @exception Zend_Log_Exception
-     * @param mixed $config
+     * @param  array|Zend_Config $config
      * @return Zend_Log_Filter_Priority
+     * @throws Zend_Log_Exception
      */
     static public function factory($config) 
     {
         $config = self::_parseConfig($config);
-        $config = $config + array('priority'=>NULL, 'operator'=>NULL);
+        $config = $config + array(
+            'priority' => null, 
+            'operator' => null,
+        );
 
         // Add support for constants
         if (is_string($config['priority'])) {
@@ -95,5 +98,4 @@ class Zend_Log_Filter_Priority extends Zend_Log_Filter_Abstract
     {
         return version_compare($event['priority'], $this->_priority, $this->_operator);
     }
-
 }

+ 2 - 2
library/Zend/Log/Filter/Suppress.php

@@ -66,9 +66,9 @@ class Zend_Log_Filter_Suppress extends Zend_Log_Filter_Abstract
     /**
      * Create a new instance of Zend_Log_Filter_Suppress
      * 
-     * @exception Zend_Log_Exception
-     * @param mixed $config
+     * @param  array|Zend_Config $config
      * @return Zend_Log_Filter_Suppress
+     * @throws Zend_Log_Exception
      */
     static public function factory($config)
     {

+ 3 - 3
library/Zend/Log/Writer/Abstract.php

@@ -107,9 +107,9 @@ abstract class Zend_Log_Writer_Abstract implements Zend_Log_FactoryInterface
     /**
      * Validate and optionally convert the config to array
      * 
-     * @exception Zend_Log_Exception
-     * @param mixed $config Zend_Config or Array
+     * @param  array|Zend_Config $config Zend_Config or Array
      * @return array
+     * @throws Zend_Log_Exception
      */
     static protected function _parseConfig($config)
     {
@@ -126,4 +126,4 @@ abstract class Zend_Log_Writer_Abstract implements Zend_Log_FactoryInterface
 
         return $config;
     }
-}
+}

+ 7 - 4
library/Zend/Log/Writer/Db.php

@@ -69,14 +69,18 @@ class Zend_Log_Writer_Db extends Zend_Log_Writer_Abstract
     /**
      * Create a new instance of Zend_Log_Writer_Db
      * 
-     * @exception Zend_Log_Exception
-     * @param mixed $config
+     * @param  array|Zend_Config $config
      * @return Zend_Log_Writer_Db
+     * @throws Zend_Log_Exception
      */
     static public function factory($config)
     {
         $config = self::_parseConfig($config);
-        $config = $config + array('db'=>NULL, 'table'=>NULL, 'columnMap'=>NULL);
+        $config = $config + array(
+            'db'        => null, 
+            'table'     => null, 
+            'columnMap' => null,
+        );
         
         if (isset($config['columnmap'])) {
             $config['columnMap'] = $config['columnmap'];
@@ -132,5 +136,4 @@ class Zend_Log_Writer_Db extends Zend_Log_Writer_Abstract
 
         $this->_db->insert($this->_table, $dataToInsert);
     }
-
 }

+ 3 - 3
library/Zend/Log/Writer/Firebug.php

@@ -74,7 +74,7 @@ class Zend_Log_Writer_Firebug extends Zend_Log_Writer_Abstract
      */
     public function __construct()
     {
-        if (php_sapi_name()=='cli') {
+        if (php_sapi_name() == 'cli') {
             $this->setEnabled(false);
         }
 
@@ -84,9 +84,9 @@ class Zend_Log_Writer_Firebug extends Zend_Log_Writer_Abstract
     /**
      * Create a new instance of Zend_Log_Writer_Firebug
      * 
-     * @exception Zend_Log_Exception
-     * @param mixed $config
+     * @param  array|Zend_Config $config
      * @return Zend_Log_Writer_Firebug
+     * @throws Zend_Log_Exception
      */
     static public function factory($config)
     {

+ 2 - 2
library/Zend/Log/Writer/Mail.php

@@ -121,9 +121,9 @@ class Zend_Log_Writer_Mail extends Zend_Log_Writer_Abstract
     /**
      * Create a new instance of Zend_Log_Writer_Mail
      * 
-     * @exception Zend_Log_Exception
-     * @param mixed $config
+     * @param  array|Zend_Config $config
      * @return Zend_Log_Writer_Mail
+     * @throws Zend_Log_Exception
      */
     static public function factory($config)
     {

+ 4 - 4
library/Zend/Log/Writer/Mock.php

@@ -67,12 +67,12 @@ class Zend_Log_Writer_Mock extends Zend_Log_Writer_Abstract
     /**
      * Create a new instance of Zend_Log_Writer_Mock
      * 
-     * @exception Zend_Log_Exception
-     * @param mixed $config
+     * @param  array|Zend_Config $config
      * @return Zend_Log_Writer_Mock
+     * @throws Zend_Log_Exception
      */
     static public function factory($config) 
     {
-        return new self( self::_parseConfig($config) );
+        return new self();
     }
-}
+}

+ 4 - 6
library/Zend/Log/Writer/Null.php

@@ -46,14 +46,12 @@ class Zend_Log_Writer_Null extends Zend_Log_Writer_Abstract
     /**
      * Create a new instance of Zend_Log_Writer_Null
      * 
-     * @exception Zend_Log_Exception
-     * @param mixed $config
+     * @param  array|Zend_Config $config
      * @return Zend_Log_Writer_Null
+     * @throws Zend_Log_Exception
      */
     static public function factory($config)
     {
-        return new self(
-            self::_parseConfig($config)
-        );
+        return new self();
     }
-}
+}

+ 6 - 4
library/Zend/Log/Writer/Stream.php

@@ -85,14 +85,17 @@ class Zend_Log_Writer_Stream extends Zend_Log_Writer_Abstract
     /**
      * Create a new instance of Zend_Log_Writer_Mock
      * 
-     * @exception Zend_Log_Exception
-     * @param mixed $config
+     * @param  array|Zend_Config $config
      * @return Zend_Log_Writer_Mock
+     * @throws Zend_Log_Exception
      */
     static public function factory($config)
     {
         $config = self::_parseConfig($config);
-        $config = $config + array('stream'=>NULL, 'mode'=>NULL);
+        $config = $config + array(
+            'stream' => null, 
+            'mode'   => null,
+        );
 
         $streamOrUrl = isset($config['url']) ? $config['url'] : $config['stream']; 
         
@@ -129,5 +132,4 @@ class Zend_Log_Writer_Stream extends Zend_Log_Writer_Abstract
             throw new Zend_Log_Exception("Unable to write to stream");
         }
     }
-
 }

+ 3 - 5
library/Zend/Log/Writer/Syslog.php

@@ -99,15 +99,13 @@ class Zend_Log_Writer_Syslog extends Zend_Log_Writer_Abstract
     /**
      * Create a new instance of Zend_Log_Writer_Syslog
      * 
-     * @exception Zend_Log_Exception
-     * @param mixed $config
+     * @param  array|Zend_Config $config
      * @return Zend_Log_Writer_Syslog
+     * @throws Zend_Log_Exception
      */
     static public function factory($config)
     {
-        return new self(
-            self::_parseConfig($config)
-        );
+        return new self(self::_parseConfig($config));
     }
 
     /**

+ 12 - 0
library/Zend/Log/Writer/ZendMonitor.php

@@ -50,6 +50,18 @@ class Zend_Log_Writer_ZendMonitor extends Zend_Log_Writer_Abstract
     }
 
     /**
+     * Create a new instance of Zend_Log_Writer_ZendMonitor
+     * 
+     * @param  array|Zend_Config $config
+     * @return Zend_Log_Writer_Syslog
+     * @throws Zend_Log_Exception
+     */
+    static public function factory($config)
+    {
+        return new self();
+    }
+
+    /**
      * Is logging to this writer enabled?
      *
      * If the Zend Monitor extension is not enabled, this log writer will