/** * Create stream for given filename. * * @param string|StreamInterface|StreamableInterface $filename * @return StreamInterface */ private function getStream($filename) { if ($filename instanceof StreamableInterface) { return $filename->getStream(); } if ($filename instanceof StreamInterface) { return $filename; } if (is_resource($filename)) { return new Stream($filename, 'r'); } if (!$this->files->isFile($filename)) { throw new \InvalidArgumentException("Unable to allocate response body stream, file does not exist."); } return new Stream(fopen($this->files->localUri($filename), 'r')); }
/** * {@inheritdoc} * * @param Isolator|null $isolator */ public function process($source, $namespace, $view, $cachedFilename = null, Isolator $isolator = null) { $isolator = !empty($isolator) ? $isolator : new Isolator(); //Let's hide original php blocks $source = $isolator->isolatePHP($source); //Now we have to detect blocks which has to be compiled //Restoring only evaluator blocks $phpBlocks = $evaluateBlocks = []; foreach ($isolator->getBlocks() as $id => $phpBlock) { if ($this->evaluatable($phpBlock)) { $evaluateBlocks[$id] = $phpBlock; continue; } $phpBlocks[$id] = $phpBlock; } //Let's only mount blocks to be evaluated $source = $isolator->setBlocks($evaluateBlocks)->repairPHP($source); $isolator->setBlocks($phpBlocks); //Let's create temporary filename $filename = $this->evalFilename($cachedFilename); //I must validate file syntax in a future try { $this->files->write($filename, $source, FilesInterface::RUNTIME, true); ob_start(); $__outputLevel__ = ob_get_level(); //Can be accessed in evaluated php $this->namespace = $namespace; $this->view = $view; try { include_once $this->files->localUri($filename); } finally { while (ob_get_level() > $__outputLevel__) { ob_end_clean(); } } $this->namespace = ''; $this->view = ''; $source = ob_get_clean(); //Dropping temporary filename $this->files->delete($filename); } catch (\ErrorException $exception) { throw $exception; } //Restoring original php blocks return $isolator->repairPHP($source); }
/** * {@inheritdoc} */ public function load($key) { if ($this->files->exists($key)) { include_once $this->files->localUri($key); } }
/** * Get local cache filename (to be included in view). * * @param string $key * @return string */ public function cachedFilename($key) { return $this->files->localUri($key); }