<?php
/**
* provides {@link r3_generate_OutputManager} class
*
*
* Copyright (c) 2007 Yahoo! Inc. All rights reserved.
* The copyrights embodied in the content of this file are licensed under the BSD
* open source license
*
* @package r3
* @subpackage generate
*/
/**
* requires
*/
require_once( "r3/generate/Output.php" );
require_once( "r3/generate/FileOutput.php" );
require_once( "r3/generate/StdoutOutput.php" );
/**
* provides {@link r3_generate_Output} class
*
* @package r3
* @subpackage generate
*/
class r3_generate_OutputManager {
private $outputstack = array();
private $defaultOutput;
function __construct() {
$this->setDefault( new r3_generate_FileOutput() );
}
function stackEmpty() {
return ( ! count( $this->outputstack ) );
}
function setDefault( r3_generate_Output $output ) {
$this->defaultOutput = $output;
}
private function current() {
if ( $this->stackEmpty() ) {
$this->add( $this->defaultOutput );
}
return $this->outputstack[ count( $this->outputstack )-1 ];
}
function open( r3_generate_GenerateContext $context ) {
$current = $this->current();
$current->open( $context );
}
function output( $txt ) {
$current = $this->current();
if ( ! $current->isOpen() ) {
throw new r3_util_Exception("attempting to write to unopened Output");
}
$current->output( $txt );
}
function close( ) {
$current = $this->current();
if ( $current->isOpen() ) {
$current->close( );
}
array_pop( $this->outputstack );
}
function remove( ) {
$this->current();
return array_pop( $this->outputstack );
}
function add( r3_generate_Output $output ) {
array_push( $this->outputstack, $output );
}
function clear() {
$this->outputstack=array();
}
function closeAll( ) {
while ( ! is_null( $this->close( ) ) ) {
;
}
}
}
?>