1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-03-24 09:30:34 +01:00

[ticket/11150] Use a trait to translate composer and introduce web_io

PHPBB3-11150
This commit is contained in:
Tristan Darricau 2015-09-12 16:55:03 +02:00 committed by Tristan Darricau
parent 8a1ca4375e
commit 8b1284594b
No known key found for this signature in database
GPG Key ID: 817043C2E29DB881
4 changed files with 240 additions and 180 deletions

View File

@ -287,7 +287,6 @@ class installer
$packages),
'replace' => $core_packages,
'repositories' => $this->get_composer_repositories(),
'minimum-stability' => 'dev',
];
$json_file = new JsonFile($this->get_composer_ext_json_filename());

View File

@ -21,15 +21,7 @@ use Symfony\Component\Console\Output\OutputInterface;
class console_io extends ConsoleIO
{
/**
* @var language
*/
protected $language;
/**
* @var array
*/
protected $composer_error;
use translate_composer_trait;
/**
* Constructor.
@ -44,174 +36,4 @@ class console_io extends ConsoleIO
parent::__construct($input, $output, $helperSet);
}
/**
* {@inheritdoc}
*/
public function write($messages, $newline = true)
{
$messages = (array) $messages;
$translated_messages = [];
foreach ($messages as $message)
{
$lang_key = $message;
$parameters = [];
$level = 0;
$message = trim(strip_tags($message), "\n\r");
if (strpos($message, 'Deleting ') === 0)
{
$elements = explode(' ', $message);
$lang_key = 'COMPOSER_DELETING';
$parameters = [$elements[1]];
}
//$translated_message = $this->language->lang_array($lang_key, $parameters);
$translated_message = call_user_func_array([$this->language, 'lang'], array_merge((array)$lang_key, $parameters));
switch ($level)
{
case 1:
$translated_message = '<info>' . $translated_message . '</info>';
break;
case 2:
$translated_message = '<comment>' . $translated_message . '</comment>';
break;
case 3:
$translated_message = '<warning>' . $translated_message . '</warning>';
break;
case 4:
$translated_message = '<error>' . $translated_message . '</error>';
break;
}
$translated_messages[] = $translated_message;
}
parent::write($translated_messages, $newline);
}
/**
* {@inheritdoc}
*/
public function writeError($messages, $newline = true)
{
$messages = (array) $messages;
$translated_messages = [];
foreach ($messages as $message)
{
$lang_key = $message;
$parameters = [];
$level = 0;
$message = trim(strip_tags($message), "\n\r");
if (strpos($message, ' Problem ') === 0)
{
if ($this->output->getVerbosity() < OutputInterface::VERBOSITY_VERBOSE)
{
continue;
}
$lang_key = "\n" . $message . "\n";
$level = 4;
}
else if ($message === 'Updating dependencies')
{
$lang_key = 'COMPOSER_UPDATING_DEPENDENCIES';
$level = 1;
}
else if ($message === 'Loading composer repositories with package information')
{
$lang_key = 'COMPOSER_LOADING_REPOSITORIES';
$level = 1;
}
else if ($message === 'Your requirements could not be resolved to an installable set of packages.')
{
$this->composer_error[] = ['COMPOSER_ERROR_CONFLICT', []];
continue;
}
else if (strpos($message, 'could not be fully loaded, package information was loaded from the local cache and may be out of date') !== false)
{
$end_repo = strpos($message, 'could not be fully loaded, package information was loaded from the local cache and may be out of date');
$repo = substr($message, 0, $end_repo - 1);
$lang_key = 'COMPOSER_REPOSITORY_UNAVAILABLE';
$parameters = [$repo];
$level = 3;
}
else if (strpos($message, 'file could not be downloaded') !== false)
{
continue;
}
else if (strpos($message, ' - Installing ') === 0)
{
$elements = explode(' ', $message);
$lang_key = 'COMPOSER_INSTALLING_PACKAGE';
$parameters = [$elements[4], trim($elements[5], '()')];
}
else if ($message === 'Nothing to install or update')
{
$lang_key = 'COMPOSER_UPDATE_NOTHING';
$level = 3;
}
else if ($message === ' Downloading')
{
continue;
}
else if ($message === ' Loading from cache')
{
continue;
}
else if ($message === 'Writing lock file')
{
continue;
}
else if (empty($message))
{
continue;
}
//$translated_message = $this->language->lang_array($lang_key, $parameters);
$translated_message = call_user_func_array([$this->language, 'lang'], array_merge((array)$lang_key, $parameters));
switch ($level)
{
case 1:
$translated_message = '<info>' . $translated_message . '</info>';
break;
case 2:
$translated_message = '<comment>' . $translated_message . '</comment>';
break;
case 3:
$translated_message = '<warning>' . $translated_message . '</warning>';
break;
case 4:
$translated_message = '<error>' . $translated_message . '</error>';
break;
}
$translated_messages[] = $translated_message;
}
parent::writeError($translated_messages, $newline);
}
public function get_composer_error()
{
$error = '';
foreach ($this->composer_error as $error_line)
{
// $error .= $this->language->lang_array($error_line[0], $error_line[1]);
$error .= call_user_func_array([$this->language, 'lang'], array_merge((array)$error_line[0], $error_line[1]));
$error .= "\n";
}
$this->composer_error = [];
return $error;
}
}

