[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/phpbb/di/ -> proxy_instantiator.php (source)

   1  <?php
   2  /**
   3   *
   4   * This file is part of the phpBB Forum Software package.
   5   *
   6   * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7   * @license GNU General Public License, version 2 (GPL-2.0)
   8   *
   9   * For full copyright and license information, please see
  10   * the docs/CREDITS.txt file.
  11   *
  12   */
  13  
  14  namespace phpbb\di;
  15  
  16  use ProxyManager\Configuration;
  17  use ProxyManager\Factory\LazyLoadingValueHolderFactory;
  18  use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy;
  19  use Symfony\Component\DependencyInjection\ContainerInterface;
  20  use Symfony\Component\DependencyInjection\Definition;
  21  use Symfony\Component\DependencyInjection\LazyProxy\Instantiator\InstantiatorInterface;
  22  
  23  /**
  24   * Runtime lazy loading proxy generator extended for allowing use while using
  25   * open_basedir restrictions
  26   *
  27   * Original author: Marco Pivetta <ocramius@gmail.com>
  28   */
  29  class proxy_instantiator implements InstantiatorInterface
  30  {
  31      /**
  32       * @var LazyLoadingValueHolderFactory
  33       */
  34      private $factory;
  35  
  36      /**
  37       * proxy_instantiator constructor
  38       * @param string $cache_dir Cache dir for fall back when using open_basedir
  39       */
  40  	public function __construct($cache_dir)
  41      {
  42          $config = new Configuration();
  43  
  44          // Prevent trying to write to system temp dir in case of open_basedir
  45          // restrictions being in effect
  46          $tmp_dir = (function_exists('sys_get_temp_dir')) ? sys_get_temp_dir() : '';
  47          if (empty($tmp_dir) || !@file_exists($tmp_dir) || !@is_writable($tmp_dir))
  48          {
  49              $config->setProxiesTargetDir($cache_dir);
  50          }
  51          $config->setGeneratorStrategy(new EvaluatingGeneratorStrategy());
  52  
  53          $this->factory = new LazyLoadingValueHolderFactory($config);
  54      }
  55  
  56      /**
  57       * {@inheritdoc}
  58       */
  59  	public function instantiateProxy(ContainerInterface $container, Definition $definition, $id, $realInstantiator)
  60      {
  61          return $this->factory->createProxy(
  62              $definition->getClass(),
  63              function (&$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface $proxy) use ($realInstantiator) {
  64                  $wrappedInstance = call_user_func($realInstantiator);
  65  
  66                  $proxy->setProxyInitializer(null);
  67  
  68                  return true;
  69              }
  70          );
  71      }
  72  }


Generated: Mon Nov 25 19:05:08 2024 Cross-referenced by PHPXref 0.7.1