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

Merge pull request #4569 from marc1706/ticket/14891

[ticket/14891] Use own proxy instantiator for open_basedir compatibility
This commit is contained in:
Máté Bartus 2016-12-09 12:40:57 +01:00
commit 54751991ad
4 changed files with 86 additions and 10 deletions

View File

@ -31,7 +31,7 @@
"guzzlehttp/guzzle": "~5.3",
"lusitanian/oauth": "^0.8.1",
"marc1706/fast-image-size": "^1.1",
"paragonie/random_compat": "^2.0",
"paragonie/random_compat": "^1.4",
"patchwork/utf8": "^1.1",
"s9e/text-formatter": "~0.8.0",
"symfony/config": "^2.8",

14
phpBB/composer.lock generated
View File

@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "9e6c5df052c3e795ad5985862bbb5797",
"content-hash": "47456b70d82a0df10e5faa0a3dc1c2ae",
"hash": "067b099cc97334a6a08a77e5648aa260",
"content-hash": "90198ca524b93a7e915aa6916b2f55af",
"packages": [
{
"name": "bantu/ini-get-wrapper",
@ -460,16 +460,16 @@
},
{
"name": "paragonie/random_compat",
"version": "v2.0.4",
"version": "v1.4.1",
"source": {
"type": "git",
"url": "https://github.com/paragonie/random_compat.git",
"reference": "a9b97968bcde1c4de2a5ec6cbd06a0f6c919b46e"
"reference": "c7e26a21ba357863de030f0b9e701c7d04593774"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/paragonie/random_compat/zipball/a9b97968bcde1c4de2a5ec6cbd06a0f6c919b46e",
"reference": "a9b97968bcde1c4de2a5ec6cbd06a0f6c919b46e",
"url": "https://api.github.com/repos/paragonie/random_compat/zipball/c7e26a21ba357863de030f0b9e701c7d04593774",
"reference": "c7e26a21ba357863de030f0b9e701c7d04593774",
"shasum": ""
},
"require": {
@ -504,7 +504,7 @@
"pseudorandom",
"random"
],
"time": "2016-11-07 23:38:38"
"time": "2016-03-18 20:34:03"
},
{
"name": "patchwork/utf8",

View File

@ -14,7 +14,6 @@
namespace phpbb\di;
use phpbb\filesystem\filesystem;
use Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator;
use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper;
use Symfony\Component\Config\ConfigCache;
use Symfony\Component\Config\FileLocator;
@ -488,7 +487,7 @@ class container_builder
protected function create_container(array $extensions)
{
$container = new ContainerBuilder(new ParameterBag($this->get_core_parameters()));
$container->setProxyInstantiator(new RuntimeInstantiator());
$container->setProxyInstantiator(new proxy_instantiator($this->get_cache_dir()));
$extensions_alias = array();

View File

@ -0,0 +1,77 @@
<?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\di;
use bantu\IniGetWrapper\IniGetWrapper;
use phpbb\filesystem\filesystem;
use ProxyManager\Configuration;
use ProxyManager\Factory\LazyLoadingValueHolderFactory;
use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\LazyProxy\Instantiator\InstantiatorInterface;
/**
* Runtime lazy loading proxy generator extended for allowing use while using
* open_basedir restrictions
*
* Original author: Marco Pivetta <ocramius@gmail.com>
*/
class proxy_instantiator implements InstantiatorInterface
{
/**
* @var LazyLoadingValueHolderFactory
*/
private $factory;
/**
* proxy_instantiator constructor
* @param string $cache_dir Cache dir for fall back when using open_basedir
*/
public function __construct($cache_dir)
{
$config = new Configuration();
// Prevent trying to write to system temp dir in case of open_basedir
// restrictions being in effect
$ini_wrapper = new IniGetWrapper();
$filesystem = new filesystem();
$tmp_dir = (function_exists('sys_get_temp_dir')) ? sys_get_temp_dir() : '';
if (empty($tmp_dir) || $ini_wrapper->getString('open_basedir') &&
(!$filesystem->exists($tmp_dir) || !$filesystem->is_writable($tmp_dir)))
{
$config->setProxiesTargetDir($cache_dir);
}
$config->setGeneratorStrategy(new EvaluatingGeneratorStrategy());
$this->factory = new LazyLoadingValueHolderFactory($config);
}
/**
* {@inheritdoc}
*/
public function instantiateProxy(ContainerInterface $container, Definition $definition, $id, $realInstantiator)
{
return $this->factory->createProxy(
$definition->getClass(),
function (&$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface $proxy) use ($realInstantiator) {
$wrappedInstance = call_user_func($realInstantiator);
$proxy->setProxyInitializer(null);
return true;
}
);
}
}