PHP Buffer Manager
A simple manager for PHP output buffers. Can manage named or unnamed buffers., (*1)
Useage
The most common useage for this class is named output buffers, so that you can buffer multiple pieces of a page and then output them later in specific places., (*2)
start('block1');
echo 'This is in block 1';
$bufferManager->end();
$bufferManager->start('block2');
echo 'This is in block 2';
$bufferManager->end();
?>
This is block 1's heading
get('block1'); ?>
This is block 2's heading
get('block2'); ?>
Here is an example for an HTML document, illustrating how it might be used to output the buffers in an HTML document, or in a JSON representation of that document if the request is via AJAX., (*3)
start('main');
include($mainContentFile);
$bufferManager->end();
$bufferManager->start('aside');
include($asideContentFile);
$bufferManager->end();
if($isAjaxRequest){
echo json_encode(Array(
'title'=> $pagetitle
,'main'=> $bufferManager->get('main')
,'aside'=> $bufferManager->get('aside')
));
}else{
?>
<!DOCTYPE html>
<html>
<title><?=$pagetitle?></title>
…
<main><?=$bufferManager->get('main')?></main>
<aside><?=$bufferManager->get('aside')?></aside>
…
</html>