diff options
author | Máté Bartus <mate.bartus@gmail.com> | 2016-12-09 12:40:57 +0100 |
---|---|---|
committer | Máté Bartus <mate.bartus@gmail.com> | 2016-12-09 12:40:57 +0100 |
commit | 54751991ad1af8c60416fac5a58abfd5d9f30f93 (patch) | |
tree | 4274d0d8437fa6b534c93ebc2a8c3bcd37f5d657 /phpBB/phpbb | |
parent | 467e6035700bd1bb5e6f3aef803b9de617dcd4ee (diff) | |
parent | 90b59bb547844f6913cb459c21d249aec4226d56 (diff) | |
download | forums-54751991ad1af8c60416fac5a58abfd5d9f30f93.tar forums-54751991ad1af8c60416fac5a58abfd5d9f30f93.tar.gz forums-54751991ad1af8c60416fac5a58abfd5d9f30f93.tar.bz2 forums-54751991ad1af8c60416fac5a58abfd5d9f30f93.tar.xz forums-54751991ad1af8c60416fac5a58abfd5d9f30f93.zip |
Merge pull request #4569 from marc1706/ticket/14891
[ticket/14891] Use own proxy instantiator for open_basedir compatibility
Diffstat (limited to 'phpBB/phpbb')
-rw-r--r-- | phpBB/phpbb/di/container_builder.php | 3 | ||||
-rw-r--r-- | phpBB/phpbb/di/proxy_instantiator.php | 77 |
2 files changed, 78 insertions, 2 deletions
diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index b6854673c2..4d5f189f12 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -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(); diff --git a/phpBB/phpbb/di/proxy_instantiator.php b/phpBB/phpbb/di/proxy_instantiator.php new file mode 100644 index 0000000000..a388e82c0e --- /dev/null +++ b/phpBB/phpbb/di/proxy_instantiator.php @@ -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; + } + ); + } +} |