~canonical-sysadmins/wordpress/4.8.1

« back to all changes in this revision

Viewing changes to wp-includes/Requests/Utility/FilteredIterator.php

  • Committer: Barry Price
  • Date: 2016-08-17 04:50:12 UTC
  • mfrom: (1.1.18 upstream)
  • Revision ID: barry.price@canonical.com-20160817045012-qfui81zhqnqv2ba9
Merge WP4.6 from upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Iterator for arrays requiring filtered values
 
4
 *
 
5
 * @package Requests
 
6
 * @subpackage Utilities
 
7
 */
 
8
 
 
9
/**
 
10
 * Iterator for arrays requiring filtered values
 
11
 *
 
12
 * @package Requests
 
13
 * @subpackage Utilities
 
14
 */
 
15
class Requests_Utility_FilteredIterator extends ArrayIterator {
 
16
        /**
 
17
         * Callback to run as a filter
 
18
         *
 
19
         * @var callable
 
20
         */
 
21
        protected $callback;
 
22
 
 
23
        /**
 
24
         * Create a new iterator
 
25
         *
 
26
         * @param array $data
 
27
         * @param callable $callback Callback to be called on each value
 
28
         */
 
29
        public function __construct($data, $callback) {
 
30
                parent::__construct($data);
 
31
 
 
32
                $this->callback = $callback;
 
33
        }
 
34
 
 
35
        /**
 
36
         * Get the current item's value after filtering
 
37
         *
 
38
         * @return string
 
39
         */
 
40
        public function current() {
 
41
                $value = parent::current();
 
42
                $value = call_user_func($this->callback, $value);
 
43
                return $value;
 
44
        }
 
45
}