Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Remove stream wrapper functionality #34

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 0 additions & 47 deletions src/Resolver/TemplatePathStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,13 @@ class TemplatePathStack implements ResolverInterface
*/
protected $lfiProtectionOn = true;

/**@+
* Flags used to determine if a stream wrapper should be used for enabling short tags
* @var bool
*/
protected $useViewStream = false;
protected $useStreamWrapper = false;
/**@-*/

/**
* Constructor
*
* @param null|array|Traversable $options
*/
public function __construct($options = null)
{
$this->useViewStream = (bool) ini_get('short_open_tag');
if ($this->useViewStream) {
if (!in_array('zend.view', stream_get_wrappers())) {
stream_wrapper_register('zend.view', 'Zend\View\Stream');
}
}

$this->paths = new SplStack;
if (null !== $options) {
$this->setOptions($options);
Expand Down Expand Up @@ -102,9 +87,6 @@ public function setOptions($options)
case 'script_paths':
$this->addPaths($value);
break;
case 'use_stream_wrapper':
$this->setUseStreamWrapper($value);
break;
case 'default_suffix':
$this->setDefaultSuffix($value);
break;
Expand Down Expand Up @@ -249,31 +231,6 @@ public function isLfiProtectionOn()
return $this->lfiProtectionOn;
}

/**
* Set flag indicating if stream wrapper should be used if short_open_tag is off
*
* @param bool $flag
* @return TemplatePathStack
*/
public function setUseStreamWrapper($flag)
{
$this->useStreamWrapper = (bool) $flag;
return $this;
}

/**
* Should the stream wrapper be used if short_open_tag is off?
*
* Returns true if the use_stream_wrapper flag is set, and if short_open_tag
* is disabled.
*
* @return bool
*/
public function useStreamWrapper()
{
return ($this->useViewStream && $this->useStreamWrapper);
}

/**
* Retrieve the filesystem path to a view script
*
Expand Down Expand Up @@ -314,10 +271,6 @@ public function resolve($name, Renderer $renderer = null)
break;
}
}
if ($this->useStreamWrapper()) {
// If using a stream wrapper, prepend the spec to the path
$filePath = 'zend.view://' . $filePath;
}
return $filePath;
}
}
Expand Down
183 changes: 0 additions & 183 deletions src/Stream.php

This file was deleted.

37 changes: 0 additions & 37 deletions test/Resolver/TemplatePathStackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,6 @@ public function testMayDisableLfiProtection()
$this->assertFalse($this->stack->isLfiProtectionOn());
}

public function testStreamWrapperDisabledByDefault()
{
$this->assertFalse($this->stack->useStreamWrapper());
}

public function testMayEnableStreamWrapper()
{
$flag = (bool) ini_get('short_open_tag');
if (!$flag) {
$this->markTestSkipped('Short tags are disabled; cannot test');
}
$this->stack->setUseStreamWrapper(true);
$this->assertTrue($this->stack->useStreamWrapper());
}

public function testDoesNotAllowParentDirectoryTraversalByDefault()
{
Expand Down Expand Up @@ -160,19 +146,6 @@ public function testReturnsFullPathNameWhenAbleToResolveScriptPath()
$this->assertEquals($expected, $test);
}

public function testReturnsPathWithStreamProtocolWhenStreamWrapperEnabled()
{
$flag = (bool) ini_get('short_open_tag');
if (!$flag) {
$this->markTestSkipped('Short tags are disabled; cannot test');
}
$this->stack->setUseStreamWrapper(true)
->addPath($this->baseDir . '/_templates');
$expected = 'zend.view://' . realpath($this->baseDir . '/_templates/test.phtml');
$test = $this->stack->resolve('test.phtml');
$this->assertEquals($expected, $test);
}

public function invalidOptions()
{
return [
Expand Down Expand Up @@ -202,7 +175,6 @@ public function validOptions()
{
$options = [
'lfi_protection' => false,
'use_stream_wrapper' => true,
'default_suffix' => 'php',
];
return [
Expand All @@ -221,12 +193,7 @@ public function testAllowsSettingOptions($options)
$options['script_paths'] = $this->paths;
$this->stack->setOptions($options);
$this->assertFalse($this->stack->isLfiProtectionOn());

$expected = (bool) ini_get('short_open_tag');
$this->assertSame($expected, $this->stack->useStreamWrapper());

$this->assertSame($options['default_suffix'], $this->stack->getDefaultSuffix());

$this->assertEquals(array_reverse($this->paths), $this->stack->getPaths()->toArray());
}

Expand All @@ -240,10 +207,6 @@ public function testAllowsPassingOptionsToConstructor($options)
$options['script_paths'] = $this->paths;
$stack = new TemplatePathStack($options);
$this->assertFalse($stack->isLfiProtectionOn());

$expected = (bool) ini_get('short_open_tag');
$this->assertSame($expected, $stack->useStreamWrapper());

$this->assertEquals(array_reverse($this->paths), $stack->getPaths()->toArray());
}

Expand Down