public function testSubArrayWithKeys() { $refArray = new WFArray(array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4)); $this->assertEquals(new WFArray(array('a' => 1, 'c' => 3)), $refArray->subArrayWithKeys(array('a', 'c'))); }
function testFirstNotNullOperator() { $a = new Node(); $a->name = NULL; $b = new Node(); $b->name = "Name"; $array = new WFArray(array($a, $b)); $this->assertEquals("Name", $array->valueForKeyPath('*****@*****.**')); }
/** * Filter the WFArray according to function $fn. If calling $fn($item) * returns true, include the item in the result, otherwise exclude it. * * @param WFFunction A WFFunction that returns true to include the item and false to exclude it. * @return WFArray The filtered array. */ public function filter(WFFunction $fn) { $filtered = new WFArray(); foreach ($this as $entry) { $include = $fn->call($entry); if ($include) { $filtered->append($entry); } } return $filtered; }
public function hasErrorWithCodeForKey($code, $key) { if (!$this->hasErrorsForKey($key)) { return false; } $errorCodesForKey = WFArray::arrayWithArray($this->errorsForKey($key))->map('errorCode'); return in_array($code, $errorCodesForKey); }