Files
sentcms/core/library/think/console/Output.php
2016-06-21 17:12:08 +08:00

86 lines
2.1 KiB
PHP

<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2015 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
namespace think\console;
use think\console\output\Formatter;
use think\console\output\Stream;
class Output extends Stream
{
/** @var Stream */
private $stderr;
public function __construct()
{
$outputStream = 'php://stdout';
if (!$this->hasStdoutSupport()) {
$outputStream = 'php://output';
}
parent::__construct(fopen($outputStream, 'w'));
$this->stderr = new Stream(fopen('php://stderr', 'w'), $this->getFormatter());
}
/**
* {@inheritdoc}
*/
public function setDecorated($decorated)
{
parent::setDecorated($decorated);
$this->stderr->setDecorated($decorated);
}
/**
* {@inheritdoc}
*/
public function setFormatter(Formatter $formatter)
{
parent::setFormatter($formatter);
$this->stderr->setFormatter($formatter);
}
/**
* {@inheritdoc}
*/
public function setVerbosity($level)
{
parent::setVerbosity($level);
$this->stderr->setVerbosity($level);
}
/**
* {@inheritdoc}
*/
public function getErrorOutput()
{
return $this->stderr;
}
/**
* {@inheritdoc}
*/
public function setErrorOutput(Output $error)
{
$this->stderr = $error;
}
/**
* 检查当前环境是否支持控制台输出写入标准输出。
* @return bool
*/
protected function hasStdoutSupport()
{
return ('OS400' != php_uname('s'));
}
}