   'phpDocumentor\Descriptor\FileDescriptor * hash 56832ed950199917e539af4df28e1b0a * pathBase/Pool.php	 * source
6<?php
/**
 * 对象池
 *
 * @author camera360_server@camera360.com
 * @copyright Chengdu pinguo Technology Co.,Ltd.
 */

namespace PG\MSF\Base;

use Exception;
use PG\AOP\Wrapper;

/**
 * Class Pool
 * @package PG\MSF\Base
 */
class Pool
{
    /**
     * @var Pool 对象池实现
     */
    private static $instance;

    /**
     * @var Wrapper AOP包装器
     */
    public $__wrapper;

    /**
     * @var array 所有内存中的对象，根据类名区分
     */
    public $map;

    /**
     * Pool constructor.
     */
    private function __construct()
    {
        $this->map = [];
    }

    /**
     * 产生对象池单例
     *
     * @return Pool
     */
    public static function getInstance()
    {
        if (self::$instance == null) {
            self::$instance = new Pool();
        }
        return self::$instance;
    }

    /**
     * 获取一个
     *
     * @param string $class 完全命名空间类名
     * @param array $args 可变参数列表
     * @return mixed
     */
    public function get($class, ...$args)
    {
        $poolName = trim($class, '\\');

        if (!$poolName) {
            return null;
        }

        $pool     = $this->map[$poolName] ?? null;
        if ($pool == null) {
            $pool = $this->applyNewPool($poolName);
        }

        if ($pool->count()) {
            $obj = $pool->shift();
            $obj->isContruct = false;
            return $obj;
        } else {
            $reflector         = new \ReflectionClass($poolName);
            $obj               = $reflector->newInstanceWithoutConstructor();
            $obj->__useCount   = 0;
            $obj->__genTime    = time();
            $obj->__isContruct = false;
            unset($reflector);
            return $obj;
        }
    }

    /**
     * 创建新的栈，用于储存相应的对象
     *
     * @param string $poolName 对象池名称
     * @return mixed
     * @throws Exception
     */
    private function applyNewPool($poolName)
    {
        if (array_key_exists($poolName, $this->map)) {
            throw new Exception('the name is exists in pool map');
        }
        $this->map[$poolName] = new \SplStack();

        return $this->map[$poolName];
    }

    /**
     * 返还一个对象
     *
     * @param mixed $classInstance 对象实例
     */
    public function push($classInstance)
    {
        $class = trim(get_class($classInstance), '\\');
        $pool = $this->map[$class] ?? null;
        if ($pool == null) {
            $pool = $this->applyNewPool($class);
        }
        $pool->push($classInstance);
    }
}
 * namespaceAliases#phpDocumentor\Descriptor\Collection * items	Exception
\ExceptionWrapper\PG\AOP\Wrapper * includes	  * constants	  * functions	 
 * classes	\PG\MSF\Base\Pool(phpDocumentor\Descriptor\ClassDescriptor	 * parent * implements	  * abstract * final	  * properties	instance+phpDocumentor\Descriptor\PropertyDescriptor" * types 
 * default 	 * static * visibilityprivate * fqsen\PG\MSF\Base\Pool::instance * name * namespace 
 * package
 * summary * description * fileDescriptor  * line * tags	var	 *phpDocumentor\Descriptor\Tag\VarDescriptor * variableName	 3phpDocumentor\Descriptor\Type\UnknownTypeDescriptor""*&对象池实现	 * errors	 /	  * inheritedElement 	__wrapper"  public \PG\MSF\Base\Pool::__wrapper"1# $%&' ()	*	 +,	 -""*&AOP包装器/	 /	 0 map"  2 \PG\MSF\Base\Pool::map"5# $%&' (!)	*	 +,	 -"array"*&-所有内存中的对象，根据类名区分/	 /	 0 
 * methods	__construct)phpDocumentor\Descriptor\MethodDescriptor" * arguments	   \PG\MSF\Base\Pool::__construct()":# $%Pool constructor.&' (&)	return	 param	 /	 0 getInstance;"2<	   \PG\MSF\Base\Pool::getInstance()"A# $%产生对象池单例&' (0)	?	 -phpDocumentor\Descriptor\Tag\ReturnDescriptor	 -""?&/	 @	 /	 0 get;"2<	$class+phpDocumentor\Descriptor\ArgumentDescriptor	 * method"W	 .phpDocumentor\Descriptor\Type\StringDescriptor   * byReference * isVariadic "F# $%&完全命名空间类名' ( )	 /	 0 $argsGH"W	 -"7 JK "M# $%&可变参数列表' ( )	 /	 0  \PG\MSF\Base\Pool::get()"E# $%获取一个&' (?)	@	 ,phpDocumentor\Descriptor\Tag\ParamDescriptor,F"["@&L/	 Q,M"c"@&N/	 ?	 D	 -"mixed"?&/	 /	 0 applyNewPool;"<		$poolNameGH"~	 I  JK "T# $%&对象池名称' ( )	 /	 0  !\PG\MSF\Base\Pool::applyNewPool()"S# $%-创建新的栈，用于储存相应的对象&' (b)	@	 Q,T""@&U/	 ?	 D	 -"R"?&/	 throws	 -phpDocumentor\Descriptor\Tag\ThrowsDescriptor	 -""X&/	 /	 0 push;"2<	$classInstanceGH"	 -"R JK "[# $%&对象实例' ( )	 /	 0  \PG\MSF\Base\Pool::push()"Z# $%返还一个对象&' (q)	@	 Q,[""@&\/	 ?	 /	 0  * usedTraits	  "Pool#\PG\MSF\Base$PG\MSF\Base%
Class Pool&'" ()	package	 &phpDocumentor\Descriptor\TagDescriptor"d&b/	 
subpackage	 /	 0  * interfaces	 	 * traits	 
 * markers	  "Pool.php# $Default%	对象池&' ( )	author	 -phpDocumentor\Descriptor\Tag\AuthorDescriptor"m&camera360_server@camera360.com/	 	copyright	 e"p&"Chengdu pinguo Technology Co.,Ltd./	 d	 e"d&k/	 f	 /	 0 