Skip to content

Commit

Permalink
Nette\Iterators\CachingIterator renamed to Nette\Latte\Runtime\Cachin…
Browse files Browse the repository at this point in the history
…gIterator (BC break!)
  • Loading branch information
dg committed Mar 21, 2014
1 parent 4ab7e5a commit 5f4b5b3
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Nette/Latte/Macros/CoreMacros.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public function macroCaptureEnd(MacroNode $node, PhpWriter $writer)
public function macroEndForeach(MacroNode $node, PhpWriter $writer)
{
if ($node->modifiers !== '|noiterator' && preg_match('#\W(\$iterator|include|require|get_defined_vars)\W#', $this->getCompiler()->expandTokens($node->content))) {
$node->openingCode = '<?php $iterations = 0; foreach ($iterator = $_l->its[] = new Nette\Iterators\CachingIterator('
$node->openingCode = '<?php $iterations = 0; foreach ($iterator = $_l->its[] = new Nette\Latte\Runtime\CachingIterator('
. preg_replace('#(.*)\s+as\s+#i', '$1) as ', $writer->formatArgs(), 1) . ') { ?>';
$node->closingCode = '<?php $iterations++; } array_pop($_l->its); $iterator = end($_l->its) ?>';
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Copyright (c) 2004 David Grudl (http://davidgrudl.com)
*/

namespace Nette\Iterators;
namespace Nette\Latte\Runtime;

use Nette;

Expand Down
1 change: 1 addition & 0 deletions Nette/Loaders/NetteLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class NetteLoader
'Nette\Utils\PhpGenerator\Parameter' => 'Nette\PhpGenerator\Parameter',
'Nette\Utils\PhpGenerator\PhpLiteral' => 'Nette\PhpGenerator\PhpLiteral',
'Nette\Utils\PhpGenerator\Property' => 'Nette\PhpGenerator\Property',
'Nette\Iterators\CachingIterator' => 'Nette\Latte\Runtime\CachingIterator',
);

/** @var array */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

/**
* Test: Nette\Iterators\CachingIterator basic usage.
* Test: Nette\Latte\Runtime\CachingIterator basic usage.
*
* @author David Grudl
*/

use Nette\Iterators,
use Nette\Latte\Runtime\CachingIterator,
Tester\Assert;


Expand All @@ -17,7 +17,7 @@ test(function() { // ==> Two items in array

$arr = array('Nette', 'Framework');

$iterator = new Iterators\CachingIterator($arr);
$iterator = new CachingIterator($arr);
$iterator->rewind();
Assert::true( $iterator->valid() );
Assert::true( $iterator->isFirst() );
Expand All @@ -44,7 +44,7 @@ test(function() { // ==> Two items in array
test(function() {
$arr = array('Nette');

$iterator = new Iterators\CachingIterator($arr);
$iterator = new CachingIterator($arr);
$iterator->rewind();
Assert::true( $iterator->valid() );
Assert::true( $iterator->isFirst() );
Expand All @@ -65,7 +65,7 @@ test(function() {
test(function() {
$arr = array();

$iterator = new Iterators\CachingIterator($arr);
$iterator = new CachingIterator($arr);
$iterator->next();
$iterator->next();
Assert::false( $iterator->isFirst() );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

/**
* Test: Nette\Iterators\CachingIterator constructor.
* Test: Nette\Latte\Runtime\CachingIterator constructor.
*
* @author David Grudl
*/

use Nette\Iterators,
use Nette\Latte\Runtime\CachingIterator,
Tester\Assert;


Expand All @@ -16,7 +16,7 @@ require __DIR__ . '/../bootstrap.php';
test(function() { // ==> array
$arr = array('Nette', 'Framework');
$tmp = array();
foreach (new Iterators\CachingIterator($arr) as $k => $v) $tmp[] = "$k => $v";
foreach (new CachingIterator($arr) as $k => $v) $tmp[] = "$k => $v";
Assert::same( array(
'0 => Nette',
'1 => Framework',
Expand All @@ -27,7 +27,7 @@ test(function() { // ==> array
test(function() { // ==> stdClass
$arr = (object) array('Nette', 'Framework');
$tmp = array();
foreach (new Iterators\CachingIterator($arr) as $k => $v) $tmp[] = "$k => $v";
foreach (new CachingIterator($arr) as $k => $v) $tmp[] = "$k => $v";
Assert::same( array(
'0 => Nette',
'1 => Framework',
Expand All @@ -38,7 +38,7 @@ test(function() { // ==> stdClass
test(function() { // ==> IteratorAggregate
$arr = new ArrayObject(array('Nette', 'Framework'));
$tmp = array();
foreach (new Iterators\CachingIterator($arr) as $k => $v) $tmp[] = "$k => $v";
foreach (new CachingIterator($arr) as $k => $v) $tmp[] = "$k => $v";
Assert::same( array(
'0 => Nette',
'1 => Framework',
Expand All @@ -49,7 +49,7 @@ test(function() { // ==> IteratorAggregate
test(function() { // ==> Iterator
$arr = new ArrayObject(array('Nette', 'Framework'));
$tmp = array();
foreach (new Iterators\CachingIterator($arr->getIterator()) as $k => $v) $tmp[] = "$k => $v";
foreach (new CachingIterator($arr->getIterator()) as $k => $v) $tmp[] = "$k => $v";
Assert::same( array(
'0 => Nette',
'1 => Framework',
Expand All @@ -60,7 +60,7 @@ test(function() { // ==> Iterator
test(function() { // ==> SimpleXMLElement
$arr = new SimpleXMLElement('<feed><item>Nette</item><item>Framework</item></feed>');
$tmp = array();
foreach (new Iterators\CachingIterator($arr) as $k => $v) $tmp[] = "$k => $v";
foreach (new CachingIterator($arr) as $k => $v) $tmp[] = "$k => $v";
Assert::same( array(
'item => Nette',
'item => Framework',
Expand All @@ -71,6 +71,6 @@ test(function() { // ==> SimpleXMLElement
test(function() { // ==> object
Assert::exception(function() {
$arr = dir('.');
foreach (new Iterators\CachingIterator($arr) as $k => $v);
foreach (new CachingIterator($arr) as $k => $v);
}, 'InvalidArgumentException', NULL);
});
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

/**
* Test: Nette\Iterators\CachingIterator width.
* Test: Nette\Latte\Runtime\CachingIterator width.
*
* @author David Grudl
*/

use Nette\Iterators,
use Nette\Latte\Runtime\CachingIterator,
Tester\Assert;


Expand All @@ -16,7 +16,7 @@ require __DIR__ . '/../bootstrap.php';
test(function() {
$arr = array('The', 'Nette', 'Framework');

$iterator = new Iterators\CachingIterator($arr);
$iterator = new CachingIterator($arr);
$iterator->rewind();

$iterator->rewind();
Expand Down Expand Up @@ -52,7 +52,7 @@ test(function() {


test(function() {
$iterator = new Iterators\CachingIterator(array());
$iterator = new CachingIterator(array());
Assert::false( $iterator->isFirst(0) );
Assert::true( $iterator->isLast(0) );
Assert::false( $iterator->isFirst(1) );
Expand Down
2 changes: 1 addition & 1 deletion tests/Nette/Latte/CoreMacros.foreach.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require __DIR__ . '/../bootstrap.php';
$compiler = new Nette\Latte\Compiler;
CoreMacros::install($compiler);

$prefix = '<?php $iterations = 0; foreach ($iterator = $_l->its[] = new Nette\Iterators\CachingIterator(';
$prefix = '<?php $iterations = 0; foreach ($iterator = $_l->its[] = new Nette\Latte\Runtime\CachingIterator(';

function expandMacro($compiler, $args, $modifiers = NULL) {
$node = $compiler->expandMacro('foreach', $args, $modifiers);
Expand Down
2 changes: 1 addition & 1 deletion tests/Nette/Latte/expected/macros.dynamicblock.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ $var = 10 ?>
call_user_func(reset($_l->blocks['static']), $_l, get_defined_vars()) ?>


<?php $iterations = 0; foreach ($iterator = $_l->its[] = new Nette\Iterators\CachingIterator(array('dynamic', 'static')) as $name) {
<?php $iterations = 0; foreach ($iterator = $_l->its[] = new Nette\Latte\Runtime\CachingIterator(array('dynamic', 'static')) as $name) {

//
// block $name
Expand Down
8 changes: 4 additions & 4 deletions tests/Nette/Latte/expected/macros.first-sep-last.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@ if (%A%}
//
?>

<?php $iterations = 0; foreach ($iterator = $_l->its[] = new Nette\Iterators\CachingIterator($people) as $person) { ?>
<?php $iterations = 0; foreach ($iterator = $_l->its[] = new Nette\Latte\Runtime\CachingIterator($people) as $person) { ?>
<?php if ($iterator->isFirst()) { ?>(<?php } ?> <?php echo Nette\Latte\Runtime\Filters::escapeHtml($person, ENT_NOQUOTES) ;if (!$iterator->isLast()) { ?>
, <?php } ?> <?php if ($iterator->isLast()) { ?>)<?php } ?>

<?php $iterations++; } array_pop($_l->its); $iterator = end($_l->its) ?>


<?php $iterations = 0; foreach ($iterator = $_l->its[] = new Nette\Iterators\CachingIterator($people) as $person) { ?>
<?php $iterations = 0; foreach ($iterator = $_l->its[] = new Nette\Latte\Runtime\CachingIterator($people) as $person) { ?>
<?php if ($iterator->isFirst(2)) { ?>(<?php } ?> <?php echo Nette\Latte\Runtime\Filters::escapeHtml($person, ENT_NOQUOTES) ;if (!$iterator->isLast(2)) { ?>
, <?php } ?> <?php if ($iterator->isLast(2)) { ?>)<?php } ?>

<?php $iterations++; } array_pop($_l->its); $iterator = end($_l->its) ?>


<?php $iterations = 0; foreach ($iterator = $_l->its[] = new Nette\Iterators\CachingIterator($people) as $person) { ?>
<?php $iterations = 0; foreach ($iterator = $_l->its[] = new Nette\Latte\Runtime\CachingIterator($people) as $person) { ?>
<?php if ($iterator->isFirst(1)) { ?>(<?php } ?> <?php echo Nette\Latte\Runtime\Filters::escapeHtml($person, ENT_NOQUOTES) ;if (!$iterator->isLast(1)) { ?>
, <?php } ?> <?php if ($iterator->isLast(1)) { ?>)<?php } ?>

<?php $iterations++; } array_pop($_l->its); $iterator = end($_l->its) ?>


<?php $iterations = 0; foreach ($iterator = $_l->its[] = new Nette\Iterators\CachingIterator($people) as $person) { if ($iterator->isFirst(0)) { ?>
<?php $iterations = 0; foreach ($iterator = $_l->its[] = new Nette\Latte\Runtime\CachingIterator($people) as $person) { if ($iterator->isFirst(0)) { ?>
<span>(</span><?php } ?>
<?php echo Nette\Latte\Runtime\Filters::escapeHtml($person, ENT_NOQUOTES) ;if (!$iterator->isLast()) { ?>
<span>, </span><?php } ?>
Expand Down
8 changes: 4 additions & 4 deletions tests/Nette/Latte/expected/macros.general.html.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ list($_l, $_g) = Nette\Latte\Macros\CoreMacros::initRuntime($template, 'xxx')
//
if (!function_exists($_l->blocks['menu'][] = '_xxx_menu')) { function _xxx_menu($_l, $_args) { foreach ($_args as $__k => $__v) $$__k = $__v
?><ul>
<?php $iterations = 0; foreach ($iterator = $_l->its[] = new Nette\Iterators\CachingIterator($menu) as $item) { ?>
<?php $iterations = 0; foreach ($iterator = $_l->its[] = new Nette\Latte\Runtime\CachingIterator($menu) as $item) { ?>
<li><?php echo Nette\Latte\Runtime\Filters::escapeHtml($counter++, ENT_NOQUOTES) ?>
<?php if (is_array($item)) { ?> <?php call_user_func(reset($_l->blocks['menu']), $_l, array('menu' => $item) + get_defined_vars()) ?>
<?php } else { echo Nette\Latte\Runtime\Filters::escapeHtml($item, ENT_NOQUOTES) ;} ?></li>
Expand Down Expand Up @@ -102,7 +102,7 @@ if ($_l->extends) {
<?php } ?>


<?php $iterations = 0; foreach ($iterator = $_l->its[] = new Nette\Iterators\CachingIterator(array(TRUE)) as $foo) { $iterations = 0; foreach ($iterator = $_l->its[] = new Nette\Iterators\CachingIterator($people) as $person) { ?>
<?php $iterations = 0; foreach ($iterator = $_l->its[] = new Nette\Latte\Runtime\CachingIterator(array(TRUE)) as $foo) { $iterations = 0; foreach ($iterator = $_l->its[] = new Nette\Latte\Runtime\CachingIterator($people) as $person) { ?>
<?php if ($iterator->isFirst()) { ?><ul><?php } ?>

<li id="item-<?php echo htmlSpecialChars($iterator->getCounter()) ?>" class="<?php echo htmlSpecialChars($iterator->isOdd() ? 'odd' : 'even') ?>
Expand Down Expand Up @@ -269,11 +269,11 @@ bold<?php if (array_pop($_l->ifs)) { ?></b>
<?php ob_start() ?>TRUE<?php ob_start() ?>FALSE<?php if (TRUE) { ob_end_clean(); ob_end_flush(); } else { $_else = ob_get_contents(); ob_end_clean(); ob_end_clean(); echo $_else; } ?>


<?php $iterations = 0; foreach ($iterator = $_l->its[] = new Nette\Iterators\CachingIterator(array(1,2,3)) as $foo) { ?>
<?php $iterations = 0; foreach ($iterator = $_l->its[] = new Nette\Latte\Runtime\CachingIterator(array(1,2,3)) as $foo) { ?>
<b<?php if ($_l->tmp = array_filter(array($iterator->even ? 'even' : NULL))) echo ' class="' . htmlSpecialChars(implode(" ", array_unique($_l->tmp))) . '"' ?>>item</b>
<?php $iterations++; } array_pop($_l->its); $iterator = end($_l->its) ?>

<?php $iterations = 0; foreach ($iterator = $_l->its[] = new Nette\Iterators\CachingIterator(array(1, 2, 3)) as $foo) { ?>
<?php $iterations = 0; foreach ($iterator = $_l->its[] = new Nette\Latte\Runtime\CachingIterator(array(1, 2, 3)) as $foo) { ?>
<p<?php if ($_l->tmp = array_filter(array($iterator->even ? 'even' : NULL))) echo ' class="' . htmlSpecialChars(implode(" ", array_unique($_l->tmp))) . '"' ?>
><?php echo Nette\Latte\Runtime\Filters::escapeHtml($foo, ENT_NOQUOTES) ?></p>
<?php $iterations++; } array_pop($_l->its); $iterator = end($_l->its) ?>
Expand Down
2 changes: 1 addition & 1 deletion tests/Nette/Latte/expected/macros.general.xhtml.menu.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if (%A%}
//
?>
<ul>
<?php $iterations = 0; foreach ($iterator = $_l->its[] = new Nette\Iterators\CachingIterator($menu) as $item) { ?>
<?php $iterations = 0; foreach ($iterator = $_l->its[] = new Nette\Latte\Runtime\CachingIterator($menu) as $item) { ?>
<li><?php if (is_array($item)) { ?> <?php Nette\Latte\Macros\CoreMacros::includeTemplate('@menu.latte', array('menu' => $item) + $template->getParameters(), $_l->templates['xxx'])->render() ?>
<?php } else { echo Nette\Latte\Runtime\Filters::escapeHtml($item, ENT_NOQUOTES) ;} ?></li>
<?php $iterations++; } array_pop($_l->its); $iterator = end($_l->its) ?>
Expand Down
8 changes: 4 additions & 4 deletions tests/Nette/Latte/expected/macros.general.xhtml.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ list($_l, $_g) = Nette\Latte\Macros\CoreMacros::initRuntime($template, 'xxx')
//
if (!function_exists($_l->blocks['menu'][] = '_xxx_menu')) { function _xxx_menu($_l, $_args) { foreach ($_args as $__k => $__v) $$__k = $__v
?><ul>
<?php $iterations = 0; foreach ($iterator = $_l->its[] = new Nette\Iterators\CachingIterator($menu) as $item) { ?>
<?php $iterations = 0; foreach ($iterator = $_l->its[] = new Nette\Latte\Runtime\CachingIterator($menu) as $item) { ?>
<li><?php echo Nette\Latte\Runtime\Filters::escapeHtml($counter++, ENT_NOQUOTES) ?>
<?php if (is_array($item)) { ?> <?php call_user_func(reset($_l->blocks['menu']), $_l, array('menu' => $item) + get_defined_vars()) ?>
<?php } else { echo Nette\Latte\Runtime\Filters::escapeHtml($item, ENT_NOQUOTES) ;} ?></li>
Expand Down Expand Up @@ -98,7 +98,7 @@ if ($_l->extends) {
<?php } ?>


<?php $iterations = 0; foreach ($iterator = $_l->its[] = new Nette\Iterators\CachingIterator(array(TRUE)) as $foo) { $iterations = 0; foreach ($iterator = $_l->its[] = new Nette\Iterators\CachingIterator($people) as $person) { ?>
<?php $iterations = 0; foreach ($iterator = $_l->its[] = new Nette\Latte\Runtime\CachingIterator(array(TRUE)) as $foo) { $iterations = 0; foreach ($iterator = $_l->its[] = new Nette\Latte\Runtime\CachingIterator($people) as $person) { ?>
<?php if ($iterator->isFirst()) { ?><ul><?php } ?>

<li id="item-<?php echo htmlSpecialChars($iterator->getCounter()) ?>" class="<?php echo htmlSpecialChars($iterator->isOdd() ? 'odd' : 'even') ?>
Expand Down Expand Up @@ -265,11 +265,11 @@ bold<?php if (array_pop($_l->ifs)) { ?></b>
<?php ob_start() ?>TRUE<?php ob_start() ?>FALSE<?php if (TRUE) { ob_end_clean(); ob_end_flush(); } else { $_else = ob_get_contents(); ob_end_clean(); ob_end_clean(); echo $_else; } ?>


<?php $iterations = 0; foreach ($iterator = $_l->its[] = new Nette\Iterators\CachingIterator(array(1,2,3)) as $foo) { ?>
<?php $iterations = 0; foreach ($iterator = $_l->its[] = new Nette\Latte\Runtime\CachingIterator(array(1,2,3)) as $foo) { ?>
<b<?php if ($_l->tmp = array_filter(array($iterator->even ? 'even' : NULL))) echo ' class="' . htmlSpecialChars(implode(" ", array_unique($_l->tmp))) . '"' ?>>item</b>
<?php $iterations++; } array_pop($_l->its); $iterator = end($_l->its) ?>

<?php $iterations = 0; foreach ($iterator = $_l->its[] = new Nette\Iterators\CachingIterator(array(1, 2, 3)) as $foo) { ?>
<?php $iterations = 0; foreach ($iterator = $_l->its[] = new Nette\Latte\Runtime\CachingIterator(array(1, 2, 3)) as $foo) { ?>
<p<?php if ($_l->tmp = array_filter(array($iterator->even ? 'even' : NULL))) echo ' class="' . htmlSpecialChars(implode(" ", array_unique($_l->tmp))) . '"' ?>
><?php echo Nette\Latte\Runtime\Filters::escapeHtml($foo, ENT_NOQUOTES) ?></p>
<?php $iterations++; } array_pop($_l->its); $iterator = end($_l->its) ?>
Expand Down

0 comments on commit 5f4b5b3

Please sign in to comment.