private function getBackendByClass($className) { $backends = $this->backendService->getBackends(); foreach ($backends as $backend) { if ($backend->getStorageClass() === $className) { return $backend; } } }
protected function execute(InputInterface $input, OutputInterface $output) { $authBackends = $this->backendService->getAuthMechanisms(); $storageBackends = $this->backendService->getBackends(); $data = ['authentication' => array_map([$this, 'serializeAuthBackend'], $authBackends), 'storage' => array_map([$this, 'serializeAuthBackend'], $storageBackends)]; $type = $input->getArgument('type'); $backend = $input->getArgument('backend'); if ($type) { if (!isset($data[$type])) { $output->writeln('<error>Invalid type "' . $type . '". Possible values are "authentication" or "storage"</error>'); return 1; } $data = $data[$type]; if ($backend) { if (!isset($data[$backend])) { $output->writeln('<error>Unknown backend "' . $backend . '" of type "' . $type . '"</error>'); return 1; } $data = $data[$backend]; } } $this->writeArrayInOutputFormat($input, $output, $data); }
public function testRegisterBackend() { $service = new BackendService($this->config, $this->l10n); $backend = $this->getBackendMock('\\Foo\\Bar'); $backendAlias = $this->getMockBuilder('\\OCA\\Files_External\\Lib\\Backend\\Backend')->disableOriginalConstructor()->getMock(); $backendAlias->method('getIdentifierAliases')->willReturn(['identifier_real', 'identifier_alias']); $backendAlias->method('getIdentifier')->willReturn('identifier_real'); $service->registerBackend($backend); $service->registerBackend($backendAlias); $this->assertEquals($backend, $service->getBackend('identifier:\\Foo\\Bar')); $this->assertEquals($backendAlias, $service->getBackend('identifier_real')); $this->assertEquals($backendAlias, $service->getBackend('identifier_alias')); $backends = $service->getBackends(); $this->assertCount(2, $backends); $this->assertArrayHasKey('identifier:\\Foo\\Bar', $backends); $this->assertArrayHasKey('identifier_real', $backends); $this->assertArrayNotHasKey('identifier_alias', $backends); }
public function testMultipleBackendProviders() { $service = new BackendService($this->config, $this->l10n); $backend1a = $this->getBackendMock('\\Foo\\Bar'); $backend1b = $this->getBackendMock('\\Bar\\Foo'); $backend2 = $this->getBackendMock('\\Dead\\Beef'); $provider1Mock = $this->getMock('\\OCA\\Files_External\\Lib\\Config\\IBackendProvider'); $provider1Mock->expects($this->once())->method('getBackends')->willReturn([$backend1a, $backend1b]); $service->registerBackendProvider($provider1Mock); $provider2Mock = $this->getMock('\\OCA\\Files_External\\Lib\\Config\\IBackendProvider'); $provider2Mock->expects($this->once())->method('getBackends')->willReturn([$backend2]); $service->registerBackendProvider($provider2Mock); $this->assertEquals($backend1a, $service->getBackend('identifier:\\Foo\\Bar')); $this->assertEquals($backend1b, $service->getBackend('identifier:\\Bar\\Foo')); $this->assertEquals($backend2, $service->getBackend('identifier:\\Dead\\Beef')); $this->assertCount(3, $service->getBackends()); }