From 49438d750149f5d5e7dd41e980e411e9bf8af3ce Mon Sep 17 00:00:00 2001 From: Mateusz Tymek Date: Mon, 8 Feb 2016 21:55:37 +0100 Subject: [PATCH] Remove stream wrapper functionality --- src/Resolver/TemplatePathStack.php | 47 ------ src/Stream.php | 183 ------------------------ test/Resolver/TemplatePathStackTest.php | 37 ----- 3 files changed, 267 deletions(-) delete mode 100644 src/Stream.php diff --git a/src/Resolver/TemplatePathStack.php b/src/Resolver/TemplatePathStack.php index 6a5405a8..9cd61774 100644 --- a/src/Resolver/TemplatePathStack.php +++ b/src/Resolver/TemplatePathStack.php @@ -50,14 +50,6 @@ 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 * @@ -65,13 +57,6 @@ class TemplatePathStack implements ResolverInterface */ 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); @@ -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; @@ -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 * @@ -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; } } diff --git a/src/Stream.php b/src/Stream.php deleted file mode 100644 index b4994f2d..00000000 --- a/src/Stream.php +++ /dev/null @@ -1,183 +0,0 @@ -data = file_get_contents($path); - - /** - * If reading the file failed, update our local stat store - * to reflect the real stat of the file, then return on failure - */ - if ($this->data === false) { - $this->stat = stat($path); - return false; - } - - /** - * Convert to long-form and to - * - */ - $this->data = preg_replace('/\<\?\=/', "data); - $this->data = preg_replace('/<\?(?!xml|php)/s', 'data); - - /** - * file_get_contents() won't update PHP's stat cache, so we grab a stat - * of the file to prevent additional reads should the script be - * requested again, which will make include() happy. - */ - $this->stat = stat($path); - - return true; - } - - /** - * Included so that __FILE__ returns the appropriate info - * - * @return array - */ - public function url_stat() - { - return $this->stat; - } - - /** - * Reads from the stream. - * - * @param int $count - * @return string - */ - public function stream_read($count) - { - $ret = substr($this->data, $this->pos, $count); - $this->pos += strlen($ret); - return $ret; - } - - /** - * Tells the current position in the stream. - * - * @return int - */ - public function stream_tell() - { - return $this->pos; - } - - /** - * Tells if we are at the end of the stream. - * - * @return bool - */ - public function stream_eof() - { - return $this->pos >= strlen($this->data); - } - - /** - * Stream statistics. - * - * @return array - */ - public function stream_stat() - { - return $this->stat; - } - - /** - * Seek to a specific point in the stream. - * - * @param $offset - * @param $whence - * @return bool - */ - public function stream_seek($offset, $whence) - { - switch ($whence) { - case SEEK_SET: - if ($offset < strlen($this->data) && $offset >= 0) { - $this->pos = $offset; - return true; - } else { - return false; - } - break; - - case SEEK_CUR: - if ($offset >= 0) { - $this->pos += $offset; - return true; - } else { - return false; - } - break; - - case SEEK_END: - if (strlen($this->data) + $offset >= 0) { - $this->pos = strlen($this->data) + $offset; - return true; - } else { - return false; - } - break; - - default: - return false; - } - } -} diff --git a/test/Resolver/TemplatePathStackTest.php b/test/Resolver/TemplatePathStackTest.php index b2212346..05b07a4e 100644 --- a/test/Resolver/TemplatePathStackTest.php +++ b/test/Resolver/TemplatePathStackTest.php @@ -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() { @@ -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 [ @@ -202,7 +175,6 @@ public function validOptions() { $options = [ 'lfi_protection' => false, - 'use_stream_wrapper' => true, 'default_suffix' => 'php', ]; return [ @@ -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()); } @@ -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()); }