public function testEach() { // from js $test =& $this; __::each(array(1, 2, 3), function ($num, $i) use($test) { $test->assertEquals($num, $i + 1, 'each iterators provide value and iteration count'); }); $answers = array(); $context = (object) array('multiplier' => 5); __::each(array(1, 2, 3), function ($num) use(&$answers, $context) { $answers[] = $num * $context->multiplier; }); $this->assertEquals(array(5, 10, 15), $answers, 'context object property accessed'); $answers = array(); $obj = (object) array('one' => 1, 'two' => 2, 'three' => 3); __::each($obj, function ($value, $key) use(&$answers) { $answers[] = $key; }); $this->assertEquals(array('one', 'two', 'three'), $answers, 'iterating over objects works'); $answer = null; __::each(array(1, 2, 3), function ($num, $index, $arr) use(&$answer) { if (__::includ($arr, $num)) { $answer = true; } }); $this->assertTrue($answer, 'can reference the original collection from inside the iterator'); $answers = 0; __::each(null, function () use(&$answers) { $answers++; }); $this->assertEquals(0, $answers, 'handles a null property'); // extra $test =& $this; __(array(1, 2, 3))->each(function ($num, $i) use($test) { $test->assertEquals($num, $i + 1, 'each iterators provide value and iteration count within OO-style call'); }); // docs $str = ''; __::each(array(1, 2, 3), function ($num) use(&$str) { $str .= $num . ','; }); $this->assertEquals('1,2,3,', $str); $str = ''; $multiplier = 2; __::each(array(1, 2, 3), function ($num, $index) use($multiplier, &$str) { $str .= $index . '=' . $num * $multiplier . ','; }); $this->assertEquals('0=2,1=4,2=6,', $str); }
function each_channel($template) { __::each($this->channels, $template); }
function each_item($template) { __::each($this->contents, $template); }
echo "No Talking Points Found. Exiting\n"; exit(0); } $points = __::reduce( $points_results->rows, function($memo, $row){ $memo[$row->value->handle] = $row->value->points; return $memo; },array() ); /* ======================= Configure SubscriptionFulfilment ----------------------- */ $fulfillment = new SubscriptionFulfillment(new EmailSubscriptionFulfillment()); /* ======================== Main Distribution processing ------------------------ */ __::each($subscriptions, function($subscription) use($points, $fulfillment){ if(!$subscription) continue; $pointsForSubscriber = __::reduce( $subscription->handles, function($memo, $handle) use ($points){ if(empty($points[$handle])) return $memo; return array_merge($memo, $points[$handle]); }, array()); $fulfillment->handle($subscription, $pointsForSubscriber); });