Просмотр исходного кода

Merge r25284 to 1.12 release branch

git-svn-id: http://framework.zend.com/svn/framework/standard/branches/release-1.12@25285 44c647ce-9c0f-0410-b52a-842ac1e357ba
frosch 13 лет назад
Родитель
Сommit
a2869cf522

+ 0 - 50
library/Zend/Service/WindowsAzure/CommandLine/sample.php

@@ -1,50 +0,0 @@
-<?php
-
-/**
- * Sample command.
- * 
- * @command-handler sample
- * @command-handler-description Sample command.
- * @command-handler-header Windows Azure SDK for PHP
- * @command-handler-header (C) RealDolmen 2011 - www.realdolmen.com
- */
-class Sample
-	extends Zend_Service_Console_Command
-{
-	/**
-	 * Hello command
-	 * 
-	 * @command-name hello
-	 * @command-description Prints Hello, World!
-	 * @command-parameter-for $name Zend_Service_Console_Command_ParameterSource_Argv|Zend_Service_Console_Command_ParameterSource_Env --name|-n Required. Name to say hello to.
-	 * @command-parameter-for $bePolite Zend_Service_Console_Command_ParameterSource_Argv -p Optional. Switch to enable polite mode or not.
-	 * @command-example Print "Hello, Maarten! How are you?" (using polite mode):
-	 * @command-example   hello -n:"Maarten" -p
-	 * 
-	 * @param string $name
-	 */
-	public function helloCommand($name, $bePolite = false)
-	{
-		echo 'Hello, ' . $name . '.';
-		if ($bePolite) {
-			echo ' How are you?';
-		}
-		echo "\r\n";
-	}
-	
-	/**
-	 * What time is it command
-	 * 
-	 * @command-name timestamp
-	 * @command-description Prints the current timestamp.
-	 * 
-	 * @param string $name
-	 */
-	public function timestampCommand()
-	{
-		echo date();
-		echo "\r\n";
-	}
-}
-
-Zend_Service_Console_Command::bootstrap($_SERVER['argv']);

+ 38 - 0
library/Zend/Service/WindowsAzure/Log/Exception.php

@@ -0,0 +1,38 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Service_WindowsAzure
+ * @subpackage Exception
+ * @version    $Id$
+ * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+
+/**
+ * @see Zend_Service_WindowsAzure_Exception
+ */
+require_once 'Zend/Service/WindowsAzure/Exception.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_Service_WindowsAzure
+ * @subpackage Log
+ * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Service_WindowsAzure_Log_Exception
+    extends Zend_Service_WindowsAzure_Exception
+{
+}

+ 30 - 29
library/Zend/Service/WindowsAzure/Log/Formatter/WindowsAzure.php

@@ -21,9 +21,9 @@
  */
 
 /**
- * @see Zend_Service_Log_Formatter_Interface
+ * @see Zend_Log_Formatter_Interface
  */
-require_once 'Zend/Service/Log/Formatter/Interface.php';
+require_once 'Zend/Log/Formatter/Interface.php';
 
 /**
  * @see Zend_Service_WindowsAzure_Storage_DynamicTableEntity
@@ -37,36 +37,37 @@ require_once 'Zend/Service/WindowsAzure/Storage/DynamicTableEntity.php';
  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  * @license    http://framework.zend.com/license/new-bsd     New BSD License
  */
