| 1 | <?php |
||
| 14 | class ScannerFactory{ |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var \OCA\Files_Antivirus\AppConfig |
||
| 18 | */ |
||
| 19 | protected $appConfig; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var ILogger; |
||
| 23 | */ |
||
| 24 | protected $logger; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var string |
||
| 28 | */ |
||
| 29 | protected $scannerClass; |
||
| 30 | |||
| 31 | 8 | public function __construct(AppConfig $appConfig, ILogger $logger){ |
|
| 32 | 8 | $this->appConfig = $appConfig; |
|
| 33 | 8 | $this->logger = $logger; |
|
| 34 | try { |
||
| 35 | 8 | $avMode = $appConfig->getAvMode(); |
|
| 36 | switch ($avMode) { |
||
| 37 | 8 | case 'daemon': |
|
| 38 | 4 | $this->scannerClass = 'OCA\Files_Antivirus\Scanner\Daemon'; |
|
| 39 | 4 | break; |
|
| 40 | 5 | case 'socket': |
|
| 41 | $this->scannerClass = 'OCA\Files_Antivirus\Scanner\Socket'; |
||
| 42 | break; |
||
| 43 | 5 | case 'executable': |
|
| 44 | 5 | $this->scannerClass = 'OCA\Files_Antivirus\Scanner\Local'; |
|
| 45 | 5 | break; |
|
| 46 | default: |
||
| 47 | throw new InitException( |
||
| 48 | sprintf( |
||
| 49 | 'Please check the settings at the admin page. Invalid mode: "%s"', |
||
| 50 | 8 | $avMode |
|
| 51 | ) |
||
| 52 | ); |
||
| 53 | } |
||
| 54 | } catch (InitException $e) { |
||
| 55 | // TODO: add a new config option to prevent upload on misconfiguration |
||
| 56 | // and check it here |
||
| 57 | $this->logger->warning( |
||
| 58 | sprintf( |
||
| 59 | 'Application is misconfigured. %s', |
||
| 60 | $e->getMessage() |
||
| 61 | ) |
||
| 62 | ); |
||
| 63 | } catch (\Exception $e) { |
||
| 64 | $message = implode(' ', [ __CLASS__, __METHOD__, $e->getMessage()]); |
||
| 65 | $this->logger->warning($message); |
||
| 66 | } |
||
| 67 | 8 | } |
|
| 68 | |||
| 69 | /** |
||
| 70 | * Produce a scanner instance |
||
| 71 | * @return \OCA\Files_Antivirus\Scanner\AbstractScanner |
||
| 72 | */ |
||
| 73 | 4 | public function getScanner(){ |
|
| 76 | } |
||
| 77 |