View File

@ -0,0 +1,200 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\composer\io;
use phpbb\language\language;
use Symfony\Component\Console\Output\OutputInterface;
trait translate_composer_trait
{
/**
* @var language
*/
protected $language;
/**
* @var array
*/
protected $composer_error;
/**
* {@inheritdoc}
*/
public function write($messages, $newline = true)
{
$messages = (array) $messages;
$translated_messages = [];
foreach ($messages as $message)
{
$lang_key = $message;
$parameters = [];
$level = 0;
$message = trim(strip_tags($message), "\n\r");
if (strpos($message, 'Deleting ') === 0)
{
$elements = explode(' ', $message);
$lang_key = 'COMPOSER_DELETING';
$parameters = [$elements[1]];
}
//$translated_message = $this->language->lang_array($lang_key, $parameters);
$translated_message = call_user_func_array([$this->language, 'lang'], array_merge((array)$lang_key, $parameters));
switch ($level)
{
case 1:
$translated_message = '<info>' . $translated_message . '</info>';
break;
case 2:
$translated_message = '<comment>' . $translated_message . '</comment>';
break;
case 3:
$translated_message = '<warning>' . $translated_message . '</warning>';
break;
case 4:
$translated_message = '<error>' . $translated_message . '</error>';
break;
}
$translated_messages[] = $translated_message;
}
parent::write($translated_messages, $newline);
}
/**
* {@inheritdoc}
*/
public function writeError($messages, $newline = true)
{
$messages = (array) $messages;
$translated_messages = [];
foreach ($messages as $message)
{
$lang_key = $message;
$parameters = [];
$level = 0;
$message = trim(strip_tags($message), "\n\r");
if (strpos($message, ' Problem ') === 0)
{
if ($this->output->getVerbosity() < OutputInterface::VERBOSITY_VERBOSE)
{
continue;
}
$lang_key = "\n" . $message . "\n";
$level = 4;
}
else if ($message === 'Updating dependencies')
{
$lang_key = 'COMPOSER_UPDATING_DEPENDENCIES';
$level = 1;
}
else if ($message === 'Loading composer repositories with package information')
{
$lang_key = 'COMPOSER_LOADING_REPOSITORIES';
$level = 1;
}
else if ($message === 'Your requirements could not be resolved to an installable set of packages.')
{
$this->composer_error[] = ['COMPOSER_ERROR_CONFLICT', []];
continue;
}
else if (strpos($message, 'could not be fully loaded, package information was loaded from the local cache and may be out of date') !== false)
{
$end_repo = strpos($message, 'could not be fully loaded, package information was loaded from the local cache and may be out of date');
$repo = substr($message, 0, $end_repo - 1);
$lang_key = 'COMPOSER_REPOSITORY_UNAVAILABLE';
$parameters = [$repo];
$level = 3;
}
else if (strpos($message, 'file could not be downloaded') !== false)
{
continue;
}
else if (strpos($message, ' - Installing ') === 0)
{
$elements = explode(' ', $message);
$lang_key = 'COMPOSER_INSTALLING_PACKAGE';
$parameters = [$elements[4], trim($elements[5], '()')];
}
else if ($message === 'Nothing to install or update')
{
$lang_key = 'COMPOSER_UPDATE_NOTHING';
$level = 3;
}
else if ($message === ' Downloading')
{
continue;
}
else if ($message === ' Loading from cache')
{
continue;
}
else if ($message === 'Writing lock file')
{
continue;
}
else if (empty($message))
{
continue;
}
//$translated_message = $this->language->lang_array($lang_key, $parameters);
$translated_message = call_user_func_array([$this->language, 'lang'], array_merge((array)$lang_key, $parameters));
switch ($level)
{
case 1:
$translated_message = '<info>' . $translated_message . '</info>';
break;
case 2:
$translated_message = '<comment>' . $translated_message . '</comment>';
break;
case 3:
$translated_message = '<warning>' . $translated_message . '</warning>';
break;
case 4:
$translated_message = '<error>' . $translated_message . '</error>';
break;
}
$translated_messages[] = $translated_message;
}
parent::writeError($translated_messages, $newline);
}
public function get_composer_error()
{
$error = '';
foreach ($this->composer_error as $error_line)
{
// $error .= $this->language->lang_array($error_line[0], $error_line[1]);
$error .= call_user_func_array([$this->language, 'lang'], array_merge((array)$error_line[0], $error_line[1]));
$error .= "\n";
}
$this->composer_error = [];
return $error;
}
}

View File

@ -0,0 +1,39 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\composer\io;
use Composer\IO\BufferIO;
use phpbb\language\language;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class web_io extends BufferIO
{
use translate_composer_trait;
/**
* Constructor.
*
* @param InputInterface $input The input instance
* @param OutputInterface $output The output instance
* @param HelperSet $helperSet The helperSet instance
*/
public function __construct(InputInterface $input, OutputInterface $output, HelperSet $helperSet, language $language)
{
$this->language = $language;
parent::__construct($input, $output, $helperSet);
}
}