00001 <?php
00002
00003 class Varien_Pear_Frontend extends PEAR_Frontend
00004 {
00005 protected $_logStream = null;
00006 protected $_outStream = null;
00007 protected $_log = array();
00008 protected $_out = array();
00009
00010
00011
00012
00013
00014
00015 public function setLogStream($stream)
00016 {
00017 $this->_logStream = $stream;
00018 return $this;
00019 }
00020
00021 public function getLogStream()
00022 {
00023 return $this->_logStream;
00024 }
00025
00026 public function log($msg, $append_crlf = true)
00027 {
00028 if (is_null($msg) || false===$msg or ''===$msg) {
00029 return;
00030 }
00031
00032 if ($append_crlf) {
00033 $msg .= "\r\n";
00034 }
00035
00036 $this->_log[] = $msg;
00037
00038 if ('stdout'===$this->_logStream) {
00039 if ($msg==='.') {
00040 echo ' ';
00041 }
00042 echo $msg;
00043 }
00044 elseif (is_resource($this->_logStream)) {
00045 fwrite($this->_logStream, $msg);
00046 }
00047 }
00048
00049 public function outputData($data, $command = '_default')
00050 {
00051 $this->_out[] = array('output'=>$data, 'command'=>$command);
00052
00053 if ('stdout'===$this->_logStream) {
00054 if (is_string($data)) {
00055 echo $data."\r\n";
00056 } elseif (is_array($data) && !empty($data['message']) && is_string($data['message'])) {
00057 echo $data['message']."\r\n";
00058 } elseif (is_array($data) && !empty($data['data']) && is_string($data['data'])) {
00059 echo $data['data']."\r\n";
00060 } else {
00061 print_r($data);
00062 }
00063 }
00064 }
00065
00066 public function userConfirm()
00067 {
00068
00069 }
00070
00071 public function clear()
00072 {
00073 $this->_log = array();
00074 $this->_out = array();
00075 }
00076
00077 public function getLog()
00078 {
00079 return $this->_log;
00080 }
00081
00082 public function getLogText()
00083 {
00084 $text = '';
00085 foreach ($this->getLog() as $log) {
00086 $text .= $log;
00087 }
00088 return $text;
00089 }
00090
00091 public function getOutput()
00092 {
00093 return $this->_out;
00094 }
00095 }