Skip to content

Commit b65caef

Browse files
committed
Support getting list of all variables for given field name
1 parent 00bf8cd commit b65caef

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

src/Protocol/Message.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,25 @@ public function getFieldValues($key)
6060
return $values;
6161
}
6262

63+
/**
64+
* Returns a hashmap of all variable assignments in the given $key
65+
*
66+
* @param string $key
67+
* @return array
68+
* @uses self::getFieldValues()
69+
*/
70+
public function getFieldVariables($key)
71+
{
72+
$variables = array();
73+
74+
foreach ($this->getFieldValues($key) as $value) {
75+
$temp = explode('=', $value, 2);
76+
$variables[$temp[0]] = $temp[1];
77+
}
78+
79+
return $variables;
80+
}
81+
6382
public function toJson()
6483
{
6584
return json_encode($this->getFields());

tests/Protocol/ActionTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,8 @@ public function testOneFieldMultipleKeyValues()
9191

9292
$this->assertEquals('first=on', $action->getFieldValue('Variables'));
9393
$this->assertEquals(array('first=on', 'second=off'), $action->getFieldValues('Variables'));
94+
95+
$this->assertEquals(array('first' => 'on', 'second' => 'off'), $action->getFieldVariables('Variables'));
96+
$this->assertEquals(array(), $action->getFieldVariables('unknown'));
9497
}
9598
}

0 commit comments

Comments
 (0)