Merge #16192 - Support Twig 3

Pull-request: #16192
Signed-off-by: William Desportes <williamdes@wdes.fr>
This commit is contained in:
William Desportes 2020-06-15 13:03:38 +02:00
commit 289fbc129a
No known key found for this signature in database
GPG Key ID: 90A0EF1B8251A889
18 changed files with 71 additions and 109 deletions

View File

@ -49,7 +49,7 @@
"phpmyadmin/motranslator": "^4.0",
"phpmyadmin/shapefile": "^2.0",
"phpmyadmin/sql-parser": "^5.0",
"phpmyadmin/twig-i18n-extension": "^2.0",
"phpmyadmin/twig-i18n-extension": "^2.0 || ^3.0",
"phpseclib/phpseclib": "^2.0",
"symfony/config": "^4.2.8",
"symfony/dependency-injection": "^4.2.8",
@ -57,7 +57,7 @@
"symfony/polyfill-ctype": "^1.8",
"symfony/polyfill-mbstring": "^1.3",
"symfony/yaml": "^4.2.8",
"twig/twig": "^2.9",
"twig/twig": "^2.9 || ^3",
"williamdes/mariadb-mysql-kbs": "^1.2"
},
"conflict": {

View File

@ -11,9 +11,6 @@ namespace PhpMyAdmin\Controllers\Server;
use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\ReplicationGui;
use Throwable;
use Twig_Error_Loader;
use Twig_Error_Runtime;
use Twig_Error_Syntax;
/**
* Server replications
@ -27,9 +24,9 @@ class ReplicationController extends AbstractController
*
* @return string HTML
* @throws Throwable
* @throws Twig_Error_Loader
* @throws Twig_Error_Runtime
* @throws Twig_Error_Syntax
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
public function index(array $params, ReplicationGui $replicationGui): string
{

View File

@ -12,9 +12,6 @@ namespace PhpMyAdmin\Controllers\Server\Status;
use PhpMyAdmin\ReplicationGui;
use PhpMyAdmin\Util;
use Throwable;
use Twig_Error_Loader;
use Twig_Error_Runtime;
use Twig_Error_Syntax;
/**
* Class StatusController
@ -27,9 +24,9 @@ class StatusController extends AbstractController
*
* @return string
* @throws Throwable
* @throws Twig_Error_Loader
* @throws Twig_Error_Runtime
* @throws Twig_Error_Syntax
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
public function index(ReplicationGui $replicationGui): string
{

View File

@ -12,9 +12,6 @@ namespace PhpMyAdmin\Display;
use PhpMyAdmin\Sanitize;
use PhpMyAdmin\Template;
use Throwable;
use Twig_Error_Loader;
use Twig_Error_Runtime;
use Twig_Error_Syntax;
/**
* Displays Error
@ -32,9 +29,9 @@ class Error
*
* @return string
* @throws Throwable
* @throws Twig_Error_Loader
* @throws Twig_Error_Runtime
* @throws Twig_Error_Syntax
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
public static function display(
Template $template,

View File

@ -21,9 +21,6 @@ use PhpMyAdmin\Table;
use PhpMyAdmin\Template;
use PhpMyAdmin\Util;
use Throwable;
use Twig_Error_Loader;
use Twig_Error_Runtime;
use Twig_Error_Syntax;
/**
* PhpMyAdmin\Display\Export class
@ -576,9 +573,9 @@ class Export
*
* @return string
* @throws Throwable
* @throws Twig_Error_Loader
* @throws Twig_Error_Runtime
* @throws Twig_Error_Syntax
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
private function getHtmlForCurrentAlias()
{

View File

@ -17,9 +17,6 @@ use Samyoul\U2F\U2FServer\U2FException;
use Samyoul\U2F\U2FServer\U2FServer;
use stdClass;
use Throwable;
use Twig_Error_Loader;
use Twig_Error_Runtime;
use Twig_Error_Syntax;
/**
* Hardware key based two-factor authentication
@ -137,9 +134,9 @@ class Key extends TwoFactorPlugin
* @return string HTML code
* @throws U2FException
* @throws Throwable
* @throws Twig_Error_Loader
* @throws Twig_Error_Runtime
* @throws Twig_Error_Syntax
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
public function setup()
{

View File

@ -25,14 +25,8 @@ use PhpMyAdmin\Twig\UtilExtension;
use RuntimeException;
use Throwable;
use Twig\Environment;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;
use Twig\Loader\FilesystemLoader;
use Twig_Error_Loader;
use Twig_Error_Runtime;
use Twig_Error_Syntax;
use Twig_TemplateWrapper;
use Twig\TemplateWrapper;
/**
* Class Template
@ -95,12 +89,12 @@ class Template
*
* @param string $templateName Template path name
*
* @return Twig_TemplateWrapper
* @throws LoaderError
* @throws RuntimeError
* @throws SyntaxError
* @return TemplateWrapper
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
public function load(string $templateName): Twig_TemplateWrapper
public function load(string $templateName): TemplateWrapper
{
try {
$template = static::$twig->load($templateName . '.twig');
@ -131,9 +125,9 @@ class Template
*
* @return string
* @throws Throwable
* @throws Twig_Error_Loader
* @throws Twig_Error_Runtime
* @throws Twig_Error_Syntax
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
public function render(string $template, array $data = []): string
{

View File

@ -11,7 +11,6 @@ namespace PhpMyAdmin\Twig\I18n;
use PhpMyAdmin\Twig\Extensions\TokenParser\TransTokenParser;
use Twig\Token;
use Twig_Error_Syntax;
/**
* Class TokenParserTrans
@ -27,7 +26,7 @@ class TokenParserTrans extends TransTokenParser
*
* @return NodeTrans
*
* @throws Twig_Error_Syntax
* @throws \Twig\Error\SyntaxError
*/
public function parse(Token $token)
{

View File

@ -11,9 +11,6 @@ namespace PhpMyAdmin;
use PhpMyAdmin\Config\Forms\User\UserFormList;
use Throwable;
use Twig_Error_Loader;
use Twig_Error_Runtime;
use Twig_Error_Syntax;
/**
* Functions for displaying user preferences header
@ -30,9 +27,9 @@ class UserPreferencesHeader
*
* @return string
* @throws Throwable
* @throws Twig_Error_Loader
* @throws Twig_Error_Runtime
* @throws Twig_Error_Syntax
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
public static function getContent(Template $template, Relation $relation): string
{
@ -46,9 +43,9 @@ class UserPreferencesHeader
*
* @return string
* @throws Throwable
* @throws Twig_Error_Loader
* @throws Twig_Error_Runtime
* @throws Twig_Error_Syntax
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
protected static function displayTabs(Template $template): string
{

View File

@ -72,7 +72,11 @@ foreach (new \RecursiveIteratorIterator(
// force compilation
if ($file->isFile() && $file->getExtension() === 'twig') {
$name = str_replace($tplDir . '/', '', $file->getPathname());
$template = $twig->loadTemplate($name);
if (Environment::MAJOR_VERSION === 3) {
$template = $twig->loadTemplate($twig->getTemplateClass($name), $name);
} else {
$template = $twig->loadTemplate($name);
}
// Generate line map
$cacheFilename = $twigCache->generateKey($name, $twig->getTemplateClass($name));

View File

@ -15,13 +15,11 @@
</select>
{% if char_editing == 'textarea' %}
{% apply spaceless %}
<textarea name="field_expression[{{ column_number }}]"
cols="15"
class="textfield expression">
{{ expression }}
{{- expression -}}
</textarea>
{% endapply %}
{% else %}
<input type="text"
name="field_expression[{{ column_number }}]"

View File

@ -143,11 +143,9 @@
) }}
</td>
<td>
{% apply spaceless %}
<textarea name="{{ subpartition['prefix'] }}[comment]">
{{ subpartition['comment'] }}
{{- subpartition['comment'] -}}
</textarea>
{% endapply %}
</td>
<td>
<input type="text" name="{{ subpartition['prefix'] }}[data_directory]"

View File

@ -1,9 +1,7 @@
{# Invisible characters will make javascript crash #}
{% apply spaceless %}
<script type="text/javascript">
var designerConfig = {{ designer_config|raw }};
</script>
{% endapply %}
{# side menu #}
{% if not has_query %}

View File

@ -163,15 +163,13 @@
</fieldset>
<fieldset>
{% apply spaceless %}
<textarea id="MultiSqlquery"
cols="80"
rows="4"
style="float:left"
name="sql_query"
dir="ltr">
</textarea>
{% endapply %}
{# Keep the block without a space between the open and close tag #}
<textarea id="MultiSqlquery"
cols="80"
rows="4"
style="float: left;"
name="sql_query"
dir="ltr"></textarea>
</fieldset>
</fieldset>

View File

@ -9,15 +9,14 @@
<li>
<label for="limit_to">{% trans 'Number of rows:' %}</label>
<input type="text" id="limit_to" name="limit_to" size="5" value="
{%- apply spaceless %}
{% if limit_to is not null %}
{{ limit_to }}
{% elseif unlim_num_rows is not empty and unlim_num_rows != 0 %}
{{ unlim_num_rows }}
{% else %}
{{ number_of_rows }}
{% endif %}
{% endapply %}" onfocus="this.select()">
{# Keep everything space less because it is a value #}
{%- if limit_to is not null -%}
{{- limit_to -}}
{%- elseif unlim_num_rows is not empty and unlim_num_rows != 0 -%}
{{- unlim_num_rows -}}
{%- else %}
{{- number_of_rows -}}
{%- endif -%}" onfocus="this.select()">
</li>
<li>
<label for="limit_from">{% trans 'Row to begin at:' %}</label>

View File

@ -18,7 +18,6 @@ $( function() {
{% set import_url = get_common_raw({'import_status': 1}, '&') %}
{% set upload_html %}
{% apply spaceless %}
<div class="upload_progress">
<div class="upload_progress_bar_outer">
<div class="percentage"></div>
@ -31,7 +30,6 @@ $( function() {
</div>
<div id="statustext"></div>
</div>
{% endapply %}
{% endset %}
{# Start output #}
@ -79,7 +77,7 @@ $( function() {
{# Show progress UI #}
$("#importmain").hide();
$("#import_form_status")
.html('{{ upload_html|raw }}')
.html('{{ upload_html|spaceless|raw }}')
.show();
import_start = now;
}

View File

@ -13,9 +13,6 @@ use PhpMyAdmin\Display\Error;
use PhpMyAdmin\Template;
use PHPUnit\Framework\TestCase;
use Throwable;
use Twig_Error_Loader;
use Twig_Error_Runtime;
use Twig_Error_Syntax;
require_once ROOT_PATH . 'libraries/config.default.php';
@ -33,9 +30,9 @@ class ErrorTest extends TestCase
*
* @return void
* @throws Throwable
* @throws Twig_Error_Loader
* @throws Twig_Error_Runtime
* @throws Twig_Error_Syntax
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
public function testDisplaySimple(): void
{
@ -61,9 +58,9 @@ class ErrorTest extends TestCase
*
* @return void
* @throws Throwable
* @throws Twig_Error_Loader
* @throws Twig_Error_Runtime
* @throws Twig_Error_Syntax
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
public function testDisplayToSanitize(): void
{

View File

@ -17,9 +17,6 @@ use PhpMyAdmin\Tests\PmaTestCase;
use PhpMyAdmin\UserPreferences;
use PhpMyAdmin\UserPreferencesHeader;
use Throwable;
use Twig_Error_Loader;
use Twig_Error_Runtime;
use Twig_Error_Syntax;
/**
* tests for methods under PhpMyAdmin\UserPreferencesHeader class
@ -48,9 +45,9 @@ class UserPreferencesHeaderTest extends PmaTestCase
*
* @return void
* @throws Throwable
* @throws Twig_Error_Loader
* @throws Twig_Error_Runtime
* @throws Twig_Error_Syntax
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
public function testGetContentWithSelectedTab(): void
{
@ -83,9 +80,9 @@ class UserPreferencesHeaderTest extends PmaTestCase
*
* @return void
* @throws Throwable
* @throws Twig_Error_Loader
* @throws Twig_Error_Runtime
* @throws Twig_Error_Syntax
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
public function testGetContentAfterSave(): void
{
@ -108,9 +105,9 @@ class UserPreferencesHeaderTest extends PmaTestCase
*
* @return void
* @throws Throwable
* @throws Twig_Error_Loader
* @throws Twig_Error_Runtime
* @throws Twig_Error_Syntax
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
public function testGetContentWithSessionStorage(): void
{