<?php
 class vB_Library_Filescan extends vB_Library { protected $enabled_instances = null; protected $initErrors = []; protected function __construct() { $this->initializeInstances(); } private function initializeInstances() { if (!is_null($this->enabled_instances)) { return; } $this->enabled_instances = []; $options = vB::getDatastore()->getValue('options'); if (!empty($options['enabled_scanner'])) { $options['enabled_scanner'] = json_decode($options['enabled_scanner'], true); if (!is_array($options['enabled_scanner'])) { $options['enabled_scanner'] = []; } $this->enabled_instances = $this->doInitInstances($options['enabled_scanner']); } } private function doInitInstances($scanners) { $enabled_instances = []; $this->initErrors = []; $vboptions = vB::getDatastore()->getValue('options'); foreach ($scanners AS $tag => $enabled) { if ($enabled) { $tag = strtolower($tag); try { $class = vB::getVbClassNameFromTag($tag, 'Utility_Filescanner', 'vB_Utility_Filescanner'); $instance = new $class($vboptions); if ($instance->isEnabled()) { $enabled_instances[$tag] = $instance; } $errors = $instance->fetchErrors(); if (!empty($errors)) { $this->initErrors = array_merge($this->initErrors, $errors); } } catch(Throwable $e) { $this->initErrors[] = $e->getMessage(); } } } return $enabled_instances; } public function validateEnabledScanners($scanners) { $this->doInitInstances($scanners); return $this->initErrors; } public function scanFile($filename) { $filename = realpath($filename); foreach ($this->enabled_instances AS $scanner) { if (!$scanner->scanFile($filename)) { return false; } } return true; } } 