mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-01-11 17:28:04 +08:00
4cc2207513
Original unminified source code (dev folder - js, css, less) (fixes #6) Grunt build system Multiple identities correction (fixes #9) Compose html editor (fixes #12) New general settings - Loading Description New warning about default admin password Split general and login screen settings
116 lines
2.3 KiB
PHP
116 lines
2.3 KiB
PHP
<?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;
|
|
}
|
|
}
|
|
}
|