{{ 'cd'|in('abcde') }}
You can use this filter to perform a containment test on strings, arrays, or
-objects implementing the `ArrayAccess` interface.
+objects implementing the `Traversable` interface.
### `default`
{
return false !== strpos($compare, (string) $value);
}
- elseif (is_object($compare) && $compare instanceof ArrayAccess)
+ elseif (is_object($compare) && $compare instanceof Traversable)
{
return in_array($value, iterator_to_array($compare));
}
--- /dev/null
+--TEST--
+"in" filter
+--TEMPLATE--
+{{ 1|in([1, 2, 3]) }}
+{{ 5|in([1, 2, 3]) }}
+{{ 'cd'|in('abcde') }}
+{{ 'ad'|in('abcde') }}
+{{ 'foo'|in(foo) }}
+{{ 'a'|in(foo|keys) }}
+--DATA--
+class ItemsIteratorForInFilter implements Iterator
+{
+ protected $values = array('a' => 'foo', 'b' => 'bar');
+ public function current() { return current($this->values); }
+ public function key() { return key($this->values); }
+ public function next() { return next($this->values); }
+ public function rewind() { return reset($this->values); }
+ public function valid() { return false !== current($this->values); }
+}
+return array('foo' => new ItemsIteratorForInFilter())
+--EXPECT--
+1
+
+1
+
+1
+1
}
}
-$t = new LimeTest(52);
+$t = new LimeTest(53);
$fixturesDir = realpath(dirname(__FILE__).'/../fixtures/');
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($fixturesDir), RecursiveIteratorIterator::LEAVES_ONLY) as $file)