From 1b8d2102820124978b335f155560847133efa8a3 Mon Sep 17 00:00:00 2001 From: David Callizaya Date: Thu, 17 Aug 2017 17:19:43 -0400 Subject: [PATCH] HOR-3700 Implement factory for adapters used for dashlets and ldap. --- gulliver/system/class.g.php | 113 ++++-------------- .../methods/authSources/ldapAdvancedProxy.php | 2 +- .../engine/src/ProcessMaker/Util/helpers.php | 89 ++++++++++++++ 3 files changed, 116 insertions(+), 88 deletions(-) diff --git a/gulliver/system/class.g.php b/gulliver/system/class.g.php index cc6a5c8f9..08aa85354 100644 --- a/gulliver/system/class.g.php +++ b/gulliver/system/class.g.php @@ -46,6 +46,20 @@ class G public static $pathDataPublic; public static $httpHost; + /** + * Adapters used for different services inside Processmaker. + * + * @var string[] $adapters + */ + private static $adapters = [ + 'ldap' => LDAP::class, + 'ldapadvanced' => LdapAdvanced::class, + 'dashletopenvscompleted' => DashletOpenVsCompleted::class, + 'dashletrssreader' => DashletRssReader::class, + 'dashletprocesspakerenterprise' => DashletProcessMakerEnterprise::class, + 'dashletprocessmakercommunity' => DashletProcessMakerCommunity::class, + ]; + /** * @deprecated 3.2.2, We keep this function only for backwards compatibility because is used in the plugin manager */ @@ -5865,93 +5879,18 @@ class G define('PM_SCHEDULER_CREATE_CASE_BEFORE', 1019); define('PM_SCHEDULER_CREATE_CASE_AFTER', 1020); } -} -/** - * eprint - * - * @param string $s default value '' - * @param string $c default value null - * - * @return void - */ -function eprint ($s = "", $c = null) -{ - if (G::isHttpRequest()) { - if (isset( $c )) { - echo "
$s
"; - } else { - echo "
$s
"; - } - } else { - if (isset( $c )) { - switch ($c) { - case 'green': - printf( "\033[0;35;32m$s\033[0m" ); - return; - break; - case 'red': - printf( "\033[0;35;31m$s\033[0m" ); - return; - break; - case 'blue': - printf( "\033[0;35;34m$s\033[0m" ); - return; - break; - default: - print "$s"; - } - } else { - print "$s"; - } - } -} - -/** - * println - * - * @param string $s - * - * @return eprintln($s) - */ -function println ($s) -{ - return eprintln( $s ); -} - -/** - * eprintln - * - * @param string $s - * @param string $c - * - * @return void - */ -function eprintln ($s = "", $c = null) -{ - if (G::isHttpRequest()) { - if (isset( $c )) { - echo "
$s
"; - } else { - echo "
$s
"; - } - } else { - if (isset( $c ) && (PHP_OS != 'WINNT')) { - switch ($c) { - case 'green': - printf( "\033[0;35;32m$s\033[0m\n" ); - return; - break; - case 'red': - printf( "\033[0;35;31m$s\033[0m\n" ); - return; - break; - case 'blue': - printf( "\033[0;35;34m$s\033[0m\n" ); - return; - break; - } - } - print "$s\n"; + /** + * Instanciate an adapter by name. + * + * @param string $name Adapter name or class name + * @param string[] $parameters Constructor parameters + */ + public static function factory($name, ...$parameters) + { + $key = strtolower($name); + $class = isset(self::$adapters[$key]) ? self::$adapters[$key] : $name; + $rc = new ReflectionClass($class); + return $rc->newInstanceArgs($parameters); } } diff --git a/workflow/engine/methods/authSources/ldapAdvancedProxy.php b/workflow/engine/methods/authSources/ldapAdvancedProxy.php index 2800c8825..16d081334 100644 --- a/workflow/engine/methods/authSources/ldapAdvancedProxy.php +++ b/workflow/engine/methods/authSources/ldapAdvancedProxy.php @@ -318,7 +318,7 @@ switch ($function) { $sClassName = strtolower($aFields['AUTH_SOURCE_PROVIDER']); - $plugin = new $sClassName(); + $plugin = G::factory($sClassName); $aAuthSource = $RBAC->authSourcesObj->load($authSourceUid); diff --git a/workflow/engine/src/ProcessMaker/Util/helpers.php b/workflow/engine/src/ProcessMaker/Util/helpers.php index 0bc3340b3..828ef8e8d 100644 --- a/workflow/engine/src/ProcessMaker/Util/helpers.php +++ b/workflow/engine/src/ProcessMaker/Util/helpers.php @@ -272,3 +272,92 @@ function getVarsGrid($proUid, $dynUid) } return $dynaformFieldTypes; } + +/** + * eprint + * + * @param string $s default value '' + * @param string $c default value null + * + * @return void + */ +function eprint ($s = "", $c = null) +{ + if (G::isHttpRequest()) { + if (isset( $c )) { + echo "
$s
"; + } else { + echo "
$s
"; + } + } else { + if (isset( $c )) { + switch ($c) { + case 'green': + printf( "\033[0;35;32m$s\033[0m" ); + return; + break; + case 'red': + printf( "\033[0;35;31m$s\033[0m" ); + return; + break; + case 'blue': + printf( "\033[0;35;34m$s\033[0m" ); + return; + break; + default: + print "$s"; + } + } else { + print "$s"; + } + } +} + +/** + * println + * + * @param string $s + * + * @return eprintln($s) + */ +function println ($s) +{ + return eprintln( $s ); +} + +/** + * eprintln + * + * @param string $s + * @param string $c + * + * @return void + */ +function eprintln ($s = "", $c = null) +{ + if (G::isHttpRequest()) { + if (isset( $c )) { + echo "
$s
"; + } else { + echo "
$s
"; + } + } else { + if (isset( $c ) && (PHP_OS != 'WINNT')) { + switch ($c) { + case 'green': + printf( "\033[0;35;32m$s\033[0m\n" ); + return; + break; + case 'red': + printf( "\033[0;35;31m$s\033[0m\n" ); + return; + break; + case 'blue': + printf( "\033[0;35;34m$s\033[0m\n" ); + return; + break; + } + } + print "$s\n"; + } +}