diff --git a/.travis.yml b/.travis.yml index 5df1392bcb..864c087d63 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,6 +50,7 @@ jobs: - composer phpcs - yarn run js-lint --quiet - yarn run css-lint + - php scripts/console lint:twig templates --show-deprecations - stage: "Lint and analyse code" name: "Run phpstan" diff --git a/composer.json b/composer.json index 248447333f..40fbd17610 100644 --- a/composer.json +++ b/composer.json @@ -89,7 +89,9 @@ "phpunit/phpunit": "^7.5 || ^8.0 || ^9.0", "pragmarx/google2fa-qrcode": "^1.0.1", "samyoul/u2f-php-server": "^1.1", - "symfony/console": "^4.3", + "symfony/console": "^4.4", + "symfony/finder": "^4.4", + "symfony/twig-bridge": "^4.4", "tecnickcom/tcpdf": "^6.3", "vimeo/psalm": "^3.11" }, diff --git a/scripts/console b/scripts/console index cfdd9b80e4..8e98f3e7b8 100755 --- a/scripts/console +++ b/scripts/console @@ -3,7 +3,24 @@ use PhpMyAdmin\Command\AdvisoryRulesCommand; use PhpMyAdmin\Command\CacheWarmupCommand; +use PhpMyAdmin\Config; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Tests\Stubs\DbiDummy; +use PhpMyAdmin\Twig\CoreExtension; +use PhpMyAdmin\Twig\I18nExtension; +use PhpMyAdmin\Twig\MessageExtension; +use PhpMyAdmin\Twig\PluginsExtension; +use PhpMyAdmin\Twig\RelationExtension; +use PhpMyAdmin\Twig\SanitizeExtension; +use PhpMyAdmin\Twig\TableExtension; +use PhpMyAdmin\Twig\TrackerExtension; +use PhpMyAdmin\Twig\TransformationsExtension; +use PhpMyAdmin\Twig\UrlExtension; +use PhpMyAdmin\Twig\UtilExtension; +use Symfony\Bridge\Twig\Command\LintCommand; use Symfony\Component\Console\Application; +use Twig\Environment; +use Twig\Loader\FilesystemLoader; if (! defined('ROOT_PATH')) { define('ROOT_PATH', dirname(__DIR__) . DIRECTORY_SEPARATOR); @@ -19,9 +36,36 @@ if (! class_exists(Application::class)) { exit(1); } +$cfg['environment'] = 'production'; +$PMA_Config = new Config(CONFIG_FILE); +$PMA_Config->set('environment', $cfg['environment']); +$dbi = new DatabaseInterface(new DbiDummy()); +$tplDir = ROOT_PATH . 'templates'; +$tmpDir = ROOT_PATH . 'twig-templates'; + +$loader = new FilesystemLoader($tplDir); +$twig = new Environment($loader, [ + 'auto_reload' => true, + 'cache' => $tmpDir, +]); +$twig->setExtensions([ + new CoreExtension(), + new I18nExtension(), + new MessageExtension(), + new PluginsExtension(), + new RelationExtension(), + new SanitizeExtension(), + new TableExtension(), + new TrackerExtension(), + new TransformationsExtension(), + new UrlExtension(), + new UtilExtension(), +]); + $application = new Application('phpMyAdmin Console Tool'); $application->add(new AdvisoryRulesCommand()); $application->add(new CacheWarmupCommand()); +$application->add(new LintCommand($twig)); $application->run();