-class Zend_Service_WindowsAzure_Log_Formatter_WindowsAzure implements Zend_Service_Log_Formatter_Interface
+class Zend_Service_WindowsAzure_Log_Formatter_WindowsAzure
+    implements Zend_Log_Formatter_Interface
 {
-	/**
-	 * Write a message to the table storage
-	 *
-	 * @param  array $event
-	 * @return Zend_Service_WindowsAzure_Storage_DynamicTableEntity
-	 */
-	public function format($event)
-	{
-
-		// partition key is the current date, represented as YYYYMMDD
-		// row key will always be the current timestamp. These values MUST be hardcoded.
-		$logEntity = new Zend_Service_WindowsAzure_Storage_DynamicTableEntity(
-			date('Ymd'), microtime(true));
-		// Windows Azure automatically adds the timestamp, but the timezone is most of the time
-		// different compared to the origin server's timezone, so add this timestamp aswell.
-		$event['server_timestamp'] = $event['timestamp'];
-		unset($event['timestamp']);
-
-		foreach ($event as $key => $value) {
-			 if ((is_object($value) && !method_exists($value,'__toString'))
-                || is_array($value)) {
+    /**
+     * Write a message to the table storage
+     *
+     * @param  array $event
+     *
+     * @return Zend_Service_WindowsAzure_Storage_DynamicTableEntity
+     */
+    public function format($event)
+    {
+        // partition key is the current date, represented as YYYYMMDD
+        // row key will always be the current timestamp. These values MUST be hardcoded.
+        $logEntity = new Zend_Service_WindowsAzure_Storage_DynamicTableEntity(
+            date('Ymd'), microtime(true)
+        );
+        // Windows Azure automatically adds the timestamp, but the timezone is most of the time
+        // different compared to the origin server's timezone, so add this timestamp aswell.
+        $event['server_timestamp'] = $event['timestamp'];
+        unset($event['timestamp']);
 
+        foreach ($event as $key => $value) {
+            if ((is_object($value) && !method_exists($value, '__toString'))
+                || is_array($value)
+            ) {
                 $value = gettype($value);
             }
+            $logEntity->{$key} = $value;
+        }
 
-			$logEntity->{$key} = $value;
-		}
-
-		return $logEntity;
-	}
+        return $logEntity;
+    }
 }

+ 139 - 117
library/Zend/Service/WindowsAzure/Log/Writer/WindowsAzure.php

@@ -21,9 +21,9 @@
  */
 
 /**
- * @see Zend_Service_Log_Writer_Abstract
+ * @see Zend_Log_Writer_Abstract
  */
-require_once 'Zend/Service/Log/Writer/Abstract.php';
+require_once 'Zend/Log/Writer/Abstract.php';
 
 /**
  * @category   Zend
@@ -32,94 +32,109 @@ require_once 'Zend/Service/Log/Writer/Abstract.php';
  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  * @license    http://framework.zend.com/license/new-bsd     New BSD License
  */
-class Zend_Service_WindowsAzure_Log_Writer_WindowsAzure extends Zend_Service_Log_Writer_Abstract
+class Zend_Service_WindowsAzure_Log_Writer_WindowsAzure
+    extends Zend_Log_Writer_Abstract
 {
-	/**
-	 * @var Zend_Service_Log_Formatter_Interface
-	 */
-	protected $_formatter;
-
-	/**
-	 * Connection to a windows Azure 
-	 * 
-	 * @var Zend_Service_Service_WindowsAzure_Storage_Table
-	 */
-	protected $_tableStorageConnection = null;
-
-	/**
-	 * Name of the table to use for logging purposes
-	 *
-	 * @var string
-	 */
-	protected $_tableName = null;
-
-	/**
-	 * Whether to keep all messages to be logged in an external buffer until the script ends and
-	 * only then to send the messages in batch to the logging component.
-	 *
-	 * @var bool
-	 */
-	protected $_bufferMessages = false;
-
-	/**
-	 * If message buffering is activated, it will store all the messages in this buffer and only
-	 * write them to table storage (in a batch transaction) when the script ends.
-	 *
-	 * @var array
-	 */
-	protected $_messageBuffer = array();
-
-	/**
-	 * @param Zend_Service_Service_WindowsAzure_Storage_Table $tableStorageConnection
-	 * @param string $tableName
-	 * @param bool   $createTable create the Windows Azure table for logging if it does not exist
-	 */
-	public function __construct(Zend_Service_WindowsAzure_Storage_Table $tableStorageConnection,
-		$tableName, $createTable = true, $bufferMessages = true)
-	{
-		if ($tableStorageConnection == null) {
-			require_once 'Zend/Service/Log/Exception.php';
-			throw new Zend_Service_Log_Exception('No connection to the Windows Azure tables provided.');
-		}
-
-		if (!is_string($tableName)) {
-			require_once 'Zend/Service/Log/Exception.php';
-			throw new Zend_Service_Log_Exception('Provided Windows Azure table name must be a string.');
-		}
-
-		$this->_tableStorageConnection = $tableStorageConnection;
-		$this->_tableName              = $tableName;
-
-		// create the logging table if it does not exist. It will add some overhead, so it's optional
-		if ($createTable) {
-			$this->_tableStorageConnection->createTableIfNotExists($this->_tableName);
-		}
-
-		// keep messages to be logged in an internal buffer and only send them over the wire when
-		// the script execution ends
-		if ($bufferMessages) {
-			$this->_bufferMessages = $bufferMessages;
-		}
-
-		$this->_formatter = new Zend_Service_WindowsAzure_Log_Formatter_WindowsAzure();
-	}
-
-	/**
-	 * If the log messages have been stored in the internal buffer, just send them
-	 * to table storage.
-	 */
-	public function shutdown() {
-		parent::shutdown();
-		if ($this->_bufferMessages) {
-			$this->_tableStorageConnection->startBatch();
-			foreach ($this->_messageBuffer as $logEntity) {
-				$this->_tableStorageConnection->insertEntity($this->_tableName, $logEntity);
-			}
-			$this->_tableStorageConnection->commit();
-		}
-	}
-
-	/**
+    /**
+     * @var Zend_Service_Log_Formatter_Interface
+     */
+    protected $_formatter;
+
+    /**
+     * Connection to a windows Azure
+     *
+     * @var Zend_Service_Service_WindowsAzure_Storage_Table
+     */
+    protected $_tableStorageConnection = null;
+
+    /**
+     * Name of the table to use for logging purposes
+     *
+     * @var string
+     */
+    protected $_tableName = null;
+
+    /**
+     * Whether to keep all messages to be logged in an external buffer until the script ends and
+     * only then to send the messages in batch to the logging component.
+     *
+     * @var bool
+     */
+    protected $_bufferMessages = false;
+
+    /**
+     * If message buffering is activated, it will store all the messages in this buffer and only
+     * write them to table storage (in a batch transaction) when the script ends.
+     *
+     * @var array
+     */
+    protected $_messageBuffer = array();
+
+    /**
+     * @param Zend_Service_Service_WindowsAzure_Storage_Table|Zend_Service_WindowsAzure_Storage_Table $tableStorageConnection
+     * @param string                                                                                  $tableName
+     * @param bool                                                                                    $createTable create the Windows Azure table for logging if it does not exist
+     * @param bool                                                                                    $bufferMessages
+     * @throws Zend_Service_Log_Exception
+     */
+    public function __construct(
+        Zend_Service_WindowsAzure_Storage_Table $tableStorageConnection,
+        $tableName, $createTable = true, $bufferMessages = true
+    )
+    {
+        if ($tableStorageConnection == null) {
+            require_once 'Zend/Service/Log/Exception.php';
+            throw new Zend_Service_Log_Exception(
+                'No connection to the Windows Azure tables provided.'
+            );
+        }
+
+        if (!is_string($tableName)) {
+            require_once 'Zend/Service/Log/Exception.php';
+            throw new Zend_Service_Log_Exception(
+                'Provided Windows Azure table name must be a string.'
+            );
+        }
+
+        $this->_tableStorageConnection = $tableStorageConnection;
+        $this->_tableName              = $tableName;
+
+        // create the logging table if it does not exist. It will add some overhead, so it's optional
+        if ($createTable) {
+            $this->_tableStorageConnection->createTableIfNotExists(
+                $this->_tableName
+            );
+        }
+
+        // keep messages to be logged in an internal buffer and only send them over the wire when
+        // the script execution ends
+        if ($bufferMessages) {
+            $this->_bufferMessages = $bufferMessages;
+        }
+
+        $this->_formatter =
+            new Zend_Service_WindowsAzure_Log_Formatter_WindowsAzure();
+    }
+
+    /**
+     * If the log messages have been stored in the internal buffer, just send them
+     * to table storage.
+     */
+    public function shutdown()
+    {
+        parent::shutdown();
+        if ($this->_bufferMessages) {
+            $this->_tableStorageConnection->startBatch();
+            foreach ($this->_messageBuffer as $logEntity) {
+                $this->_tableStorageConnection->insertEntity(
+                    $this->_tableName, $logEntity
+                );
+            }
+            $this->_tableStorageConnection->commit();
+        }
+    }
+
+    /**
      * Create a new instance of Zend_Service_Log_Writer_WindowsAzure
      *
      * @param  array $config
@@ -129,11 +144,13 @@ class Zend_Service_WindowsAzure_Log_Writer_WindowsAzure extends Zend_Service_Log
     static public function factory($config)
     {
         $config = self::_parseConfig($config);
-        $config = array_merge(array(
-            'connection'  => null,
-            'tableName'   => null,
-            'createTable' => true,
-        ), $config);
+        $config = array_merge(
+            array(
+                 'connection' => null,
+                 'tableName' => null,
+                 'createTable' => true,
+            ), $config
+        );
 
         return new self(
             $config['connection'],
@@ -142,33 +159,38 @@ class Zend_Service_WindowsAzure_Log_Writer_WindowsAzure extends Zend_Service_Log
         );
     }
 
-	/**
+    /**
      * The only formatter accepted is already  loaded in the constructor
-	 *
-	 * @todo enable custom formatters using the WindowsAzure_Storage_DynamicTableEntity class
+     *
+     * @todo enable custom formatters using the WindowsAzure_Storage_DynamicTableEntity class
      */
-    public function setFormatter(Zend_Service_Log_Formatter_Interface $formatter)
+    public function setFormatter(
+        Zend_Service_Log_Formatter_Interface $formatter
+    )
     {
         require_once 'Zend/Service/Log/Exception.php';
-        throw new Zend_Service_Log_Exception(get_class($this) . ' does not support formatting');
+        throw new Zend_Service_Log_Exception(
+            get_class($this) . ' does not support formatting');
     }
 
-	/**
-	 * Write a message to the table storage. If buffering is activated, then messages will just be
-	 * added to an internal buffer.
-	 *
-	 * @param  array $event
-	 * @return void
-	 * @todo   format the event using a formatted, not in this method
-	 */
-	protected function _write($event)
-	{
-		$logEntity = $this->_formatter->format($event);
-
-		if ($this->_bufferMessages) {
-			$this->_messageBuffer[] = $logEntity;
-		} else {
-			$this->_tableStorageConnection->insertEntity($this->_tableName, $logEntity);
-		}
-	}
+    /**
+     * Write a message to the table storage. If buffering is activated, then messages will just be
+     * added to an internal buffer.
+     *
+     * @param  array $event
+     * @return void
+     * @todo   format the event using a formatted, not in this method
+     */
+    protected function _write($event)
+    {
+        $logEntity = $this->_formatter->format($event);
+
+        if ($this->_bufferMessages) {
+            $this->_messageBuffer[] = $logEntity;
+        } else {
+            $this->_tableStorageConnection->insertEntity(
+                $this->_tableName, $logEntity
+            );
+        }
+    }
 }

+ 1 - 1
library/Zend/Service/WindowsAzure/Management/Exception.php

@@ -33,6 +33,6 @@ require_once 'Zend/Service/WindowsAzure/Exception.php';
  * @license    http://framework.zend.com/license/new-bsd     New BSD License
  */
 class Zend_Service_WindowsAzure_Management_Exception
-	extends Zend_Service_WindowsAzure_Exception
+    extends Zend_Service_WindowsAzure_Exception
 {
 }