   'phpDocumentor\Descriptor\FileDescriptor * hash 61cc4a7704b89a3b00aaecd142aa0620 * pathControllers/Controller.php	 * source<?php
/**
 * Web Controller控制器基类
 *
 * @author camera360_server@camera360.com
 * @copyright Chengdu pinguo Technology Co.,Ltd.
 */

namespace PG\MSF\Controllers;

use PG\Exception\Errno;
use PG\Exception\ParameterValidationExpandException;
use PG\Exception\PrivilegeException;
use PG\AOP\Wrapper;
use PG\AOP\MI;
use PG\MSF\Base\Core;
use Exception;
use PG\MSF\Coroutine\CException;

/**
 * Class Controller
 * @package PG\MSF\Controllers
 */
class Controller extends Core
{
    /**
     * @var Wrapper|\PG\MSF\Base\Pool 对象池
     */
    protected $objectPool;

    /**
     * @var array 当前请求已使用的对象列表
     */
    public $objectPoolBuckets = [];

    /**
     * @var float 请求开始处理的时间
     */
    public $requestStartTime = 0.0;

    /**
     * @var string TCP_REQUEST|HTTP_REQUEST 请求类型
     */
    public $requestType;

    /**
     * Controller constructor.
     *
     * @param string $controllerName controller标识
     * @param string $methodName method名称
     */
    public function __construct($controllerName, $methodName)
    {
        // 支持自动销毁成员变量
        MI::__supportAutoDestroy(static::class);
        $this->requestStartTime = microtime(true);
    }

    /**
     * 获取对象池
     *
     * @return Wrapper|\PG\MSF\Base\Pool
     */
    public function getObjectPool()
    {
        return $this->objectPool;
    }

    /**
     * 设置对象池
     *
     * @param Wrapper|\PG\MSF\Base\Pool|NULL $objectPool Pool实例
     * @return $this
     */
    public function setObjectPool($objectPool)
    {
        $this->objectPool = $objectPool;
        return $this;
    }

    /**
     * 设置请求类型
     *
     * @param string $requestType TCP_REQUEST|HTTP_REQUEST
     * @return $this
     */
    public function setRequestType($requestType)
    {
        $this->requestType = $requestType;
        return $this;
    }

    /**
     * 返回请求类型
     *
     * @return string
     */
    public function getRequestType()
    {
        return $this->requestType;
    }

    /**
     * 异常的回调
     *
     * @param \Throwable $e 异常实例
     * @throws \Throwable
     */
    public function onExceptionHandle(\Throwable $e)
    {
        try {
            if ($e->getPrevious()) {
                $ce     = $e->getPrevious();
                $errMsg = dump($ce, false, true);
            } else {
                $errMsg = dump($e, false, true);
                $ce     = $e;
            }

            if ($ce instanceof ParameterValidationExpandException) {
                $this->getContext()->getLog()->warning($errMsg . ' with code ' . Errno::PARAMETER_VALIDATION_FAILED);
                $this->output('Server internal error', Errno::PARAMETER_VALIDATION_FAILED);
            } elseif ($ce instanceof PrivilegeException) {
                $this->getContext()->getLog()->warning($errMsg . ' with code ' . Errno::PRIVILEGE_NOT_PASS);
                $this->output('Server internal error', Errno::PRIVILEGE_NOT_PASS);
            } elseif ($ce instanceof \MongoException) {
                $this->getContext()->getLog()->error($errMsg . ' with code ' . $ce->getCode());
                $this->output('Server internal error', Errno::FATAL);
            } elseif ($ce instanceof CException) {
                $this->getContext()->getLog()->error($errMsg . ' with code ' . $ce->getCode());
                $this->output(parent::$stdClass, $ce->getCode());
            } else {
                $this->getContext()->getLog()->error($errMsg . ' with code ' . $ce->getCode());
                $this->output('Server internal error', $ce->getCode());
            }
        } catch (\Throwable $ne) {
            getInstance()->log->error('previous exception ' . dump($ce, false, true));
            getInstance()->log->error('handle exception ' . dump($ne, false, true));
        }
    }

