Extend SDKLoader to support non-OO SDKs, starting with Sentry
This commit is contained in:
@@ -27,20 +27,47 @@ class SDKLoader {
|
|||||||
$this->reader = new NodeReader;
|
$this->reader = new NodeReader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the SDK with the given name and options; used for
|
||||||
|
* SDKs that are initialized with a function and not a class name.
|
||||||
|
*
|
||||||
|
* @param string $sdkName The name of the SDK to initialize.
|
||||||
|
* @param array $options Additional options for the SDK (if necessary).
|
||||||
|
* @return mixed The return value of the SDK initialization, which may vary depending on the SDK.
|
||||||
|
* @throws Exception If the SDK is not supported or cannot be initialized.
|
||||||
|
*/
|
||||||
|
public function init(string $sdkName, array $options = []) : mixed {
|
||||||
|
$namespace = $this->objectRetriever->getAuthenticatingNamespaceCloudObject();
|
||||||
|
|
||||||
|
switch (strtolower($sdkName)) {
|
||||||
|
case "sentry":
|
||||||
|
// --- Sentry (https://sentry.io/) ---
|
||||||
|
$initFunction = '\Sentry\init';
|
||||||
|
return $initFunction(array_merge([
|
||||||
|
'dsn' => $namespace->getString('coid://sentry.io.3rd-party.co/DSN')
|
||||||
|
], $options));
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new Exception("No rules defined to initialize SDK with name <".$sdkName.">.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize and return the SDK with the given classname.
|
* Initialize and return the SDK with the given classname.
|
||||||
* Throws Exception if the SDK is not supported.
|
* Throws Exception if the SDK is not supported.
|
||||||
*
|
*
|
||||||
* @param $classname Classname for the SDK's main class
|
* @param string $classname Classname for the SDK's main class.
|
||||||
* @param array $options Additional options for the SDK (if necessary)
|
* @param array $options Additional options for the SDK (if necessary).
|
||||||
|
* @return mixed The initialized SDK instance.
|
||||||
|
* @throws Exception If the SDK is not supported or cannot be initialized.
|
||||||
*/
|
*/
|
||||||
public function get($classname, array $options) {
|
public function get(string $classname, array $options) : mixed {
|
||||||
if (!class_exists($classname))
|
if (!class_exists($classname))
|
||||||
throw new Exception("<".$classname."> is not a valid classname.");
|
throw new Exception("<".$classname."> is not a valid classname.");
|
||||||
|
|
||||||
$hashkey = md5($classname.serialize($options));
|
$hashkey = md5($classname.serialize($options));
|
||||||
if (!isset($this->classes[$hashkey])) {
|
if (!isset($this->classes[$hashkey])) {
|
||||||
$nsNode = $this->objectRetriever->getAuthenticatingNamespaceObject();
|
$nsNode = $this->objectRetriever->getAuthenticatingNamespaceObjectNode();
|
||||||
|
|
||||||
// --- Amazon Web Services (https://aws.amazon.com/) ---
|
// --- Amazon Web Services (https://aws.amazon.com/) ---
|
||||||
// has multiple classnames, so check for common superclass
|
// has multiple classnames, so check for common superclass
|
||||||
|
|||||||
Reference in New Issue
Block a user