for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2024 Christoph Wurst <[email protected]>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\TwoFactorGateway\Provider\Channel\SMS;
use OCA\TwoFactorGateway\Exception\InvalidProviderException;
use OCA\TwoFactorGateway\Provider\AFactory;
use OCA\TwoFactorGateway\Provider\Channel\SMS\Provider\IProvider;
class Factory extends AFactory {
/** @var array<string,IProvider> */
protected array $instances = [];
#[\Override]
protected function getPrefix(): string {
return 'OCA\\TwoFactorGateway\\Provider\\Channel\\SMS\\Provider\\Drivers\\';
}
protected function getSuffix(): string {
return '';
protected function getBaseClass(): string {
return IProvider::class;
public function isValid(string $fqcn): bool {
return defined("$fqcn::SCHEMA")
&& is_array($fqcn::SCHEMA);
public function get(string $name): IProvider {
if (isset($this->instances[$name])) {
return $this->instances[$name];
foreach ($this->getFqcnList() as $fqcn) {
if ($fqcn::getProviderId() === $name) {
$instance = \OCP\Server::get($fqcn);
$instance->setAppConfig(\OCP\Server::get(\OCP\IAppConfig::class));
$this->instances[$name] = $instance;
return $instance;
throw new InvalidProviderException("Provider <$name> does not exist");