From 7ace6df8b70db5fe5698656f6408416ee8fd9159 Mon Sep 17 00:00:00 2001 From: Paul Robert Date: Sat, 5 Mar 2022 00:41:29 +0100 Subject: [PATCH] Added clean file directive. --- Chase/Helga/Executioner.php | 9 +++++++++ docs/rules.md | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/Chase/Helga/Executioner.php b/Chase/Helga/Executioner.php index 4930b55..87f744f 100644 --- a/Chase/Helga/Executioner.php +++ b/Chase/Helga/Executioner.php @@ -315,6 +315,15 @@ public static function fileImage($target, $key = null) }, $key); } + public static function file($target, $key = null) + { + return self::exec(function () use ($target) { + return (!rawContainsCode($target)); + }, function ($r) use ($key) { + $r->message = sprintf("%s must not contain php code.", ucwords($key ?? 'File')); + }, $key); + } + public static function filePdf($target, $key = null) { return self::exec(function () use ($target) { diff --git a/docs/rules.md b/docs/rules.md index 2a8dc01..9d78e6e 100644 --- a/docs/rules.md +++ b/docs/rules.md @@ -255,6 +255,13 @@ $path = '/files/image.png'; $v = validate($path)->withRules(['fileImage']); ``` +`file` +Ensures the file at the path passed does not contain any php code. +```php +$path = '/files/pdf.pdf'; +$v = validate($path)->withRules(['file']); +``` + `filePdf` The path passed must point to a valid pdf file. ```php