mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-31 21:19:21 +03:00
v1.2.7.416
This commit is contained in:
parent
54e2645fcf
commit
3b27abbe9a
434 changed files with 51 additions and 72 deletions
|
|
@ -1,116 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace MailSo\Base;
|
||||
|
||||
/**
|
||||
* @category MailSo
|
||||
* @package Base
|
||||
*/
|
||||
class ResourceRegistry
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public static $Resources = array();
|
||||
|
||||
/**
|
||||
* @access private
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @staticvar bool $bInited
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private static function regResourcesShutdownFunc()
|
||||
{
|
||||
static $bInited = false;
|
||||
if (!$bInited)
|
||||
{
|
||||
$bInited = true;
|
||||
\register_shutdown_function(function () {
|
||||
if (\is_array(\MailSo\Base\ResourceRegistry::$Resources))
|
||||
{
|
||||
foreach (\array_keys(\MailSo\Base\ResourceRegistry::$Resources) as $sKey)
|
||||
{
|
||||
if (\is_resource(\MailSo\Base\ResourceRegistry::$Resources[$sKey]))
|
||||
{
|
||||
\MailSo\Base\Loader::IncStatistic('CloseMemoryResource');
|
||||
\fclose(\MailSo\Base\ResourceRegistry::$Resources[$sKey]);
|
||||
}
|
||||
\MailSo\Base\ResourceRegistry::$Resources[$sKey] = null;
|
||||
}
|
||||
}
|
||||
|
||||
\MailSo\Base\ResourceRegistry::$Resources = array();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $iMemoryMaxInMb = 5
|
||||
*
|
||||
* @return resource | bool
|
||||
*/
|
||||
public static function CreateMemoryResource($iMemoryMaxInMb = 5)
|
||||
{
|
||||
self::regResourcesShutdownFunc();
|
||||
|
||||
$oResult = @\fopen('php://temp/maxmemory:'.($iMemoryMaxInMb * 1024 * 1024), 'r+b');
|
||||
if (\is_resource($oResult))
|
||||
{
|
||||
\MailSo\Base\Loader::IncStatistic('CreateMemoryResource');
|
||||
\MailSo\Base\ResourceRegistry::$Resources[(string) $oResult] = $oResult;
|
||||
return $oResult;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sString
|
||||
*
|
||||
* @return resource | bool
|
||||
*/
|
||||
public static function CreateMemoryResourceFromString($sString)
|
||||
{
|
||||
$oResult = self::CreateMemoryResource();
|
||||
if (\is_resource($oResult))
|
||||
{
|
||||
\fwrite($oResult, $sString);
|
||||
\rewind($oResult);
|
||||
}
|
||||
|
||||
return $oResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $rResource
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function CloseMemoryResource(&$rResource)
|
||||
{
|
||||
if (\is_resource($rResource))
|
||||
{
|
||||
$sKey = (string) $rResource;
|
||||
if (isset(\MailSo\Base\ResourceRegistry::$Resources[$sKey]))
|
||||
{
|
||||
\fclose(\MailSo\Base\ResourceRegistry::$Resources[$sKey]);
|
||||
\MailSo\Base\ResourceRegistry::$Resources[$sKey] = null;
|
||||
unset(\MailSo\Base\ResourceRegistry::$Resources[$sKey]);
|
||||
\MailSo\Base\Loader::IncStatistic('CloseMemoryResource');
|
||||
}
|
||||
|
||||
if (\is_resource($rResource))
|
||||
{
|
||||
\fclose($rResource);
|
||||
}
|
||||
|
||||
$rResource = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue