[ticket/11150] CS

PHPBB3-11150
This commit is contained in:
Tristan Darricau 2015-12-15 19:36:56 +01:00 committed by Tristan Darricau
parent 4617037feb
commit 718ca44a06
No known key found for this signature in database
GPG key ID: 817043C2E29DB881
8 changed files with 124 additions and 45 deletions

View file

@ -2975,4 +2975,5 @@ fieldset.permissions .permissions-switch {
color: #f1f1f1; color: #f1f1f1;
font-family: monospace; font-family: monospace;
overflow-x:scroll; overflow-x:scroll;
line-height: 1.5em;
} }

View file

@ -15,6 +15,7 @@ services:
class: phpbb\composer\installer class: phpbb\composer\installer
arguments: arguments:
- '%core.root_path%' - '%core.root_path%'
- '@filesystem'
- '@config' - '@config'
ext.composer.manager: ext.composer.manager:

View file

@ -20,6 +20,7 @@ use Composer\IO\NullIO;
use Composer\Json\JsonFile; use Composer\Json\JsonFile;
use Composer\Package\BasePackage; use Composer\Package\BasePackage;
use Composer\Package\CompletePackage; use Composer\Package\CompletePackage;
use Composer\Package\Link;
use Composer\Package\PackageInterface; use Composer\Package\PackageInterface;
use Composer\Repository\ComposerRepository; use Composer\Repository\ComposerRepository;
use Composer\Repository\RepositoryInterface; use Composer\Repository\RepositoryInterface;
@ -27,6 +28,7 @@ use Composer\Semver\Constraint\ConstraintInterface;
use Composer\Util\RemoteFilesystem; use Composer\Util\RemoteFilesystem;
use phpbb\config\config; use phpbb\config\config;
use phpbb\exception\runtime_exception; use phpbb\exception\runtime_exception;
use phpbb\filesystem\filesystem;
/** /**
* Class to install packages through composer while freezing core dependencies. * Class to install packages through composer while freezing core dependencies.
@ -76,10 +78,11 @@ class installer
private $ext_json_file_backup; private $ext_json_file_backup;
/** /**
* @param string $root_path phpBB root path * @param string $root_path phpBB root path
* @param config $config Config object * @param filesystem $filesystem Filesystem object
* @param config $config Config object
*/ */
public function __construct($root_path, config $config = null) public function __construct($root_path, filesystem $filesystem, config $config = null)
{ {
if ($config) if ($config)
{ {
@ -90,13 +93,15 @@ class installer
$this->repositories = (array) $repositories; $this->repositories = (array) $repositories;
} }
$this->packagist = (bool) $config['exts_composer_packagist']; $this->packagist = (bool) $config['exts_composer_packagist'];
$this->composer_filename = $config['exts_composer_json_file']; $this->composer_filenam = $config['exts_composer_json_file'];
$this->packages_vendor_dir = $config['exts_composer_vendor_dir']; $this->packages_vendor_dir = $config['exts_composer_vendor_dir'];
$this->minimum_stability = $config['exts_composer_minimum_stability']; $this->minimum_stability = $config['exts_composer_minimum_stability'];
} }
$this->root_path = $root_path; $this->root_path = $root_path;
putenv('COMPOSER_HOME=' . $filesystem->realpath($root_path) . 'store/composer');
} }
/** /**
@ -119,7 +124,7 @@ class installer
$this->do_install($packages, $whitelist, $io); $this->do_install($packages, $whitelist, $io);
$this->restore_cwd(); $this->restore_cwd();
} }
catch (\Exception $e) catch (runtime_exception $e)
{ {
$this->restore_cwd(); $this->restore_cwd();
throw $e; throw $e;
@ -175,6 +180,7 @@ class installer
{ {
$this->restore_ext_json_file(); $this->restore_ext_json_file();
$this->restore_cwd(); $this->restore_cwd();
throw new runtime_exception('COMPOSER_CANNOT_INSTALL', [], $e); throw new runtime_exception('COMPOSER_CANNOT_INSTALL', [], $e);
} }
@ -182,6 +188,7 @@ class installer
{ {
$this->restore_ext_json_file(); $this->restore_ext_json_file();
$this->restore_cwd(); $this->restore_cwd();
throw new runtime_exception($io->get_composer_error(), []); throw new runtime_exception($io->get_composer_error(), []);
} }
} }
@ -192,6 +199,8 @@ class installer
* @param string|array $types Returns only the packages with the given type(s) * @param string|array $types Returns only the packages with the given type(s)
* *
* @return array The installed packages associated to their version. * @return array The installed packages associated to their version.
*
* @throws runtime_exception
*/ */
public function get_installed_packages($types) public function get_installed_packages($types)
{ {
@ -203,7 +212,7 @@ class installer
$result = $this->do_get_installed_packages($types); $result = $this->do_get_installed_packages($types);
$this->restore_cwd(); $this->restore_cwd();
} }
catch (\Exception $e) catch (runtime_exception $e)
{ {
$this->restore_cwd(); $this->restore_cwd();
throw $e; throw $e;
@ -231,6 +240,8 @@ class installer
$composer = Factory::create($io, $this->get_composer_ext_json_filename(), false); $composer = Factory::create($io, $this->get_composer_ext_json_filename(), false);
$installed = []; $installed = [];
/** @var Link[] $required_links */
$required_links = $composer->getPackage()->getRequires(); $required_links = $composer->getPackage()->getRequires();
$installed_packages = $composer->getRepositoryManager()->getLocalRepository()->getCanonicalPackages(); $installed_packages = $composer->getRepositoryManager()->getLocalRepository()->getCanonicalPackages();
@ -260,6 +271,8 @@ class installer
* @param string $type Returns only the packages with the given type * @param string $type Returns only the packages with the given type
* *
* @return array The name of the available packages, associated to their definition. Ordered by name. * @return array The name of the available packages, associated to their definition. Ordered by name.
*
* @throws runtime_exception
*/ */
public function get_available_packages($type) public function get_available_packages($type)
{ {
@ -271,7 +284,7 @@ class installer
$result = $this->do_get_available_packages($type); $result = $this->do_get_available_packages($type);
$this->restore_cwd(); $this->restore_cwd();
} }
catch (\Exception $e) catch (runtime_exception $e)
{ {
$this->restore_cwd(); $this->restore_cwd();
throw $e; throw $e;
@ -488,7 +501,6 @@ class installer
'replace' => $core_packages, 'replace' => $core_packages,
'repositories' => $this->get_composer_repositories(), 'repositories' => $this->get_composer_repositories(),
'config' => [ 'config' => [
'cache-dir' => 'store/composer',
'vendor-dir'=> $this->packages_vendor_dir, 'vendor-dir'=> $this->packages_vendor_dir,
], ],
'minimum-stability' => $this->minimum_stability, 'minimum-stability' => $this->minimum_stability,

View file

@ -19,7 +19,7 @@ use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
class console_io extends ConsoleIO class console_io extends ConsoleIO implements io_interface
{ {
use translate_composer_trait; use translate_composer_trait;

View file

@ -4,7 +4,7 @@
* This file is part of the phpBB Forum Software package. * This file is part of the phpBB Forum Software package.
* *
* @copyright (c) phpBB Limited <https://www.phpbb.com> * @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0) * @license GNU General Public License, version 2 (GPL-2.0)
* *
* For full copyright and license information, please see * For full copyright and license information, please see
* the docs/CREDITS.txt file. * the docs/CREDITS.txt file.
@ -16,34 +16,35 @@ namespace phpbb\composer\io;
class html_output_formatter extends \Composer\Console\HtmlOutputFormatter class html_output_formatter extends \Composer\Console\HtmlOutputFormatter
{ {
protected static $availableForegroundColors = [ protected static $availableForegroundColors = [
30 => 'black', 30 => 'black',
31 => 'red', 31 => 'red',
32 => 'green', 32 => 'green',
33 => 'orange', 33 => 'orange',
34 => 'blue', 34 => 'blue',
35 => 'magenta', 35 => 'magenta',
36 => 'cyan', 36 => 'cyan',
37 => 'white' 37 => 'white',
]; ];
protected static $availableBackgroundColors = [ protected static $availableBackgroundColors = [
40 => 'black', 40 => 'black',
41 => 'red', 41 => 'red',
42 => 'green', 42 => 'green',
43 => 'yellow', 43 => 'yellow',
44 => 'blue', 44 => 'blue',
45 => 'magenta', 45 => 'magenta',
46 => 'cyan', 46 => 'cyan',
47 => 'white' 47 => 'white',
]; ];
protected static $availableOptions = [ protected static $availableOptions
1 => 'bold', = [
4 => 'underscore', 1 => 'bold',
//5 => 'blink', 4 => 'underscore',
//7 => 'reverse', //5 => 'blink',
//8 => 'conceal' //7 => 'reverse',
]; //8 => 'conceal'
];
/** /**
* {@inheritdoc} * {@inheritdoc}
@ -52,7 +53,7 @@ class html_output_formatter extends \Composer\Console\HtmlOutputFormatter
{ {
$formatted = parent::format($message); $formatted = parent::format($message);
return preg_replace_callback("{[\033\e]\[([0-9;]+)m(.*?)[\033\e]\[[0-9;]+m}s", array($this, 'formatHtml'), $formatted); return preg_replace_callback("{[\033\e]\[([0-9;]+)m(.*?)[\033\e]\[[0-9;]+m}s", [$this, 'formatHtml'], $formatted);
} }
protected function formatHtml($matches) protected function formatHtml($matches)
@ -62,13 +63,13 @@ class html_output_formatter extends \Composer\Console\HtmlOutputFormatter
{ {
if (isset(self::$availableForegroundColors[$code])) if (isset(self::$availableForegroundColors[$code]))
{ {
$out .= 'color:'.self::$availableForegroundColors[$code].';'; $out .= 'color:' . self::$availableForegroundColors[$code] . ';';
} }
elseif (isset(self::$availableBackgroundColors[$code])) else if (isset(self::$availableBackgroundColors[$code]))
{ {
$out .= 'background-color:'.self::$availableBackgroundColors[$code].';'; $out .= 'background-color:' . self::$availableBackgroundColors[$code] . ';';
} }
elseif (isset(self::$availableOptions[$code])) else if (isset(self::$availableOptions[$code]))
{ {
switch (self::$availableOptions[$code]) switch (self::$availableOptions[$code])
{ {
@ -83,6 +84,6 @@ class html_output_formatter extends \Composer\Console\HtmlOutputFormatter
} }
} }
return $out.'">'.$matches[2].'</span>'; return $out . '">' . $matches[2] . '</span>';
} }
} }

View file

@ -0,0 +1,32 @@
<?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\ConsoleIO;
use Composer\IO\IOInterface;
use Composer\IO\NullIO;
use phpbb\language\language;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
interface io_interface extends IOInterface
{
/**
* Returns the composer errors that occurred since the last tcall of the method.
*
* @return string
*/
public function get_composer_error();
}

View file

@ -0,0 +1,32 @@
<?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\ConsoleIO;
use Composer\IO\NullIO;
use phpbb\language\language;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class console_io extends NullIO implements io_interface
{
/**
* {@inheritdoc}
*/
public function get_composer_error()
{
return '';
}
}

View file

@ -18,7 +18,7 @@ use phpbb\language\language;
use Symfony\Component\Console\Formatter\OutputFormatterInterface; use Symfony\Component\Console\Formatter\OutputFormatterInterface;
use Symfony\Component\Console\Output\StreamOutput; use Symfony\Component\Console\Output\StreamOutput;
class web_io extends BufferIO class web_io extends BufferIO implements io_interface
{ {
use translate_composer_trait; use translate_composer_trait;