/** * Tests the whole class. */ public function testIterator() { $data = range(0, 10); $callback = function ($value) { return 0 == $value % 2; }; $iterator = new FilterIterator(new \ArrayIterator($data), $callback); $expected = array(0 => 0, 2 => 2, 4 => 4, 6 => 6, 8 => 8, 10 => 10); $results = array(); foreach ($iterator as $key => $value) { $results[$key] = $value; } $this->assertSame($expected, $results); $this->assertSame($expected, $iterator->toArray()); }
/** * Takes both a directory iterator and a file extension and only returns * results matching the particular extension. * * @access public */ public function __construct(DirectoryIterator $it, $ext, $whitelisted = false) { parent::__construct($it); $this->_it = $it; $this->_ext = $ext; $this->_whitelisted = $whitelisted; }
/** * Constructor. * * @param \Iterator $iterator The Iterator to filter * @param array $directories An array of directories to exclude */ public function __construct(\Iterator $iterator, array $directories) { foreach ($directories as $directory) { $this->patterns[] = '#(^|/)' . preg_quote($directory, '#') . '(/|$)#'; } parent::__construct($iterator); }
/** * {@inheritdoc} */ public function accept() { if (null === $this->status) { return true; } return $this->status == parent::current()->getStatus(); }
/** * Prepares filter with the iterator and the maximum age of session * files we want to compare to. * * @param \Iterator $iterator The iterator with the files we want to compare to * @param integer $maximumAge The maximum age of the session files we want to load */ public function __construct(\Iterator $iterator, $maximumAge) { // call parent constructor parent::__construct($iterator); // initialize the maximum age of the session files we want to load $this->maximumAge = $maximumAge; }
/** * Constructor. * * @param \RecursiveIteratorIterator $iterator The Iterator to filter * @param int $minDepth The min depth * @param int $maxDepth The max depth */ public function __construct(\RecursiveIteratorIterator $iterator, $minDepth = 0, $maxDepth = INF) { $this->minDepth = $minDepth; $iterator->setMaxDepth(INF === $maxDepth ? -1 : $maxDepth); parent::__construct($iterator); }
/** * @param \Iterator $sourceIterator Iterator to wrap and filter * @param \Iterator $targetIterator Iterator used to compare against the source iterator * @param FilenameConverterInterface $sourceConverter Key converter to convert source to target keys * @param FilenameConverterInterface $targetConverter Key converter to convert target to source keys */ public function __construct(\Iterator $sourceIterator, \Iterator $targetIterator, FilenameConverterInterface $sourceConverter, FilenameConverterInterface $targetConverter) { $this->targetIterator = $targetIterator; $this->sourceConverter = $sourceConverter; $this->targetConverter = $targetConverter; parent::__construct($sourceIterator); }
function __construct(\Iterator $iterator, array $filters) { foreach ($filters as $filter) { $this->filters[] = $filter; } parent::__construct($iterator); }
/** * Creates a FilterIterator for Zym_Navigation_Iterator_Dfs * * @param Zym_Navigation_Iterator_Dfs $iterator iterator to iterate * @param bool $parentDependent [optional] whether page should be * invisible if parent is invisible, * defaults to true */ public function __construct(Zym_Navigation_Iterator_Dfs $iterator, $parentDependent = null) { parent::__construct($iterator); if (is_bool($parentDependent)) { $this->_parentDependent = $parentDependent; } }
/** * Constructor. * * @param \RecursiveIteratorIterator $iterator The Iterator to filter * @param array $comparators An array of \NumberComparator instances */ public function __construct(\RecursiveIteratorIterator $iterator, array $comparators) { $minDepth = 0; $maxDepth = INF; foreach ($comparators as $comparator) { switch ($comparator->getOperator()) { case '>': $minDepth = $comparator->getTarget() + 1; break; case '>=': $minDepth = $comparator->getTarget(); break; case '<': $maxDepth = $comparator->getTarget() - 1; break; case '<=': $maxDepth = $comparator->getTarget(); break; default: $minDepth = $maxDepth = $comparator->getTarget(); } } $this->minDepth = $minDepth; $iterator->setMaxDepth(INF === $maxDepth ? -1 : $maxDepth); parent::__construct($iterator); }
function __construct(array $ignore, $path, $it, $role) { $this->ignore = $ignore; $this->path = $path; $this->role = $role; parent::__construct($it); }
/** * Create an instance of the locator iterator * * Expects either a directory, or a DirectoryIterator (or its recursive variant) * instance. * * @param string|DirectoryIterator $dirOrIterator */ public function __construct($dirOrIterator = '.') { if (is_string($dirOrIterator)) { if (!is_dir($dirOrIterator)) { throw new InvalidArgumentException('Expected a valid directory name'); } $dirOrIterator = new RecursiveDirectoryIterator($dirOrIterator); } if (!$dirOrIterator instanceof DirectoryIterator) { throw new InvalidArgumentException('Expected a DirectoryIterator'); } if ($dirOrIterator instanceof RecursiveIterator) { $iterator = new RecursiveIteratorIterator($dirOrIterator); } else { $iterator = $dirOrIterator; } parent::__construct($iterator); $this->setInfoClass('Zend_File_PhpClassFile'); // Forward-compat with PHP 5.3 if (version_compare(PHP_VERSION, '5.3.0', '<')) { if (!defined('T_NAMESPACE')) { define('T_NAMESPACE', 'namespace'); } if (!defined('T_NS_SEPARATOR')) { define('T_NS_SEPARATOR', '\\'); } } }
/** * Initializes an instance of <b>OfTypeIterator</b>. * * @param Iterator $iterator * @param string $type */ public function __construct(Iterator $iterator, $type) { parent::__construct($iterator); switch (strtolower($type)) { case 'int': case 'integer': $this->acceptCallback = function ($current) { return is_int($current); }; break; case 'float': case 'double': $this->acceptCallback = function ($current) { return is_float($current); }; break; case 'string': $this->acceptCallback = function ($current) { return is_string($current); }; break; case 'bool': case 'boolean': $this->acceptCallback = function ($current) { return is_bool($current); }; break; default: $this->acceptCallback = function ($current) use($type) { return $current instanceof $type; }; } }
function __construct(\Iterator $iterator, array $ignored) { parent::__construct($iterator); foreach ($ignored as $folder) { $this->ignored[] = $folder; } }
/** * @param \Traversable $transitions * @param object $subject * @param \ArrayAccess $context * @param EventInterface $event */ public function __construct(\Traversable $transitions, $subject, \ArrayAccess $context, EventInterface $event = null) { parent::__construct(new \IteratorIterator($transitions)); $this->subject = $subject; $this->context = $context; $this->event = $event; }
public function accept() { $return = true; if ($this->_filter['filterField'] && $this->_filter['filterCompare']) { $filterValue = $this->_filter['filterValue']; switch ($this->_filter['filterField']) { case 'price': $value = parent::current()->getPrice(); break; case 'code': $value = parent::current()->getCode(); break; case 'name': $value = parent::current()->getName(); break; default: $value = false; break; } switch ($this->_filter['filterCompare']) { case 'ilike': $return = $value == $filterValue; break; case 'bigger': $return = $value > $filterValue; break; case 'smaller': $return = $value < $filterValue; break; } } return $return; }
/** * RegexDirectoryIterator constructor. * * @param string $path * The path to scan. * @param string $regex * The regular expression to match, including delimiters. For example, * /\.yml$/ would list only files ending in .yml. */ public function __construct($path, $regex) { // Use FilesystemIterator to not iterate over the the . and .. directories. $iterator = new \FilesystemIterator($path); parent::__construct($iterator); $this->regex = $regex; }
/** * Constructor * * @param \Iterator $iterator Inner Iterator * @param int $appearsAfter The unix timestamp of file modification time * after which the update should appear in the result list */ public function __construct(\Iterator $iterator, $appearsAfter) { parent::__construct($iterator); $this->appearsAfter = $appearsAfter; if (empty($this->appearsAfter) || !is_numeric($appearsAfter)) { throw new \InvalidArgumentException(sprintf('Second parameter is expected to be valid number, "%s" given for class "%s".', $appearsAfter, get_class($this))); } }
/** * * @param \Iterator $iterator * @param type $included * @param type $excluded */ function __construct(\Iterator $iterator, $included, $excluded = "") { $this->textIncluded = $included; if (NULL !== $excluded) { $this->textExcluded = $excluded; } parent::__construct($iterator); }
/** * Constructor. * * @param \Iterator $iterator Source data * @param \Closure|callback $callback Filter callback * @throws \InvalidArgumentException Supplied callback is not callable */ public function __construct(\Iterator $iterator, $callback) { if (!is_callable($callback)) { throw new \InvalidArgumentException('Callback is not callable'); } parent::__construct($iterator); $this->callback = $callback; }
/** * Creates a filtered iterator using the callback to determine * which items are accepted or rejected. * * @param \Iterator $iterator The iterator to be filtered. * @param callable $callback The callback, which should return TRUE to accept the current item * or FALSE otherwise. May be any valid callable value. * The callback should accept up to three arguments: the current item, * the current key and the iterator, respectively. * ``` php * function my_callback($current, $key, $iterator) * ``` * * @throws InvalidArgumentException * * @since 1.2.0 */ public function __construct(\Iterator $iterator, $callback) { if (!is_callable($callback)) { throw new \InvalidArgumentException("Argument 2 of CallbackFilterIterator should be callable."); } $this->callback = $callback; parent::__construct($iterator); }
public function __construct($path, $predicate) { $this->predicate = $predicate; $this->path = $path; $it = new RecursiveDirectoryIterator($path); $flatIterator = new RecursiveDirectoryIterator($it); parent::__construct($flatIterator); }
public function __construct($path, Logger $logger = null, array $accepted_extensions = array(), array $ignored_directories = array()) { parent::__construct(new \DirectoryIterator($path)); $this->logger = $logger; //$this->setProcessFilesFlag($path); $this->accepted_extensions = $accepted_extensions; $this->ignored_directories = $ignored_directories; }
/** * @param Iterator * @param callable Signature: (mixed $current): bool. */ public function __construct(Iterator $iterator, $callback) { parent::__construct($iterator); if (!is_callable($callback)) { throw new Exception(pht('Callback must be callable.')); } $this->callback = $callback; }
/** * Class init. * * @param \Iterator $iterator * @param callable $callback * * @throws InvalidArgumentException */ public function __construct(\Iterator $iterator, $callback) { if (!is_callable($callback)) { throw new \InvalidArgumentException("Invalid callback"); } $this->callback = $callback; parent::__construct($iterator); }
/** * Constructor. * * @param Traversable $iter * @param \Closure $callback * * @throws InvalidArgumentException */ public function __construct(Traversable $iter, $callback) { parent::__construct($iter); if (!is_callable($callback)) { throw new InvalidArgumentException('Invalid Callback'); } $this->callback = $callback; }
public function current() { $tag = parent::current(); if ($tag) { $tag = substr($tag, 6); } return $tag; }
/** * @param $iterator * @param string/array Extension(s) that should be accepted */ function __construct($iterator, $extensions) { $this->it = $iterator; if (!is_array($extensions)) { $extensions = array($extensions); } $this->_extensions = $extensions; parent::__construct($this->it); }
public function __construct(\PharData $archive, $archive_file, $needle, $strip_tags = true) { $flags = \RecursiveIteratorIterator::LEAVES_ONLY; $it = new \RecursiveIteratorIterator($archive, $flags); parent::__construct($it); $this->archive_file = $archive_file; $this->needle = $needle; $this->strip_tags = $strip_tags; }
public function __construct($path = NULL, $recurse = true) { if (!is_null($path)) { $path = VIEWS . '/' . trim($path, '/'); } else { $path = VIEWS; } parent::__construct($recurse == true ? new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST) : new DirectoryIterator($path)); }