PDF rausgenommen
This commit is contained in:
111
msd2/phpBB3/vendor/symfony/twig-bridge/NodeVisitor/Scope.php
vendored
Normal file
111
msd2/phpBB3/vendor/symfony/twig-bridge/NodeVisitor/Scope.php
vendored
Normal file
@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bridge\Twig\NodeVisitor;
|
||||
|
||||
/**
|
||||
* @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
|
||||
*/
|
||||
class Scope
|
||||
{
|
||||
private $parent;
|
||||
private $data = array();
|
||||
private $left = false;
|
||||
|
||||
public function __construct(Scope $parent = null)
|
||||
{
|
||||
$this->parent = $parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a new child scope.
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function enter()
|
||||
{
|
||||
return new self($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes current scope and returns parent one.
|
||||
*
|
||||
* @return self|null
|
||||
*/
|
||||
public function leave()
|
||||
{
|
||||
$this->left = true;
|
||||
|
||||
return $this->parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores data into current scope.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @throws \LogicException
|
||||
*/
|
||||
public function set($key, $value)
|
||||
{
|
||||
if ($this->left) {
|
||||
throw new \LogicException('Left scope is not mutable.');
|
||||
}
|
||||
|
||||
$this->data[$key] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if a data is visible from current scope.
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function has($key)
|
||||
{
|
||||
if (array_key_exists($key, $this->data)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (null === $this->parent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->parent->has($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns data visible from current scope.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key, $default = null)
|
||||
{
|
||||
if (array_key_exists($key, $this->data)) {
|
||||
return $this->data[$key];
|
||||
}
|
||||
|
||||
if (null === $this->parent) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
return $this->parent->get($key, $default);
|
||||
}
|
||||
}
|
134
msd2/phpBB3/vendor/symfony/twig-bridge/NodeVisitor/TranslationDefaultDomainNodeVisitor.php
vendored
Normal file
134
msd2/phpBB3/vendor/symfony/twig-bridge/NodeVisitor/TranslationDefaultDomainNodeVisitor.php
vendored
Normal file
@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bridge\Twig\NodeVisitor;
|
||||
|
||||
use Symfony\Bridge\Twig\Node\TransDefaultDomainNode;
|
||||
use Symfony\Bridge\Twig\Node\TransNode;
|
||||
use Twig\Environment;
|
||||
use Twig\Node\BlockNode;
|
||||
use Twig\Node\Expression\ArrayExpression;
|
||||
use Twig\Node\Expression\AssignNameExpression;
|
||||
use Twig\Node\Expression\ConstantExpression;
|
||||
use Twig\Node\Expression\FilterExpression;
|
||||
use Twig\Node\Expression\NameExpression;
|
||||
use Twig\Node\ModuleNode;
|
||||
use Twig\Node\Node;
|
||||
use Twig\Node\SetNode;
|
||||
use Twig\NodeVisitor\AbstractNodeVisitor;
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class TranslationDefaultDomainNodeVisitor extends AbstractNodeVisitor
|
||||
{
|
||||
private $scope;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->scope = new Scope();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doEnterNode(Node $node, Environment $env)
|
||||
{
|
||||
if ($node instanceof BlockNode || $node instanceof ModuleNode) {
|
||||
$this->scope = $this->scope->enter();
|
||||
}
|
||||
|
||||
if ($node instanceof TransDefaultDomainNode) {
|
||||
if ($node->getNode('expr') instanceof ConstantExpression) {
|
||||
$this->scope->set('domain', $node->getNode('expr'));
|
||||
|
||||
return $node;
|
||||
} else {
|
||||
$var = $this->getVarName();
|
||||
$name = new AssignNameExpression($var, $node->getTemplateLine());
|
||||
$this->scope->set('domain', new NameExpression($var, $node->getTemplateLine()));
|
||||
|
||||
return new SetNode(false, new Node(array($name)), new Node(array($node->getNode('expr'))), $node->getTemplateLine());
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->scope->has('domain')) {
|
||||
return $node;
|
||||
}
|
||||
|
||||
if ($node instanceof FilterExpression && \in_array($node->getNode('filter')->getAttribute('value'), array('trans', 'transchoice'))) {
|
||||
$arguments = $node->getNode('arguments');
|
||||
$ind = 'trans' === $node->getNode('filter')->getAttribute('value') ? 1 : 2;
|
||||
if ($this->isNamedArguments($arguments)) {
|
||||
if (!$arguments->hasNode('domain') && !$arguments->hasNode($ind)) {
|
||||
$arguments->setNode('domain', $this->scope->get('domain'));
|
||||
}
|
||||
} else {
|
||||
if (!$arguments->hasNode($ind)) {
|
||||
if (!$arguments->hasNode($ind - 1)) {
|
||||
$arguments->setNode($ind - 1, new ArrayExpression(array(), $node->getTemplateLine()));
|
||||
}
|
||||
|
||||
$arguments->setNode($ind, $this->scope->get('domain'));
|
||||
}
|
||||
}
|
||||
} elseif ($node instanceof TransNode) {
|
||||
if (!$node->hasNode('domain')) {
|
||||
$node->setNode('domain', $this->scope->get('domain'));
|
||||
}
|
||||
}
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doLeaveNode(Node $node, Environment $env)
|
||||
{
|
||||
if ($node instanceof TransDefaultDomainNode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($node instanceof BlockNode || $node instanceof ModuleNode) {
|
||||
$this->scope = $this->scope->leave();
|
||||
}
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPriority()
|
||||
{
|
||||
return -10;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
private function isNamedArguments($arguments)
|
||||
{
|
||||
foreach ($arguments as $name => $node) {
|
||||
if (!\is_int($name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function getVarName()
|
||||
{
|
||||
return sprintf('__internal_%s', hash('sha256', uniqid(mt_rand(), true), false));
|
||||
}
|
||||
}
|
136
msd2/phpBB3/vendor/symfony/twig-bridge/NodeVisitor/TranslationNodeVisitor.php
vendored
Normal file
136
msd2/phpBB3/vendor/symfony/twig-bridge/NodeVisitor/TranslationNodeVisitor.php
vendored
Normal file
@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bridge\Twig\NodeVisitor;
|
||||
|
||||
use Symfony\Bridge\Twig\Node\TransNode;
|
||||
use Twig\Environment;
|
||||
use Twig\Node\Expression\ConstantExpression;
|
||||
use Twig\Node\Expression\FilterExpression;
|
||||
use Twig\Node\Node;
|
||||
use Twig\NodeVisitor\AbstractNodeVisitor;
|
||||
|
||||
/**
|
||||
* TranslationNodeVisitor extracts translation messages.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class TranslationNodeVisitor extends AbstractNodeVisitor
|
||||
{
|
||||
const UNDEFINED_DOMAIN = '_undefined';
|
||||
|
||||
private $enabled = false;
|
||||
private $messages = array();
|
||||
|
||||
public function enable()
|
||||
{
|
||||
$this->enabled = true;
|
||||
$this->messages = array();
|
||||
}
|
||||
|
||||
public function disable()
|
||||
{
|
||||
$this->enabled = false;
|
||||
$this->messages = array();
|
||||
}
|
||||
|
||||
public function getMessages()
|
||||
{
|
||||
return $this->messages;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doEnterNode(Node $node, Environment $env)
|
||||
{
|
||||
if (!$this->enabled) {
|
||||
return $node;
|
||||
}
|
||||
|
||||
if (
|
||||
$node instanceof FilterExpression &&
|
||||
'trans' === $node->getNode('filter')->getAttribute('value') &&
|
||||
$node->getNode('node') instanceof ConstantExpression
|
||||
) {
|
||||
// extract constant nodes with a trans filter
|
||||
$this->messages[] = array(
|
||||
$node->getNode('node')->getAttribute('value'),
|
||||
$this->getReadDomainFromArguments($node->getNode('arguments'), 1),
|
||||
);
|
||||
} elseif (
|
||||
$node instanceof FilterExpression &&
|
||||
'transchoice' === $node->getNode('filter')->getAttribute('value') &&
|
||||
$node->getNode('node') instanceof ConstantExpression
|
||||
) {
|
||||
// extract constant nodes with a trans filter
|
||||
$this->messages[] = array(
|
||||
$node->getNode('node')->getAttribute('value'),
|
||||
$this->getReadDomainFromArguments($node->getNode('arguments'), 2),
|
||||
);
|
||||
} elseif ($node instanceof TransNode) {
|
||||
// extract trans nodes
|
||||
$this->messages[] = array(
|
||||
$node->getNode('body')->getAttribute('data'),
|
||||
$node->hasNode('domain') ? $this->getReadDomainFromNode($node->getNode('domain')) : null,
|
||||
);
|
||||
}
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doLeaveNode(Node $node, Environment $env)
|
||||
{
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPriority()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Node $arguments
|
||||
* @param int $index
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
private function getReadDomainFromArguments(Node $arguments, $index)
|
||||
{
|
||||
if ($arguments->hasNode('domain')) {
|
||||
$argument = $arguments->getNode('domain');
|
||||
} elseif ($arguments->hasNode($index)) {
|
||||
$argument = $arguments->getNode($index);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
return $this->getReadDomainFromNode($argument);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
private function getReadDomainFromNode(Node $node)
|
||||
{
|
||||
if ($node instanceof ConstantExpression) {
|
||||
return $node->getAttribute('value');
|
||||
}
|
||||
|
||||
return self::UNDEFINED_DOMAIN;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user