Beispiel #1
0
 /**
  * {@inheritdoc}
  *
  * @param Isolator $isolator Custom PHP isolator instance.
  */
 public function process($source, Isolator $isolator = null)
 {
     $isolator = !empty($isolator) ? $isolator : new Isolator();
     //Real php source code isolation
     $source = $isolator->isolatePHP($source);
     //Restoring only evaluator blocks
     $phpBlocks = $evaluateBlocks = [];
     foreach ($isolator->getBlocks() as $id => $phpBlock) {
         foreach ($this->options['flags'] as $flag) {
             if (strpos($phpBlock, $flag) !== false) {
                 $evaluateBlocks[$id] = $phpBlock;
                 continue 2;
             }
         }
         $phpBlocks[$id] = $phpBlock;
     }
     $source = $isolator->setBlocks($evaluateBlocks)->repairPHP($source);
     $isolator->setBlocks($phpBlocks);
     //Required to prevent collisions
     $filename = $this->views->config()['cache']['directory'] . "/{$this->uniqueID()}.php";
     try {
         $this->files->write($filename, $source, FilesInterface::RUNTIME, true);
         ob_start();
         include_once $filename;
         $source = ob_get_clean();
         $this->files->delete($filename);
     } catch (\ErrorException $exception) {
         throw $exception;
     }
     return $isolator->repairPHP($source);
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function __construct(ViewManager $views, FilesInterface $files, $namespace, $view, $filename)
 {
     //Our configuration is stored in parent ViewManager config
     $this->config = $views->config()['compiler'];
     $this->config['cache'] = $views->config()['cache'];
     $this->views = $views;
     $this->files = $files;
     $this->namespace = $namespace;
     $this->view = $view;
     $this->filename = $filename;
     $this->dependencies = $views->getDependencies();
 }