Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removeDuplicatedCookies() not in interface #1464

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions Nette/Http/IResponse.php
Expand Up @@ -130,5 +130,11 @@ function setCookie($name, $value, $expire, $path = NULL, $domain = NULL, $secure
* @return void
*/
function deleteCookie($name, $path = NULL, $domain = NULL, $secure = NULL);

/**
* Removes duplicate cookies from response.
* @return void
*/
public function removeDuplicateCookies();

}
6 changes: 3 additions & 3 deletions Nette/Latte/MacroTokens.php
Expand Up @@ -15,7 +15,7 @@
*
* @author David Grudl
*/
class MacroTokens extends Nette\Utils\TokenIterator
class MacroTokens extends TokenIterator
{
const T_WHITESPACE = 1,
T_COMMENT = 2,
Expand All @@ -27,7 +27,7 @@ class MacroTokens extends Nette\Utils\TokenIterator
T_KEYWORD = 8,
T_CHAR = 9;

/** @var Nette\Utils\Tokenizer */
/** @var Tokenizer */
private static $tokenizer;

/** @var int */
Expand All @@ -43,7 +43,7 @@ public function __construct($input = NULL)

public function parse($s)
{
self::$tokenizer = self::$tokenizer ?: new Nette\Utils\Tokenizer(array(
self::$tokenizer = self::$tokenizer ?: new Tokenizer(array(
self::T_WHITESPACE => '\s+',
self::T_COMMENT => '(?s)/\*.*?\*/',
self::T_STRING => Parser::RE_STRING,
Expand Down
2 changes: 1 addition & 1 deletion Nette/Latte/Macros/CoreMacros.php
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
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
Expand Up @@ -5,7 +5,7 @@
* Copyright (c) 2004 David Grudl (http://davidgrudl.com)
*/

namespace Nette\Utils;
namespace Nette\Latte;

use Nette;

Expand Down
86 changes: 86 additions & 0 deletions Nette/Latte/Tokenizer.php
@@ -0,0 +1,86 @@
<?php

/**
* This file is part of the Nette Framework (http://nette.org)
* Copyright (c) 2004 David Grudl (http://davidgrudl.com)
*/

namespace Nette\Latte;

use Nette,
Nette\Utils\Strings;


/**
* Simple lexical analyser. Internal class.
*
* @author David Grudl
* @internal
*/
class Tokenizer extends Nette\Object
{
const VALUE = 0,
OFFSET = 1,
TYPE = 2;

/** @var string */
private $re;

/** @var array */
private $types;


/**
* @param array of [(int) symbol type => pattern]
* @param string regular expression flag
*/
public function __construct(array $patterns, $flags = '')
{
$this->re = '~(' . implode(')|(', $patterns) . ')~A' . $flags;
$this->types = array_keys($patterns);
}


/**
* Tokenize string.
* @param string
* @return array
*/
public function tokenize($input)
{
$tokens = Strings::matchAll($input, $this->re);
$len = 0;
$count = count($this->types);
foreach ($tokens as & $match) {
$type = NULL;
for ($i = 1; $i <= $count; $i++) {
if (!isset($match[$i])) {
break;
} elseif ($match[$i] != NULL) {
$type = $this->types[$i - 1]; break;
}
}
$match = array(self::VALUE => $match[0], self::OFFSET => $len, self::TYPE => $type);
$len += strlen($match[self::VALUE]);
}
if ($len !== strlen($input)) {
list($line, $col) = $this->getCoordinates($input, $len);
$token = str_replace("\n", '\n', substr($input, $len, 10));
throw new TokenizerException("Unexpected '$token' on line $line, column $col.");
}
return $tokens;
}


/**
* Returns position of token in input string.
* @param int token number
* @return array [line, column]
*/
public static function getCoordinates($text, $offset)
{
$text = substr($text, 0, $offset);
return array(substr_count($text, "\n") + 1, $offset - strrpos("\n" . $text, "\n") + 1);
}

}
7 changes: 7 additions & 0 deletions Nette/Latte/exceptions.php
Expand Up @@ -20,4 +20,11 @@ class CompileException extends Nette\Templating\FilterException
}


/**
* The exception that indicates tokenizer error.
*/
class TokenizerException extends \Exception
{
}

class_alias('Nette\Latte\CompileException', 'Nette\Latte\ParseException');
5 changes: 4 additions & 1 deletion Nette/Loaders/NetteLoader.php
Expand Up @@ -33,6 +33,9 @@ class NetteLoader
'Nette\Utils\PhpGenerator\Parameter' => 'Nette\PhpGenerator\Parameter',
'Nette\Utils\PhpGenerator\PhpLiteral' => 'Nette\PhpGenerator\PhpLiteral',
'Nette\Utils\PhpGenerator\Property' => 'Nette\PhpGenerator\Property',
'Nette\Utils\Tokenizer' => 'Nette\Latte\Tokenizer',
'Nette\Utils\TokenIterator' => 'Nette\Latte\TokenIterator',
'Nette\Iterators\CachingIterator' => 'Nette\Latte\Runtime\CachingIterator',
);

/** @var array */
Expand Down Expand Up @@ -64,6 +67,7 @@ class NetteLoader
'Nette\InvalidArgumentException' => 'common/exceptions',
'Nette\InvalidStateException' => 'common/exceptions',
'Nette\Latte\CompileException' => 'Latte/exceptions',
'Nette\Latte\TokenizerException' => 'Latte/exceptions',
'Nette\Mail\SmtpException' => 'Mail/SmtpMailer',
'Nette\MemberAccessException' => 'common/exceptions',
'Nette\NotImplementedException' => 'common/exceptions',
Expand All @@ -79,7 +83,6 @@ class NetteLoader
'Nette\Utils\NeonEntity' => 'Utils/Neon',
'Nette\Utils\NeonException' => 'Utils/Neon',
'Nette\Utils\RegexpException' => 'Utils/Strings',
'Nette\Utils\TokenizerException' => 'Utils/Tokenizer',
);


Expand Down
107 changes: 0 additions & 107 deletions Nette/Utils/Tokenizer.php

This file was deleted.

@@ -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