    /**
     * 请求处理完成销毁相关资源
     */
    public function destroy()
    {
        if ($this->getContext()) {
            $this->getContext()->getLog()->appendNoticeLog();
            //销毁对象池
            foreach ($this->objectPoolBuckets as $k => $obj) {
                $this->objectPool->push($obj);
                $this->objectPoolBuckets[$k] = null;
                unset($this->objectPoolBuckets[$k]);
            }
            $this->resetProperties();
            $this->__isContruct = false;
            getInstance()->objectPool->push($this);
            parent::destroy();
        }
    }

    /**
     * 响应原始数据
     *
     * @param mixed|null $data 响应数据
     * @param int $status 响应HTTP状态码
     * @return void
     */
    public function output($data = null, $status = 200)
    {
        $this->getContext()->getOutput()->output($data, $status);
    }

    /**
     * 响应json格式数据
     *
     * @param mixed|null $data 响应数据
     * @param int $status 响应HTTP状态码
     * @return void
     */
    public function outputJson($data = null, $status = 200)
    {
        $this->getContext()->getOutput()->outputJson($data, $status);
    }

    /**
     * 通过模板引擎响应输出HTML
     *
     * @param array $data 待渲染KV数据
     * @param string|null $view 文件名
     * @throws \Exception
     * @throws \Throwable
     * @throws Exception
     * @return void
     */
    public function outputView(array $data, $view = null)
    {
        $this->getContext()->getOutput()->outputView($data, $view);
    }
}
 * namespaceAliases#phpDocumentor\Descriptor\Collection * itemsErrno\PG\Exception\Errno"ParameterValidationExpandException0\PG\Exception\ParameterValidationExpandExceptionPrivilegeException \PG\Exception\PrivilegeExceptionWrapper\PG\AOP\WrapperMI
