Author: kn
Date: Thu Oct 11 15:41:10 2007
New Revision: 6423

Log:
- Use struct instead of complex array

Added:
    trunk/Webdav/src/structs/output_result.php   (with props)
Modified:
    trunk/Webdav/design/class_diagram.png
    trunk/Webdav/src/transport.php
    trunk/Webdav/src/webdav_autoload.php
    trunk/Webdav/tests/classes/transport_test_mock.php

Modified: trunk/Webdav/design/class_diagram.png
==============================================================================
Binary files - no diff available.

Added: trunk/Webdav/src/structs/output_result.php
==============================================================================
--- trunk/Webdav/src/structs/output_result.php (added)
+++ trunk/Webdav/src/structs/output_result.php [iso-8859-1] Thu Oct 11 15:41:10 
2007
@@ -1,0 +1,60 @@
+<?php
+/**
+ * File containing the ezcWebdavOutputResult struct.
+ *
+ * @package Webdav
+ * @version //autogentag//
+ * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+/**
+ * Display information.
+ *
+ * Used by [EMAIL PROTECTED] ezcWebdavTransport} to transport information on 
displaying a
+ * response to the browser.
+ *
+ * @version //autogentag//
+ * @package Webdav
+ * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+class ezcWebdavOutputResult
+{
+    /**
+     * Response code
+     * 
+     * @var string
+     */
+    public $status;
+
+    /**
+     * Response headers
+     * 
+     * @var array
+     */
+    public $header;
+
+    /**
+     * Response body
+     * 
+     * @var string
+     */
+    public $body;
+    
+    /**
+     * Creates a new struct.
+     * 
+     * @param string $status 
+     * @param array $header 
+     * @param string $body 
+     * @return void
+     */
+    public function __construct( $status = '', array $header = array(), $body 
= '' )
+    {
+        $this->status = $status;
+        $this->header = $header;
+        $this->body   = $body;
+    }
+}
+
+?>

Propchange: trunk/Webdav/src/structs/output_result.php
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: trunk/Webdav/src/transport.php
==============================================================================
--- trunk/Webdav/src/transport.php [iso-8859-1] (original)
+++ trunk/Webdav/src/transport.php [iso-8859-1] Thu Oct 11 15:41:10 2007
@@ -366,8 +366,10 @@
     protected function flattenResponse( ezcWebdavDisplayInformation $info )
     {
         $headers     = array_merge( $info->response->getHeaders() );
-        $headers[''] = (string) $info->response;
         $body        = '';
+
+        $output = new ezcWebdavOutputResult();
+        $output->status = (string) $info->response;
 
         switch ( true )
         {
@@ -393,8 +395,11 @@
                 $body = '';
                 break;
         }
+
+        $output->headers = $headers;
+        $output->body    = $body;
         
-        return array( 'headers' => $headers, 'body' => $body );
+        return $output;
     }
 
     /**
@@ -402,39 +407,26 @@
      *
      * This method is called to finally send the response to the browser. It
      * can be overwritten in test cases to change the behaviour of printing out
-     * the result and sending the headers. The method receives an array
-     * containg 2 elements: The key 'headers' is assigned to an array of
-     * headers to be send. This array is indexed by the header name, while
-     * there is usually 1 empty key, that contains the response code header.
-     * The second element has the key 'body' and contains the string to be send
-     * to the client.
-     *
-     * <code>
-     *      array(
-     *          'headers' => array(
-     *              ''       => '<responsecodeandname>',
-     *              '<name>' => '<value>',
-     *              // ...
-     *          ),
-     *          'body' => '<string>'
-     *      )
-     * </code>
-     *
-     * @param array(string=>mixed) $output
+     * the result and sending the headers.
+     *
+     * @param ezcWebdavOutputResult $output
      * @return void
      *
      * @todo Should $output be a struct?
      */
-    protected function sendResponse( array $output )
-    {
-        // Sends HTTP response code and description
-        foreach( $output['headers'] as $name => $content )
-        {
-            header( ( $name === '' ? $content : "{$name}: {$content}" ) );
-        }
+    protected function sendResponse( ezcWebdavOutputResult $output )
+    {
+        // Sends HTTP headers
+        foreach( $output->headers as $name => $content )
+        {
+            header( "{$name}: {$content}" );
+        }
+
+        // Send HTTP status code
+        header( $output->status );
 
         // Content-Length header automatically send
-        echo $result;
+        echo $output->body;
     }
 
     /**

Modified: trunk/Webdav/src/webdav_autoload.php
==============================================================================
--- trunk/Webdav/src/webdav_autoload.php [iso-8859-1] (original)
+++ trunk/Webdav/src/webdav_autoload.php [iso-8859-1] Thu Oct 11 15:41:10 2007
@@ -80,6 +80,7 @@
     'ezcWebdavNamespaceRegistry'                      => 
'Webdav/namespace_registry.php',
     'ezcWebdavOptionsRequest'                         => 
'Webdav/requests/options.php',
     'ezcWebdavOptionsResponse'                        => 
'Webdav/responses/options.php',
+    'ezcWebdavOutputResult'                           => 
'Webdav/structs/output_result.php',
     'ezcWebdavPluginConfiguration'                    => 
'Webdav/plugin_configuration.php',
     'ezcWebdavPluginParameters'                       => 
'Webdav/plugin_parameters.php',
     'ezcWebdavPluginRegistry'                         => 
'Webdav/plugin_registry.php',

Modified: trunk/Webdav/tests/classes/transport_test_mock.php
==============================================================================
--- trunk/Webdav/tests/classes/transport_test_mock.php [iso-8859-1] (original)
+++ trunk/Webdav/tests/classes/transport_test_mock.php [iso-8859-1] Thu Oct 11 
15:41:10 2007
@@ -7,10 +7,10 @@
         return $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_BODY'];
     }
 
-    protected function sendResponse( array $output )
+    protected function sendResponse( ezcWebdavOutputResult $output )
     {
-        $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_HEADERS'] = 
$output['headers'];
-        $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_BODY']    = 
$output['body'];
+        $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_HEADERS'] = 
$output->headers;
+        $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_BODY']    = $output->body;
     }
 }
 


-- 
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to