-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed1d146
commit d24a581
Showing
12 changed files
with
411 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
includes: | ||
- vendor/phpstan/phpstan-deprecation-rules/rules.neon | ||
- vendor/phpstan/phpstan-nette/extension.neon | ||
- vendor/phpstan/phpstan-nette/rules.neon | ||
- vendor/phpstan/phpstan-strict-rules/rules.neon | ||
|
||
parameters: | ||
level: max | ||
paths: | ||
- src | ||
- tests | ||
excludePaths: | ||
- src/Latte/TranslatorExtension.php | ||
- src/Latte/Nodes/* | ||
ignoreErrors: | ||
- | ||
count: 2 | ||
message: '#^Variable property access on object\.$#' | ||
path: 'src/Loaders/Doctrine.php' | ||
|
||
# ------------------------------------------------------------------- | ||
# for back compatibility with old packages - will be remove in future | ||
# ------------------------------------------------------------------- | ||
|
||
- | ||
message: """ | ||
#^Fetching class constant class of deprecated class Nette\\\\Localization\\\\ITranslator\\: | ||
use Nette\\\\Localization\\\\Translator$# | ||
""" | ||
count: 2 | ||
path: src/DI/TranslationExtension.php | ||
|
||
- | ||
count: 1 | ||
message: """ | ||
#^Parameter \\$translator of method Contributte\\\\Translation\\\\Latte\\\\Filters\\:\\:__construct\\(\\) has typehint with deprecated interface Nette\\\\Localization\\\\ITranslator\\: | ||
use Nette\\\\Localization\\\\Translator$# | ||
""" | ||
path: src/Latte/Filters.php | ||
|
||
- | ||
count: 1 | ||
message: """ | ||
#^Call to an undefined method Nette\\\\Localization\\\\ITranslator::translate\\(\\)# | ||
""" | ||
path: src/Latte/Filters.php | ||
|
||
- | ||
count: 1 | ||
message: """ | ||
#^Parameter \\$translator of method Contributte\\\\Translation\\\\Latte\\\\TranslatorExtension\\:\\:__construct\\(\\) has typehint with deprecated interface Nette\\\\Localization\\\\ITranslator\\: | ||
use Nette\\\\Localization\\\\Translator$# | ||
""" | ||
path: src/Latte/TranslatorExtension.php | ||
|
||
- | ||
count: 1 | ||
message: """ | ||
#^Class Contributte\\\\Translation\\\\PrefixedTranslator implements deprecated interface Nette\\\\Localization\\\\ITranslator\\: | ||
use Nette\\\\Localization\\\\Translator$# | ||
""" | ||
path: src/PrefixedTranslator.php | ||
|
||
- | ||
count: 1 | ||
message: """ | ||
#^Class Contributte\\\\Translation\\\\Translator implements deprecated interface Nette\\\\Localization\\\\ITranslator\\: | ||
use Nette\\\\Localization\\\\Translator$# | ||
""" | ||
path: src/Translator.php | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Contributte\Translation\Latte\Nodes; | ||
|
||
use Latte\Compiler\NodeHelpers; | ||
use Latte\Compiler\Nodes\AreaNode; | ||
use Latte\Compiler\Nodes\NopNode; | ||
use Latte\Compiler\Nodes\Php; | ||
use Latte\Compiler\Nodes\Php\ModifierNode; | ||
use Latte\Compiler\Nodes\StatementNode; | ||
use Latte\Compiler\Nodes\TextNode; | ||
use Latte\Compiler\PrintContext; | ||
use Latte\Compiler\Tag; | ||
|
||
class TranslateNode extends StatementNode | ||
{ | ||
|
||
public AreaNode $content; | ||
|
||
public ModifierNode $modifier; | ||
|
||
/** @return \Generator<int, ?array<mixed>, array{AreaNode, ?Tag}, TranslateNode|NopNode> */ | ||
public static function create( | ||
Tag $tag | ||
): \Generator | ||
{ | ||
$tag->outputMode = $tag::OutputKeepIndentation; | ||
|
||
$node = new TranslateNode(); | ||
$args = $tag->parser->parseArguments(); | ||
$node->modifier = $tag->parser->parseModifier(); | ||
$node->modifier->escape = true; | ||
if ($tag->void) { | ||
return new NopNode(); | ||
} | ||
|
||
[$node->content] = yield; | ||
|
||
if (($text = NodeHelpers::toText($node->content)) !== null) { | ||
$node->content = new TextNode($text); | ||
} | ||
|
||
array_unshift($node->modifier->filters, new Php\FilterNode(new Php\IdentifierNode('translate'), $args->toArguments())); | ||
|
||
return $node; | ||
} | ||
|
||
|
||
public function print( | ||
PrintContext $context | ||
): string | ||
{ | ||
if ($this->content instanceof TextNode) { | ||
return $context->format( | ||
' | ||
$ʟ_fi = new LR\FilterInfo(%dump); | ||
echo %modifyContent(%dump) %line; | ||
', | ||
$context->getEscaper()->export(), | ||
$this->modifier, | ||
$this->content->content, | ||
$this->position, | ||
); | ||
|
||
} else { | ||
return $context->format( | ||
' | ||
ob_start(fn() => ""); try { | ||
%node | ||
} finally { | ||
$ʟ_tmp = ob_get_clean(); | ||
} | ||
$ʟ_fi = new LR\FilterInfo(%dump); | ||
echo %modifyContent($ʟ_tmp) %line; | ||
', | ||
$this->content, | ||
$context->getEscaper()->export(), | ||
$this->modifier, | ||
$this->position, | ||
); | ||
} | ||
} | ||
|
||
|
||
public function &getIterator(): \Generator | ||
{ | ||
yield $this->content; | ||
yield $this->modifier; | ||
} | ||
|
||
} |
Oops, something went wrong.