Zend Framework

Handling Arrays in Nirvanix Service

Details

  • Type: Improvement Improvement
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: 1.6.0, 1.6.1, 1.6.2, 1.7.0, 1.7.1, 1.7.2, 1.7.3, 1.7.4, 1.7.5, 1.7.6, 1.7.7, 1.7.8, 1.8.0, 1.8.1, 1.8.2, 1.8.3, 1.8.4
  • Fix Version/s: None
  • Component/s: Zend_Service_Nirvanix
  • Labels:
    None

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))
    Unknown macro: { 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

<?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
  • @subpackage Nirvanix
  • @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  • @license http://framework.zend.com/license/new-bsd 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. (http://www.zend.com)
  • @license http://framework.zend.com/license/new-bsd 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:

<?php

set_include_path(get_include_path() . PATH_SEPARATOR . 'C:\Program Files\PHP\ZendFramework-1.8.2-minimal\library');
require_once 'C:\Program Files\PHP\ZendFramework-1.8.2-minimal\library\Zend\Service\Nirvanix.php';

$auth = array('username' => '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
)
)
)
)

Activity

There are no comments yet on this issue.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated: