Scalr\Service\Aws\DataType\ListDataType::getQueryArray PHP Method

getQueryArray() public method

This method overrides parent method.
public getQueryArray ( string $uriParameterName = null, boolean $member = true ) : string
$uriParameterName string optional Parameter name. If null it will use class property name that is provided in constructor.
$member boolean optional Should it add member prefix
return string Returns query parameters array looks like array ( 'parameterName.member.n[.propName[.member.m]]' => value ) Values are not url encoded.
    public function getQueryArray($uriParameterName = null, $member = true)
    {
        $mprefix = $member ? '.member.' : '.';
        $this->refresh();
        if ($uriParameterName === null) {
            if ($this->propertyName === null || is_array($this->propertyName)) {
                $uriParameterName = 'Undefined';
            } else {
                $uriParameterName = $this->uppercaseProperty($this->propertyName);
            }
        }
        $fnCast = function ($value) {
            if ($value instanceof StringType || is_int($value) || is_float($value)) {
                $value = (string) $value;
            } else {
                if ($value instanceof \DateTime) {
                    $value = $value->format('c');
                } else {
                    if (is_bool($value)) {
                        $value = $value ? 'true' : 'false';
                    }
                }
            }
            return $value;
        };
        $n = 1;
        $arr = array();
        foreach ($this->list as $v) {
            if (is_array($this->propertyName)) {
                foreach ((array) $this->propertyName as $prop) {
                    $ucProp = $this->uppercaseProperty($prop);
                    if (isset($v[$prop]) && $v[$prop] instanceof AbstractDataType) {
                        $sub = $v[$prop]->getQueryArray($uriParameterName . $mprefix . $n . '.' . $ucProp, $member);
                        if (!empty($sub)) {
                            $arr = array_merge($arr, $sub);
                            unset($sub);
                        }
                    } else {
                        if (isset($v[$prop]) && (is_array($v[$prop]) || $v[$prop] instanceof \Traversable)) {
                            $m = 1;
                            foreach ($v[$prop] as $mval) {
                                $arr[$uriParameterName . $mprefix . $n . '.' . $ucProp . $mprefix . $m] = $fnCast($mval);
                                $m++;
                            }
                        } else {
                            $arr[$uriParameterName . $mprefix . $n . '.' . $ucProp] = $fnCast($v[$prop]);
                        }
                    }
                }
                $n++;
            } else {
                $arr[$uriParameterName . $mprefix . $n++] = $fnCast($v);
            }
        }
        return $arr;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * @test
  * @dataProvider provider
  */
 public function testConstructor($aListData, $propertyName, $dataClassName = null, $opt = array())
 {
     $list = new ListDataType($aListData, $propertyName, $dataClassName);
     $this->assertEquals($opt, $list->getQueryArray(), 'Unexpected options array');
     $this->assertEquals(count($opt), (is_array($propertyName) ? count($propertyName) : 1) * count($list), 'Different number of arguments');
     $this->assertInstanceOf('Iterator', $list, 'List does not implement Iterator interface.');
     $this->assertInstanceOf('Countable', $list, 'List does not implement Countable interface.');
     if (!is_array($propertyName)) {
         $keys = array_keys($opt);
         foreach ($list->getQueryArray() as $key => $value) {
             $this->assertContains($key, $keys, 'Missing key');
             $this->assertContains($value, $opt, 'Missing value');
         }
         $this->assertEquals(array_values($opt), $list->getComputed(), 'Unexpected out of getComputed() method.');
     } else {
         if ($dataClassName != null) {
             foreach ($list as $value) {
                 $this->assertInstanceOf($dataClassName, $value);
             }
         }
     }
     unset($list);
 }
All Usage Examples Of Scalr\Service\Aws\DataType\ListDataType::getQueryArray