\PG\AOP\MICore\PG\MSF\Base\Core	Exception
\Exception
CException\PG\MSF\Coroutine\CException * includes	  * constants	  * functions	 
 * classes	\PG\MSF\Controllers\Controller(phpDocumentor\Descriptor\ClassDescriptor	 * parent * implements	  * abstract * final	  * properties	
objectPool+phpDocumentor\Descriptor\PropertyDescriptor " * types 
 * default 	 * static * visibility	protected * fqsen*\PG\MSF\Controllers\Controller::objectPool * name% * namespace 
 * package
 * summary * description * fileDescriptor  * line * tags	var	 *phpDocumentor\Descriptor\Tag\VarDescriptor * variableName'	 3phpDocumentor\Descriptor\Type\UnknownTypeDescriptor.9.\PG\MSF\Base\Pool.62	对象池	 * errors	 <	  * inheritedElement objectPoolBuckets& "' (array())*public,1\PG\MSF\Controllers\Controller::objectPoolBuckets.>/ 0123 4"5	6	 78'	 9.array.62$当前请求已使用的对象列表<	 <	 = requestStartTime& "' (0.0)*@,0\PG\MSF\Controllers\Controller::requestStartTime.D/ 0123 4'5	6	 78'	 -phpDocumentor\Descriptor\Type\FloatDescriptor .62请求开始处理的时间<	 <	 = requestType& "' ( )*@,+\PG\MSF\Controllers\Controller::requestType.I/ 0123 4,5	6	 78'	 .phpDocumentor\Descriptor\Type\StringDescriptor .62%TCP_REQUEST|HTTP_REQUEST 请求类型<	 <	 = 
 * methods	
__construct)phpDocumentor\Descriptor\MethodDescriptor ""#)*@ * arguments	$controllerName+phpDocumentor\Descriptor\ArgumentDescriptor	 * method"I'	 K (  * byReference * isVariadic,.Q/ 012controller标识3 4 5	 <	 = $methodNameRS"I'	 K ( TU,.W/ 012method名称3 4 5	 <	 = ,-\PG\MSF\Controllers\Controller::__construct().N/ 01Controller constructor.23 445	param	 ,phpDocumentor\Descriptor\Tag\ParamDescriptor8Q'"M.[2V<	 \8W'"U.[2X<	 return	 <	 = getObjectPoolO ""#)*@P	 ,/\PG\MSF\Controllers\Controller::getObjectPool().^/ 01获取对象池23 4@5	]	 -phpDocumentor\Descriptor\Tag\ReturnDescriptor'	 9.9.:.]2<	 [	 <	 = setObjectPoolO ""#)*@P	$objectPoolRS"|'	 9.9.:9.NULL( TU,.c/ 012
Pool实例3 4 5	 <	 = ,/\PG\MSF\Controllers\Controller::setObjectPool().b/ 01设置对象池23 4K5	[	 \8c'".[2e<	 ]	 a'	 9.$this.]2<	 <	 = setRequestTypeO ""#)*@P	$requestTypeRS"'	 K ( TU,.j/ 012TCP_REQUEST|HTTP_REQUEST3 4 5	 <	 = ,0\PG\MSF\Controllers\Controller::setRequestType().i/ 01设置请求类型23 4W5	[	 \8j'".[2k<	 ]	 a'	 9.h.]2<	 <	 = getRequestTypeO ""#)*@P	 ,0\PG\MSF\Controllers\Controller::getRequestType().n/ 01返回请求类型23 4b5	]	 a'	 K .]2<	 [	 <	 = onExceptionHandleO ""#)*@P	$eRS"'	 9.
\Throwable( TU,.r/ 012异常实例3 4 5	 <	 = ,3\PG\MSF\Controllers\Controller::onExceptionHandle().q/ 01异常的回调23 4m5	[	 \8r'".[2t<	 throws	 -phpDocumentor\Descriptor\Tag\ThrowsDescriptor'	 9.s.w2<	 ]	 <	 = destroyO ""#)*@P	 ,)\PG\MSF\Controllers\Controller::destroy().y/ 01$请求处理完成销毁相关资源23 45	]	 [	 <	 = outputO ""#)*@P	$dataRS"'	 9.mixed9.null(TU,.}/ 012响应数据3 4 5	 <	 = $statusRS"'	 /phpDocumentor\Descriptor\Type\IntegerDescriptor (200TU,./ 012响应HTTP状态码3 4 5	 <	 = ,(\PG\MSF\Controllers\Controller::output().|/ 01响应原始数据23 45	[	 \8}'".[2<	 \8'".[2<	 ]	 a'	 9.void.]2<	 <	 = 
outputJsonO ""#)*@P	}RS#'	 9.~9.(TU,.}/ 0123 4 5	 <	 = RS#'	  (TU,./ 0123 4 5	 <	 = ,,\PG\MSF\Controllers\Controller::outputJson()./ 01响应json格式数据23 45	[	 \8}'#.[2<	 \8'#%.[2<	 ]	 a'	 9..]2<	 <	 = 
outputViewO ""#)*@P	}RS#@'	 9.B( TU,.}/ 012待渲染KV数据3 4 5	 <	 = $viewRS#@'	 K 9.(TU,./ 012	文件名3 4 5	 <	 = ,,\PG\MSF\Controllers\Controller::outputView()./ 01"通过模板引擎响应输出HTML23 45	[	 \8}'#D.[2<	 \8'#L.[2<	 w	 x'	 9..w2<	 x'	 9.s.w2<	 x'	 9..w2<	 ]	 a'	 9..]2<	 <	 =  * usedTraits	 ,.
Controller/\PG\MSF\Controllers0PG\MSF\Controllers1Class Controller23" 45	package	 &phpDocumentor\Descriptor\TagDescriptor.2<	 
subpackage	 <	 =  * interfaces	 	 * traits	 
 * markers	 ,.Controller.php/ 0Default1Web Controller控制器基类23 4 5	author	 -phpDocumentor\Descriptor\Tag\AuthorDescriptor.2camera360_server@camera360.com<	 	copyright	 .2"Chengdu pinguo Technology Co.,Ltd.<	 	 .2<	 	 <	 = 