From 849493eea23b3f0504064125b9b31137f698afb7 Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Sun, 17 Jan 2021 09:39:18 +0800 Subject: [PATCH] =?UTF-8?q?add:=E6=96=B0=E5=A2=9E=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E8=BF=87=E6=BB=A4=E7=A9=BA=E5=80=BC=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- catch/monitor/command/ScheduleCommand.php | 1 + catch/monitor/command/process/Parser.php | 1 + catch/permissions/controller/User.php | 2 +- extend/catcher/Utils.php | 19 +++++ extend/catcher/base/CatchRequest.php | 20 ++++- .../phpExecutable/ExecutableFinder.php | 1 + .../phpExecutable/FindPhpExecutable.php | 84 +++++++++++++++++++ .../phpExecutable/PhpExecutableFinder.php | 1 + 8 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 catch/monitor/command/ScheduleCommand.php create mode 100644 catch/monitor/command/process/Parser.php create mode 100644 extend/catcher/library/phpExecutable/ExecutableFinder.php create mode 100644 extend/catcher/library/phpExecutable/FindPhpExecutable.php create mode 100644 extend/catcher/library/phpExecutable/PhpExecutableFinder.php diff --git a/catch/monitor/command/ScheduleCommand.php b/catch/monitor/command/ScheduleCommand.php new file mode 100644 index 0000000..b3d9bbc --- /dev/null +++ b/catch/monitor/command/ScheduleCommand.php @@ -0,0 +1 @@ +user->updateBy($id, $request->param()); + $this->user->updateBy($id, $request->filterEmptyField()->param()); $user = $this->user->findBy($id); diff --git a/extend/catcher/Utils.php b/extend/catcher/Utils.php index d92d673..7eb3fc4 100644 --- a/extend/catcher/Utils.php +++ b/extend/catcher/Utils.php @@ -210,4 +210,23 @@ class Utils { return root_path($path ? 'public/'. $path : 'public'); } + + + /** + * 过滤空字符字段 + * + * @time 2021年01月16日 + * @param $data + * @return mixed + */ + public static function filterEmptyValue($data) + { + foreach ($data as $k => $v) { + if (!$v) { + unset($data[$k]); + } + } + + return $data; + } } diff --git a/extend/catcher/base/CatchRequest.php b/extend/catcher/base/CatchRequest.php index 558e2ac..29ce9f0 100644 --- a/extend/catcher/base/CatchRequest.php +++ b/extend/catcher/base/CatchRequest.php @@ -6,7 +6,7 @@ namespace catcher\base; use app\Request; use catcher\exceptions\FailedException; use catcher\exceptions\ValidateFailedException; -use think\App; +use catcher\Utils; class CatchRequest extends Request { @@ -89,4 +89,22 @@ class CatchRequest extends Request return parent::post($name, $default, $filter); // TODO: Change the autogenerated stub } + /** + * 过滤空字段 + * + * @time 2021年01月16日 + * @return $this + */ + public function filterEmptyField(): CatchRequest + { + if ($this->isGet()) { + $this->get = Utils::filterEmptyValue($this->get); + } elseif ($this->isPost()) { + $this->post = Utils::filterEmptyValue($this->post); + } else { + $this->put = Utils::filterEmptyValue($this->put); + } + + return $this; + } } diff --git a/extend/catcher/library/phpExecutable/ExecutableFinder.php b/extend/catcher/library/phpExecutable/ExecutableFinder.php new file mode 100644 index 0000000..b3d9bbc --- /dev/null +++ b/extend/catcher/library/phpExecutable/ExecutableFinder.php @@ -0,0 +1 @@ + + * @author Johannes M. Schmitt + */ +class ExecutableFinder +{ + private $suffixes = ['.exe', '.bat', '.cmd', '.com']; + + /** + * Replaces default suffixes of executable. + */ + public function setSuffixes(array $suffixes) + { + $this->suffixes = $suffixes; + } + + /** + * Adds new possible suffix to check for executable. + * + * @param string $suffix + */ + public function addSuffix($suffix) + { + $this->suffixes[] = $suffix; + } + + /** + * Finds an executable by name. + * + * @param string $name The executable name (without the extension) + * @param string|null $default The default to return if no executable is found + * @param array $extraDirs Additional dirs to check into + * + * @return string|null The executable path or default value + */ + public function find($name, $default = null, array $extraDirs = []) + { + if (ini_get('open_basedir')) { + $searchPath = array_merge(explode(PATH_SEPARATOR, ini_get('open_basedir')), $extraDirs); + $dirs = []; + foreach ($searchPath as $path) { + // Silencing against https://bugs.php.net/69240 + if (@is_dir($path)) { + $dirs[] = $path; + } else { + if (basename($path) == $name && @is_executable($path)) { + return $path; + } + } + } + } else { + $dirs = array_merge( + explode(PATH_SEPARATOR, getenv('PATH') ?: getenv('Path')), + $extraDirs + ); + } + + $suffixes = ['']; + if ('\\' === \DIRECTORY_SEPARATOR) { + $pathExt = getenv('PATHEXT'); + $suffixes = array_merge($pathExt ? explode(PATH_SEPARATOR, $pathExt) : $this->suffixes, $suffixes); + } + foreach ($suffixes as $suffix) { + foreach ($dirs as $dir) { + if (@is_file($file = $dir.\DIRECTORY_SEPARATOR.$name.$suffix) && ('\\' === \DIRECTORY_SEPARATOR || @is_executable($file))) { + return $file; + } + } + } + + return $default; + } +} \ No newline at end of file diff --git a/extend/catcher/library/phpExecutable/PhpExecutableFinder.php b/extend/catcher/library/phpExecutable/PhpExecutableFinder.php new file mode 100644 index 0000000..b3d9bbc --- /dev/null +++ b/extend/catcher/library/phpExecutable/PhpExecutableFinder.php @@ -0,0 +1 @@ +