cvs: pear /Cache_Lite/Lite NestedOutput.php /Cache_Lite/tests NestedOutputTest.php

From: Date: Fri, 01 May 2009 13:19:25 +0000
Subject: cvs: pear /Cache_Lite/Lite NestedOutput.php /Cache_Lite/tests NestedOutputTest.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-56023@lists.php.net to get a copy of this message
tacker Fri May 1 13:19:25 2009 UTC Added files: /pear/Cache_Lite/Lite NestedOutput.php /pear/Cache_Lite/tests NestedOutputTest.php Log: Added support for nested output caching. See Pear Bug #16162. http://cvs.php.net/viewvc.cgi/pear/Cache_Lite/Lite/NestedOutput.php?view=markup&rev=1.1 Index: pear/Cache_Lite/Lite/NestedOutput.php +++ pear/Cache_Lite/Lite/NestedOutput.php <?php /** * This class extends Cache_Lite and uses output buffering to get the data to cache. * It supports nesting of caches * * @package Cache_Lite * @version $Id: NestedOutput.php,v 1.1 2009/05/01 13:19:25 tacker Exp $ * @author Markus Tacker <tacker@php.net> */ require_once('Cache/Lite/Output.php'); class Cache_Lite_NestedOutput extends Cache_Lite_Output { private $nestedIds = array(); private $nestedGroups = array(); /** * Start the cache * * @param string $id cache id * @param string $group name of the cache group * @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested * @return boolean|string false if the cache is not hit else the data * @access public */ function start($id, $group = 'default', $doNotTestCacheValidity = false) { $this->nestedIds[] = $id; $this->nestedGroups[] = $group; $data = $this->get($id, $group, $doNotTestCacheValidity); if ($data !== false) { return $data; } ob_start(); ob_implicit_flush(false); return false; } /** * Stop the cache * * @param boolen * @return string return contents of cache */ function end() { $data = ob_get_contents(); ob_end_clean(); $id = array_pop($this->nestedIds); $group = array_pop($this->nestedGroups); $this->save($data, $id, $group); return $data; } } http://cvs.php.net/viewvc.cgi/pear/Cache_Lite/tests/NestedOutputTest.php?view=markup&rev=1.1 Index: pear/Cache_Lite/tests/NestedOutputTest.php +++ pear/Cache_Lite/tests/NestedOutputTest.php <?php /** * Test for Cache_Lite_NestedOutput * * @package Cache_Lite * @category Caching * @version $Id: NestedOutputTest.php,v 1.1 2009/05/01 13:19:25 tacker Exp $ * @author Markus Tacker <tacker@php.net> */ require_once '../Lite/NestedOutput.php'; class NestedOutputTest extends PHPUnit_Framework_TestCase { /** * "Test" used for documenting the nested output buffering feature of php */ public function testPhpObNesting() { $outsideText = "This is the outside"; $insideText = "This is the inside"; ob_start(); echo $outsideText; ob_start(); echo $insideText; $innerContents = ob_get_contents(); ob_end_clean(); $outerContents = ob_get_contents(); ob_end_clean(); $this->assertEquals( $insideText, $innerContents ); $this->assertEquals( $outsideText, $outerContents ); } /** * Test for Cache_Lite_NestedOutput */ public function testCacheLiteOutputNesting() { $outsideText = "This is the outside"; $insideText = "This is the inside"; $options = array( 'caching' => true, 'cacheDir' => '/tmp/', 'lifeTime' => 10 ); $cache = new Cache_Lite_NestedOutput($options); $this->assertFalse($cache->start('foo', 'a')); echo $outsideText; $this->assertFalse($cache->start('bar', 'b')); echo $insideText; $inside = $cache->end(); $outside = $cache->end(); $this->assertEquals($outsideText, $outside, 'Validate outside'); $this->assertEquals($insideText, $inside, 'Validate inside'); $cache = new Cache_Lite_NestedOutput($options); $this->assertEquals($outsideText, $cache->start('foo', 'a'), 'Validate outside'); $this->assertEquals($insideText, $cache->start('bar', 'b'), 'Validate inside'); } }

« previous php.pear.cvs (#56023) next »