/lib/Varien/Pear/Frontend.php

https://github.com/rgranadino/magento-mirror · PHP · 127 lines · 75 code · 16 blank · 36 comment · 12 complexity · d3d737fc569c67b177ccd0b6dcb5f22f MD5 · raw file

  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magentocommerce.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category Varien
  22. * @package Varien_Pear
  23. * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * Pear frontend routines
  28. * *
  29. * @category Varien
  30. * @package Varien_Pear
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Varien_Pear_Frontend extends PEAR_Frontend
  34. {
  35. protected $_logStream = null;
  36. protected $_outStream = null;
  37. protected $_log = array();
  38. protected $_out = array();
  39. /**
  40. * Enter description here...
  41. *
  42. * @param string|resource $stream 'stdout' or open php stream
  43. */
  44. public function setLogStream($stream)
  45. {
  46. $this->_logStream = $stream;
  47. return $this;
  48. }
  49. public function getLogStream()
  50. {
  51. return $this->_logStream;
  52. }
  53. public function log($msg, $append_crlf = true)
  54. {
  55. if (is_null($msg) || false===$msg or ''===$msg) {
  56. return;
  57. }
  58. if ($append_crlf) {
  59. $msg .= "\r\n";
  60. }
  61. $this->_log[] = $msg;
  62. if ('stdout'===$this->_logStream) {
  63. if ($msg==='.') {
  64. echo ' ';
  65. }
  66. echo $msg;
  67. }
  68. elseif (is_resource($this->_logStream)) {
  69. fwrite($this->_logStream, $msg);
  70. }
  71. }
  72. public function outputData($data, $command = '_default')
  73. {
  74. $this->_out[] = array('output'=>$data, 'command'=>$command);
  75. if ('stdout'===$this->_logStream) {
  76. if (is_string($data)) {
  77. echo $data."\r\n";
  78. } elseif (is_array($data) && !empty($data['message']) && is_string($data['message'])) {
  79. echo $data['message']."\r\n";
  80. } elseif (is_array($data) && !empty($data['data']) && is_string($data['data'])) {
  81. echo $data['data']."\r\n";
  82. } else {
  83. print_r($data);
  84. }
  85. }
  86. }
  87. public function userConfirm()
  88. {
  89. }
  90. public function clear()
  91. {
  92. $this->_log = array();
  93. $this->_out = array();
  94. }
  95. public function getLog()
  96. {
  97. return $this->_log;
  98. }
  99. public function getLogText()
  100. {
  101. $text = '';
  102. foreach ($this->getLog() as $log) {
  103. $text .= $log;
  104. }
  105. return $text;
  106. }
  107. public function getOutput()
  108. {
  109. return $this->_out;
  110. }
  111. }