getPropertiesValues( [ DataStore::PROPERTY_OAUTH_KEY, DataStore::PROPERTY_OAUTH_SECRET, DataStore::PROPERTY_OAUTH_CALLBACK, RdfLtiProviderRepository::LTI_VERSION, RdfLtiProviderRepository::LTI_TOOL_IDENTIFIER, RdfLtiProviderRepository::LTI_TOOL_NAME, RdfLtiProviderRepository::LTI_TOOL_CLIENT_ID, RdfLtiProviderRepository::LTI_TOOL_DEPLOYMENT_IDS, RdfLtiProviderRepository::LTI_TOOL_AUDIENCE, RdfLtiProviderRepository::LTI_TOOL_LAUNCH_URL, RdfLtiProviderRepository::LTI_TOOL_OIDC_LOGIN_INITATION_URL, RdfLtiProviderRepository::LTI_TOOL_JWKS_URL, RdfLtiProviderRepository::LTI_TOOL_PUBLIC_KEY, ] ); return new LtiProvider( $resource->getUri(), $resource->getLabel(), (string)reset($propertiesValues[DataStore::PROPERTY_OAUTH_KEY]), (string)reset($propertiesValues[DataStore::PROPERTY_OAUTH_SECRET]), (string)reset($propertiesValues[DataStore::PROPERTY_OAUTH_CALLBACK]), [], $this->getLtiVersion($propertiesValues), (string)reset($propertiesValues[RdfLtiProviderRepository::LTI_TOOL_IDENTIFIER]), (string)reset($propertiesValues[RdfLtiProviderRepository::LTI_TOOL_NAME]), (string)reset($propertiesValues[RdfLtiProviderRepository::LTI_TOOL_CLIENT_ID]), $this->getDeploymentIds($propertiesValues), (string)reset($propertiesValues[RdfLtiProviderRepository::LTI_TOOL_AUDIENCE]), (string)reset($propertiesValues[RdfLtiProviderRepository::LTI_TOOL_OIDC_LOGIN_INITATION_URL]), (string)reset($propertiesValues[RdfLtiProviderRepository::LTI_TOOL_LAUNCH_URL]), (string)reset($propertiesValues[RdfLtiProviderRepository::LTI_TOOL_PUBLIC_KEY]), (string)reset($propertiesValues[RdfLtiProviderRepository::LTI_TOOL_JWKS_URL]) ); } public function createFromArray(array $provider): LtiProvider { $ltiVersion = $provider[ConfigurableLtiProviderRepository::LTI_VERSION] ?? '1.1'; $this->getValidationService()->validateArray($ltiVersion, $provider); return new LtiProvider( $provider['uri'], $provider['label'], $provider['key'], $provider['secret'], $provider['callback_url'], $provider['roles'] ?? [], $ltiVersion, $provider[ConfigurableLtiProviderRepository::LTI_TOOL_IDENTIFIER] ?? null, $provider[ConfigurableLtiProviderRepository::LTI_TOOL_NAME] ?? null, $provider[ConfigurableLtiProviderRepository::LTI_TOOL_CLIENT_ID] ?? null, $provider[ConfigurableLtiProviderRepository::LTI_TOOL_DEPLOYMENT_IDS] ?? [], $provider[ConfigurableLtiProviderRepository::LTI_TOOL_AUDIENCE] ?? null, $provider[ConfigurableLtiProviderRepository::LTI_TOOL_OIDC_LOGIN_INITATION_URL] ?? null, $provider[ConfigurableLtiProviderRepository::LTI_TOOL_LAUNCH_URL] ?? null, $provider[ConfigurableLtiProviderRepository::LTI_TOOL_PUBLIC_KEY] ?? null, $provider[ConfigurableLtiProviderRepository::LTI_TOOL_JWKS_URL] ?? null ); } private function getLtiVersion(array $propertiesValues): string { $ltiVersionResource = reset($propertiesValues[RdfLtiProviderRepository::LTI_VERSION]); if ($ltiVersionResource instanceof core_kernel_classes_Literal && !empty(trim($ltiVersionResource->literal))) { return $ltiVersionResource->literal === RdfLtiProviderRepository::LTI_V_13 ? '1.3' : '1.1'; } if (!$ltiVersionResource || !$ltiVersionResource instanceof core_kernel_classes_Resource) { return '1.1'; } $version = (string) $ltiVersionResource->getUri(); return $version === RdfLtiProviderRepository::LTI_V_13 ? '1.3' : '1.1'; } private function getDeploymentIds(array $propertiesValues): array { return array_filter( explode( ',', (string)reset($propertiesValues[RdfLtiProviderRepository::LTI_TOOL_DEPLOYMENT_IDS]) ) ); } private function getValidationService(): LtiProviderValidator { /** @noinspection PhpIncompatibleReturnTypeInspection */ return $this->getServiceLocator()->get(LtiProviderValidator::class); } }