Gc\View\Resolver\TemplatePathStack::resolve PHP Method

resolve() public method

Retrieve the filesystem path to a view script
public resolve ( string $name, Zend\View\Renderer\RendererInterface $renderer = null ) : string
$name string Template name
$renderer Zend\View\Renderer\RendererInterface Renderer
return string
    public function resolve($name, Renderer $renderer = null)
    {
        $this->lastLookupFailure = false;
        if ($this->isLfiProtectionOn() && preg_match('#\\.\\.[\\\\/]#', $name)) {
            throw new Exception\DomainException('Requested scripts may not include parent directory traversal ("../", "..\\" notation)');
        }
        if (!count($this->paths)) {
            $this->lastLookupFailure = static::FAILURE_NO_PATHS;
            return false;
        }
        // Ensure we have the expected file extension
        $defaultSuffix = $this->getDefaultSuffix();
        if (pathinfo($name, PATHINFO_EXTENSION) != $defaultSuffix) {
            $name .= '.' . $defaultSuffix;
        }
        foreach ($this->paths as $path) {
            $file = new SplFileInfo($path . $name);
            if ($file->isReadable()) {
                // Found! Return it.
                if (($filePath = $file->getRealPath()) === false && substr($path, 0, 7) === 'phar://') {
                    // Do not try to expand phar paths (realpath + phars == fail)
                    $filePath = $path . $name;
                    if (!file_exists($filePath)) {
                        break;
                    }
                }
                return $filePath;
            }
        }
        $this->lastLookupFailure = static::FAILURE_NOT_FOUND;
        return false;
    }

Usage Example

Example #1
0
 /**
  * Test
  *
  * @return void
  */
 public function testResolveWithFakePharProtocol()
 {
     $path = 'phar://' . __DIR__ . DIRECTORY_SEPARATOR . '_templates' . DIRECTORY_SEPARATOR . 'fake-view.phar';
     $this->object->addPath($path);
     $markup = $this->object->resolve('hello.phtml');
     $this->assertFalse($markup);
 }
TemplatePathStack