composer require cleentfaar/tissue-bundle
config/bundles.php:
return [
// ...
Cleentfaar\TissueBundle\CLTissueBundle::class => ['all' => true],
];
config/packages/cl_tissue.yaml:
cl_tissue:
adapter: cl_tissue.adapter.clamav
clamav:
binary: '/usr/bin/clamscan' # Adjust path to your ClamAV binary
CleanFile constraint to your entity:
use Cleentfaar\TissueBundle\Validator\Constraints as TissueAssert;
/**
* @TissueAssert\CleanFile()
*/
private $file;
File type in forms to trigger validation.use Symfony\Component\Form\Extension\Core\Type\FileType;
$builder->add('file', FileType::class, [
'constraints' => [new \Cleentfaar\TissueBundle\Validator\Constraints\CleanFile()]
]);
TissueException in your controller to customize error messages:
try {
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// Process file
}
} catch (\Cleentfaar\TissueBundle\Exception\TissueException $e) {
$this->addFlash('error', 'File contains malware: ' . $e->getMessage());
return $this->redirectToRoute('upload');
}
cl_tissue.scanner) and scan files in bulk:
use Cleentfaar\TissueBundle\Scanner\ScannerInterface;
public function __construct(private ScannerInterface $scanner) {}
public function processFiles(array $filePaths): void {
foreach ($filePaths as $path) {
if (!$this->scanner->scan($path)) {
throw new \RuntimeException("Malware detected in $path");
}
}
}
Cleentfaar\TissueBundle\Adapter\AdapterInterface for non-ClamAV engines (e.g., Sophos).services:
app.tissue.adapter.sophos:
class: App\Adapter\SophosAdapter
tags: ['cl_tissue.adapter']
CleanFile constraint for custom logic (e.g., whitelist file types):
use Cleentfaar\TissueBundle\Validator\Constraints\CleanFile as BaseCleanFile;
class CustomCleanFile extends BaseCleanFile {
public function validatedBy() { return static::class; }
public function getTargets() { return [self::PROPERTY_CONSTRAINT]; }
}
ClamAV Binary Path:
/usr/bin/clamscan. On Windows or custom installations, update config/packages/cl_tissue.yaml:
cl_tissue:
clamav:
binary: 'C:\Program Files\ClamAV\bin\clamscan.exe'
shell_exec('which clamscan') (Linux/macOS) or check the Windows PATH.Permission Issues:
www-data) has permissions:
chmod -R 755 /path/to/uploaded/files
Outdated Dependencies:
symfony/validator, symfony/dependency-injection).False Positives:
clamav.conf or pre-filter files:
// Whitelist specific extensions
$scanner->setAllowedExtensions(['pdf', 'jpg']);
Enable Verbose Logging:
Add to config/packages/monolog.yaml:
handlers:
cl_tissue:
type: stream
path: "%kernel.logs_dir%/tissue.log"
level: debug
channels: ["cl_tissue"]
Then log scanner events in your adapter:
$this->logger->debug('Scanning file: ' . $filePath);
Manual ClamAV Test: Validate your setup with:
clamscan -r /path/to/test/files
Custom Scanner Configuration: Override the scanner service to add pre/post-scan hooks:
services:
app.tissue.scanner:
class: App\Scanner\CustomScanner
decorates: cl_tissue.scanner
arguments: ['@app.tissue.scanner.inner']
class CustomScanner implements ScannerInterface {
public function scan($filePath) {
// Pre-scan logic (e.g., size check)
$result = $this->scanner->scan($filePath);
// Post-scan logic (e.g., quarantine)
return $result;
}
}
Async Scanning: Use Symfony Messenger to offload scans:
use Cleentfaar\TissueBundle\Message\ScanFileMessage;
$bus->dispatch(new ScanFileMessage($filePath));
Configure the transport in config/packages/messenger.yaml.
GUI Feedback:
Extend the bundle’s Twig templates (Resources/views/) to show scan progress or results to users.
How can I help you explore Laravel packages today?