Issues

ZF-7174: Handling Arrays in Nirvanix Service

Issue Type: Improvement Created: 2009-07-01T13:36:19.000+0000 Last Updated: 2012-11-20T20:53:07.000+0000 Status: Closed Fix version(s): Reporter: Barry Ruffner (bruffner) Assignee: None Tags: - Zend_Service_Nirvanix

Related issues: Attachments:

Description

In the Nirvanix web services arrays can be passed to avoid having to call the same call multiple times. The setParameterPost does not pass the parameters when passing a sub-array to the method. To change the behavior a new method is introduced below that parses the parameters and constructs the HTTP POST body directly taking the sub-array into account.

Changes:

Line 132 /trunk/library/Zend/Service/Nirvanix/Namespace/Base.php

  • $this->_httpClient->setParameterPost($params);
  • $this->_httpClient->setRawData($this->_getBody($params));

Line 171 /trunk/library/Zend/Service/Nirvanix/Namespace/Base.php

/**
 * The httpClient->setParametersPost does not handle arrays properly when
 * passing a subarray in the value.  This method handles the parameter
 * parsing to take this into account.
 *
 * @param  array    $params  Parameter array containing the name value pairs
 * @return string   URL Encoded string for the HTTP POST Body.
 */
 private function _getBody($params)
 {
      foreach ($params as $name => $value) {
           if (is_array($value)) {
                foreach ($value as $k => $value) {
                     $paramstr .= '&' . urlencode($name) . '=' . urlencode($value);
                }
           } else {
                $paramstr .= '&' . urlencode($name) . '=' . urlencode($value);
           }
      }
      return $paramstr;
 }

Unit Test:

New file: /trunk/tests/Zend/Service/Nirvanix/parameterTest.php

\* 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 \* @subpackage Nirvanix \* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. () \* @license New BSD License \*/ /\*\* \* @see Zend\_Service\_Nirvanix\_Namespace\_Imfs \*/ require\_once 'Zend/Service/Nirvanix/Namespace/Imfs.php'; /\*\* \* @see Zend\_Service\_Nirvanix\_FunctionalTestCase \*/ require\_once 'Zend/Service/Nirvanix/FunctionalTestCase.php'; /\*\* \* @category Zend \* @package Zend\_Service \* @subpackage UnitTests \* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. () \* @license New BSD License \*/ class Zend\_Service\_Nirvanix\_Namespace\_ImfsTest extends Zend\_Service\_Nirvanix\_FunctionalTestCase { public function testInheritsFromNirvanixBase() { $imfs = new Zend\_Service\_Nirvanix\_Namespace\_Imfs(); $this->assertType('Zend\_Service\_Nirvanix\_Namespace\_Base', $imfs); } // \_getBody() public function testMultiparameter() { $imfs = $this->nirvanix->getService('IMFS'); $imfs->putContents('/foo', 'contents for foo'); $metadata = $this->nirvanix->getService('Metadata'); $metaarray = array('color:blue', 'texture:smooth'); $testarray = array('path' => '/foo', 'metadata' => $metaarray); $this->httpAdapter->addResponse( $this->makeNirvanixResponse( array('ResponseCode' => '0')) ); $metadata->setMetadata($testarray); $imfs->unlink('foo'); } } A quick test to verify that everything is working outside of the unit tests as well: 'userforzendbug', 'password' => 'zendpass', 'appKey' => '1a6df3fd-c81d-4cbf-9a97-27110926e916'); $nirvanix = new Zend\_Service\_Nirvanix($auth); $imfs = $nirvanix->getService('IMFS'); $imfs->putContents('/foo.txt', 'fourteen bytes'); $metadata = $nirvanix->getService('Metadata'); $metaarray = array('color:blue', 'te&xture:smooth'); $testarray = array('path' => '/foo.txt', 'metadata' => $metaarray); $result = $metadata->setMetadata($testarray); $result = $metadata->getMetadata($testarray); print\_r($result); ?> The results should be similar to: Zend\_Service\_Nirvanix\_Response Object ( [\_sxml:protected] => SimpleXMLElement Object ( [ResponseCode] => 0 [Metadata] => Array ( [0] => SimpleXMLElement Object ( [Type] => color [Value] => blue )
                [1] => SimpleXMLElement Object
                    (
                        [Type] => MD5
                        [Value] => KpY3FwasAWNyyIXIBmsTEg==
                    )

                [2] => SimpleXMLElement Object
                    (
                        [Type] => te&xture
                        [Value] => smooth
                    )
            )
    )

)

Comments

Posted by Rob Allen (rob) on 2012-11-20T20:53:07.000+0000

Bulk change of all issues last updated before 1st January 2010 as "Won't Fix".

Feel free to re-open and provide a patch if you want to fix this issue.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts