ValueObjects\Structure\Dictionary::fromNative PHP Method

fromNative() public static method

Returns a new Dictionary object
public static fromNative ( ) : self
return self
    public static function fromNative()
    {
        $array = \func_get_arg(0);
        $keyValuePairs = array();
        foreach ($array as $arrayKey => $arrayValue) {
            $key = new StringLiteral(\strval($arrayKey));
            if ($arrayValue instanceof \Traversable || \is_array($arrayValue)) {
                $value = Collection::fromNative($arrayValue);
            } else {
                $value = new StringLiteral(\strval($arrayValue));
            }
            $keyValuePairs[] = new KeyValuePair($key, $value);
        }
        $fixedArray = \SplFixedArray::fromArray($keyValuePairs);
        return new static($fixedArray);
    }

Usage Example

Example #1
0
 public function testFromNative()
 {
     $constructedArray = \SplFixedArray::fromArray(array(new KeyValuePair(new StringLiteral('0'), new StringLiteral('zero')), new KeyValuePair(new StringLiteral('1'), new StringLiteral('one')), new KeyValuePair(new StringLiteral('2'), new StringLiteral('two'))));
     $fromNativeArray = \SplFixedArray::fromArray(array('zero', 'one', 'two'));
     $constructedDictionary = new Dictionary($constructedArray);
     $fromNativeDictionary = Dictionary::fromNative($fromNativeArray);
     $this->assertTrue($constructedDictionary->sameValueAs($fromNativeDictionary));
 }
All Usage Examples Of ValueObjects\Structure\Dictionary::fromNative