mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Code refactoring
This commit is contained in:
parent
6acba46339
commit
819ba4a2ef
6 changed files with 94 additions and 47 deletions
|
|
@ -5,8 +5,13 @@ if (!\defined('RAINLOOP_APP_LIBRARIES_PATH'))
|
|||
\define('RAINLOOP_APP_LIBRARIES_PATH', \rtrim(\realpath(__DIR__), '\\/').'/libraries/');
|
||||
\define('RAINLOOP_MB_SUPPORTED', \function_exists('mb_strtoupper'));
|
||||
|
||||
\spl_autoload_register(function ($sClassName) {
|
||||
|
||||
/**
|
||||
* @param string $sClassName
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function RainLoopSplAutoloadRegisterFunction($sClassName)
|
||||
{
|
||||
if (0 === \strpos($sClassName, 'RainLoop') && false !== \strpos($sClassName, '\\'))
|
||||
{
|
||||
return include RAINLOOP_APP_LIBRARIES_PATH.'RainLoop/'.\str_replace('\\', '/', \substr($sClassName, 9)).'.php';
|
||||
|
|
@ -31,34 +36,36 @@ if (!\defined('RAINLOOP_APP_LIBRARIES_PATH'))
|
|||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
\spl_autoload_register('RainLoopSplAutoloadRegisterFunction', false);
|
||||
}
|
||||
|
||||
if (\class_exists('RainLoop\Service'))
|
||||
{
|
||||
$oException = null;
|
||||
if (!\class_exists('MailSo\Version'))
|
||||
{
|
||||
try
|
||||
{
|
||||
include APP_VERSION_ROOT_PATH.'app/libraries/MailSo/MailSo.php';
|
||||
}
|
||||
catch (\Exception $oException) {}
|
||||
include APP_VERSION_ROOT_PATH.'app/libraries/MailSo/MailSo.php';
|
||||
}
|
||||
|
||||
if (!$oException)
|
||||
if (\class_exists('MailSo\Version'))
|
||||
{
|
||||
if (isset($_ENV['RAINLOOP_INCLUDE_AS_API']) && $_ENV['RAINLOOP_INCLUDE_AS_API'])
|
||||
if (isset($_ENV['RAINLOOP_INCLUDE_AS_API']) && $_ENV['RAINLOOP_INCLUDE_AS_API'] && !\defined('APP_API_STARTED'))
|
||||
{
|
||||
$_ENV['RAINLOOP_INCLUDE_AS_API'] = false;
|
||||
\define('APP_API_STARTED', true);
|
||||
\RainLoop\Api::Handle();
|
||||
}
|
||||
else if (!\defined('APP_STARTED'))
|
||||
{
|
||||
\define('APP_STARTED', true);
|
||||
\RainLoop\Service::NewInstance()->Handle();
|
||||
\RainLoop\Api::Handle();
|
||||
\RainLoop\Service::Handle();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (\function_exists('RainLoopSplAutoloadRegisterFunction'))
|
||||
{
|
||||
\spl_autoload_unregister('RainLoopSplAutoloadRegisterFunction');
|
||||
}
|
||||
|
||||
return '';
|
||||
|
|
@ -7,10 +7,18 @@ if (!\defined('MAILSO_LIBRARY_ROOT_PATH'))
|
|||
\define('MAILSO_LIBRARY_ROOT_PATH', \defined('MAILSO_LIBRARY_USE_PHAR')
|
||||
? 'phar://mailso.phar/' : \rtrim(\realpath(__DIR__), '\\/').'/');
|
||||
|
||||
\spl_autoload_register(function ($sClassName) {
|
||||
/**
|
||||
* @param string $sClassName
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function MailSoSplAutoloadRegisterFunction($sClassName)
|
||||
{
|
||||
return (0 === \strpos($sClassName, 'MailSo') && false !== \strpos($sClassName, '\\')) ?
|
||||
include MAILSO_LIBRARY_ROOT_PATH.\str_replace('\\', '/', \substr($sClassName, 7)).'.php' : false;
|
||||
});
|
||||
}
|
||||
|
||||
\spl_autoload_register('MailSo\MailSoSplAutoloadRegisterFunction', false);
|
||||
|
||||
if (\class_exists('MailSo\Base\Loader'))
|
||||
{
|
||||
|
|
@ -18,6 +26,6 @@ if (!\defined('MAILSO_LIBRARY_ROOT_PATH'))
|
|||
}
|
||||
else
|
||||
{
|
||||
throw new \Exception('MailSo initialisation error');
|
||||
\spl_autoload_unregister('MailSo\MailSoSplAutoloadRegisterFunction');
|
||||
}
|
||||
}
|
||||
|
|
@ -10,6 +10,34 @@ class Api
|
|||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public static function RunResult()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @staticvar bool $bOne
|
||||
* @return bool
|
||||
*/
|
||||
public static function Handle()
|
||||
{
|
||||
static $bOne = null;
|
||||
if (null === $bOne)
|
||||
{
|
||||
$bOne = \class_exists('MailSo\Version');
|
||||
if ($bOne)
|
||||
{
|
||||
\RainLoop\Api::SetupDefaultMailSoConfig();
|
||||
$bOne = \RainLoop\Api::RunResult();
|
||||
}
|
||||
}
|
||||
|
||||
return $bOne;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \RainLoop\Actions
|
||||
|
|
@ -41,28 +69,6 @@ class Api
|
|||
return \RainLoop\Api::Actions()->Logger();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public static function Handle()
|
||||
{
|
||||
static $bOne = null;
|
||||
if ($bOne)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!\class_exists('MailSo\Version'))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
\RainLoop\Api::SetupDefaultMailSoConfig();
|
||||
|
||||
$bOne = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
|
@ -193,6 +199,6 @@ class Api
|
|||
public static function LogoutCurrentLogginedUser()
|
||||
{
|
||||
\RainLoop\Utils::ClearCookie('rlsession');
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,4 +18,11 @@ interface SettingsInterface
|
|||
* @return bool
|
||||
*/
|
||||
public function Save(\RainLoop\Account $oAccount, array $aSettings);
|
||||
|
||||
/**
|
||||
* @param string $sEmail
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function ClearByEmail($sEmail);
|
||||
}
|
||||
|
|
@ -35,8 +35,6 @@ class Service
|
|||
\ini_set('display_errors', 1);
|
||||
}
|
||||
|
||||
\RainLoop\Api::SetupDefaultMailSoConfig();
|
||||
|
||||
$sServer = \trim($this->oActions->Config()->Get('security', 'custom_server_signature', ''));
|
||||
if (0 < \strlen($sServer))
|
||||
{
|
||||
|
|
@ -54,20 +52,43 @@ class Service
|
|||
@\header('Location: https://'.$this->oHttp->GetHost(false, false).$this->oHttp->GetUrl(), true);
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->localHandle();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \RainLoop\Service
|
||||
* @return bool
|
||||
*/
|
||||
public static function NewInstance()
|
||||
public function RunResult()
|
||||
{
|
||||
return new self();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @staticvar bool $bOne
|
||||
* @return bool
|
||||
*/
|
||||
public static function Handle()
|
||||
{
|
||||
static $bOne = null;
|
||||
if (null === $bOne)
|
||||
{
|
||||
$oService = null;
|
||||
if (\class_exists('MailSo\Version'))
|
||||
{
|
||||
$oService = new self();
|
||||
}
|
||||
|
||||
$bOne = $oService->RunResult();
|
||||
}
|
||||
|
||||
return $bOne;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \RainLoop\Service
|
||||
*/
|
||||
public function Handle()
|
||||
private function localHandle()
|
||||
{
|
||||
if (!\class_exists('MailSo\Version'))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -941,8 +941,6 @@ class ServiceActions
|
|||
$sEmail = \trim($this->oHttp->GetRequest('Email', ''));
|
||||
$sPassword = $this->oHttp->GetRequest('Password', '');
|
||||
|
||||
\RainLoop\Api::Handle();
|
||||
|
||||
$sResult = \RainLoop\Api::GetUserSsoHash($sEmail, $sPassword);
|
||||
$bLogout = 0 === \strlen($sResult);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue