From 3b9821b4f63ccf9f1f938447e0a534dbae4b6636 Mon Sep 17 00:00:00 2001 From: Dmitry Yu Okunev Date: Fri, 7 Oct 2016 15:54:27 +0300 Subject: [PATCH] Getting config only one time (cache it) --- cas_authn/cas_authn.php | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/cas_authn/cas_authn.php b/cas_authn/cas_authn.php index 7161820..91d7dd6 100644 --- a/cas_authn/cas_authn.php +++ b/cas_authn/cas_authn.php @@ -22,6 +22,7 @@ class cas_authn extends rcube_plugin { private $cas_inited; + private $_cache_cfg = null; /** * Initialize plugin @@ -46,8 +47,20 @@ function init() { $this->add_hook('template_object_loginform', array($this, 'add_cas_login_html')); } + /** + * Gets config and caches + * + * @return array configuration array + */ + function getCfg() { + if (is_null($_cache_cfg)) { + $_cache_cfg = rcmail::get_instance()->config->all(); + } + return $_cache_cfg; + } + function isDisabled() { - $cfg = rcmail::get_instance()->config->all(); + $cfg = $this->getCfg(); if (is_array($cfg['cas_disable_for_domains'])) { foreach ($cfg['cas_disable_for_domains'] as $domain_pattern) { if (preg_match($domain_pattern, $_SERVER['SERVER_NAME'])) { @@ -122,7 +135,7 @@ function startup($args) { $user = phpCAS::getUser(); $pass = ''; // retrieve credentials, either a Proxy Ticket or 'masteruser' password - $cfg = rcmail::get_instance()->config->all(); + $cfg = $this->getCfg(); if ($cfg['cas_proxy']) { $_SESSION['cas_pt'][php_uname('n')] = phpCAS::retrievePT($cfg['cas_imap_name'], $err_code, $output); $pass = $_SESSION['cas_pt'][php_uname('n')]; @@ -175,7 +188,7 @@ function startup($args) { */ function imap_connect($args) { // retrieve configuration - $cfg = rcmail::get_instance()->config->all(); + $cfg = $this->getCfg(); // RoundCube is acting as CAS proxy if ($cfg['cas_proxy']) { @@ -237,7 +250,7 @@ function imap_connect($args) { */ function smtp_connect($args) { // retrieve configuration - $cfg = rcmail::get_instance()->config->all(); + $cfg = $this->getCfg(); // RoundCube is acting as CAS proxy and performing SMTP authn if ($cfg['cas_proxy'] && $args['smtp_user'] && $args['smtp_pass']) { @@ -267,7 +280,7 @@ function smtp_connect($args) { */ function sieverules_connect($args) { // retrieve configuration - $cfg = rcmail::get_instance()->config->all(); + $cfg = $this->getCfg(); // RoundCube is acting as CAS proxy if ($cfg['opt_cas_proxy']) { @@ -293,7 +306,7 @@ function add_cas_login_html($args) { $RCMAIL = rcmail::get_instance(); $this->add_texts('localization'); // retrieve configuration - $cfg = rcmail::get_instance()->config->all(); + $cfg = $this->getCfg(); // Force CAS authn? if($cfg["cas_force"]) { @@ -329,7 +342,7 @@ private function cas_init() { session_destroy(); } - $cfg = rcmail::get_instance()->config->all(); + $cfg = $this->getCfg(); // include phpCAS require_once('CAS.php'); @@ -420,7 +433,7 @@ private function generate_url($params) { $delm = '&'; } } - $cfg = rcmail::get_instance()->config->all(); + $cfg = $this->getCfg(); if ( $cfg['cas_webmail_server_name'] ) { $serverName = $cfg['cas_webmail_server_name']; } else {