mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-02 05:02:48 +08:00
128 lines
3.2 KiB
PHP
128 lines
3.2 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 Exception;
|
|
use think\console\output\Descriptor;
|
|
use think\console\output\driver\Buffer;
|
|
use think\console\output\driver\Console;
|
|
use think\console\output\driver\Nothing;
|
|
|
|
/**
|
|
* Class Output
|
|
* @package think\console
|
|
*
|
|
* @see think\console\output\driver\Console::setDecorated
|
|
* @method void setDecorated($decorated)
|
|
*
|
|
* @see think\console\output\driver\Buffer::fetch
|
|
* @method string fetch()
|
|
*/
|
|
class Output
|
|
{
|
|
const VERBOSITY_QUIET = 0;
|
|
const VERBOSITY_NORMAL = 1;
|
|
const VERBOSITY_VERBOSE = 2;
|
|
const VERBOSITY_VERY_VERBOSE = 3;
|
|
const VERBOSITY_DEBUG = 4;
|
|
|
|
const OUTPUT_NORMAL = 0;
|
|
const OUTPUT_RAW = 1;
|
|
const OUTPUT_PLAIN = 2;
|
|
|
|
private $verbosity = self::VERBOSITY_NORMAL;
|
|
|
|
/** @var Buffer|Console|Nothing */
|
|
private $handle = null;
|
|
|
|
public function __construct($driver = 'console')
|
|
{
|
|
$class = '\\think\\console\\output\\driver\\' . ucwords($driver);
|
|
|
|
$this->handle = new $class($this);
|
|
}
|
|
|
|
public function writeln($messages, $type = self::OUTPUT_NORMAL)
|
|
{
|
|
$this->write($messages, true, $type);
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function write($messages, $newline = false, $type = self::OUTPUT_NORMAL)
|
|
{
|
|
$this->handle->write($messages, $newline, $type);
|
|
}
|
|
|
|
public function renderException(\Exception $e)
|
|
{
|
|
$this->handle->renderException($e);
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function setVerbosity($level)
|
|
{
|
|
$this->verbosity = (int) $level;
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function getVerbosity()
|
|
{
|
|
return $this->verbosity;
|
|
}
|
|
|
|
public function isQuiet()
|
|
{
|
|
return self::VERBOSITY_QUIET === $this->verbosity;
|
|
}
|
|
|
|
public function isVerbose()
|
|
{
|
|
return self::VERBOSITY_VERBOSE <= $this->verbosity;
|
|
}
|
|
|
|
public function isVeryVerbose()
|
|
{
|
|
return self::VERBOSITY_VERY_VERBOSE <= $this->verbosity;
|
|
}
|
|
|
|
public function isDebug()
|
|
{
|
|
return self::VERBOSITY_DEBUG <= $this->verbosity;
|
|
}
|
|
|
|
public function describe($object, array $options = [])
|
|
{
|
|
$descriptor = new Descriptor();
|
|
$options = array_merge([
|
|
'raw_text' => false,
|
|
], $options);
|
|
|
|
$descriptor->describe($this, $object, $options);
|
|
}
|
|
|
|
public function __call($method, $args)
|
|
{
|
|
if ($this->handle && method_exists($this->handle, $method)) {
|
|
return call_user_func_array([$this->handle, $method], $args);
|
|
} else {
|
|
throw new Exception('method not exists:' . __CLASS__ . '->' . $method);
|
|
}
|
|
}
|
|
|
|
}
|