[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/vendor/ocramius/proxy-manager/src/ProxyManager/GeneratorStrategy/ -> EvaluatingGeneratorStrategy.php (source)

   1  <?php
   2  
   3  declare(strict_types=1);
   4  
   5  namespace ProxyManager\GeneratorStrategy;
   6  
   7  use Zend\Code\Generator\ClassGenerator;
   8  
   9  /**
  10   * Generator strategy that produces the code and evaluates it at runtime
  11   *
  12   * @author Marco Pivetta <ocramius@gmail.com>
  13   * @license MIT
  14   */
  15  class EvaluatingGeneratorStrategy implements GeneratorStrategyInterface
  16  {
  17      /**
  18       * @var bool flag indicating whether {@see eval} can be used
  19       */
  20      private $canEval = true;
  21  
  22      /**
  23       * Constructor
  24       */
  25      public function __construct()
  26      {
  27          // @codeCoverageIgnoreStart
  28          $this->canEval = ! ini_get('suhosin.executor.disable_eval');
  29          // @codeCoverageIgnoreEnd
  30      }
  31  
  32      /**
  33       * Evaluates the generated code before returning it
  34       *
  35       * {@inheritDoc}
  36       */
  37      public function generate(ClassGenerator $classGenerator) : string
  38      {
  39          $code = $classGenerator->generate();
  40  
  41          // @codeCoverageIgnoreStart
  42          if (! $this->canEval) {
  43              $fileName = tempnam(sys_get_temp_dir(), 'EvaluatingGeneratorStrategy.php.tmp.');
  44  
  45              file_put_contents($fileName, "<?php\n" . $code);
  46              /* @noinspection PhpIncludeInspection */
  47              require $fileName;
  48              unlink($fileName);
  49  
  50              return $code;
  51          }
  52          // @codeCoverageIgnoreEnd
  53  
  54          eval($code);
  55  
  56          return $code;
  57      }
  58  }


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