update:优化代码
This commit is contained in:
parent
ddf521b62b
commit
c190672603
@ -23,7 +23,7 @@ class FileSystem
|
|||||||
* @param string $path
|
* @param string $path
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function exists($path)
|
public function exists(string $path): bool
|
||||||
{
|
{
|
||||||
return file_exists($path);
|
return file_exists($path);
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ class FileSystem
|
|||||||
* @param bool $lock
|
* @param bool $lock
|
||||||
* @return string
|
* @return string
|
||||||
**/
|
**/
|
||||||
public function get($path, $lock = false)
|
public function get(string $path, $lock = false): string
|
||||||
{
|
{
|
||||||
if ($this->isFile($path)) {
|
if ($this->isFile($path)) {
|
||||||
return $lock ? $this->sharedGet($path) : file_get_contents($path);
|
return $lock ? $this->sharedGet($path) : file_get_contents($path);
|
||||||
@ -50,7 +50,7 @@ class FileSystem
|
|||||||
* @param string $path
|
* @param string $path
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function sharedGet($path)
|
public function sharedGet(string $path): string
|
||||||
{
|
{
|
||||||
$contents = '';
|
$contents = '';
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ class FileSystem
|
|||||||
*
|
*
|
||||||
* @throws FiledNotFoundException
|
* @throws FiledNotFoundException
|
||||||
*/
|
*/
|
||||||
public function getRequire($path)
|
public function getRequire(string $path)
|
||||||
{
|
{
|
||||||
if ($this->isFile($path)) {
|
if ($this->isFile($path)) {
|
||||||
return require $path;
|
return require $path;
|
||||||
@ -96,7 +96,7 @@ class FileSystem
|
|||||||
* @param string $file
|
* @param string $file
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function requireOnce($file)
|
public function requireOnce(string $file)
|
||||||
{
|
{
|
||||||
require_once $file;
|
require_once $file;
|
||||||
}
|
}
|
||||||
@ -107,7 +107,7 @@ class FileSystem
|
|||||||
* @param string $path
|
* @param string $path
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function hash($path)
|
public function hash(string $path): string
|
||||||
{
|
{
|
||||||
return md5_file($path);
|
return md5_file($path);
|
||||||
}
|
}
|
||||||
@ -120,7 +120,7 @@ class FileSystem
|
|||||||
* @param bool $lock
|
* @param bool $lock
|
||||||
* @return int|bool
|
* @return int|bool
|
||||||
*/
|
*/
|
||||||
public function put($path, $contents, $lock = false)
|
public function put(string $path, string $contents, $lock = false)
|
||||||
{
|
{
|
||||||
return file_put_contents($path, $contents, $lock ? LOCK_EX : 0);
|
return file_put_contents($path, $contents, $lock ? LOCK_EX : 0);
|
||||||
}
|
}
|
||||||
@ -132,7 +132,7 @@ class FileSystem
|
|||||||
* @param string $content
|
* @param string $content
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function replace($path, $content)
|
public function replace(string $path, string $content)
|
||||||
{
|
{
|
||||||
|
|
||||||
clearstatcache(true, $path);
|
clearstatcache(true, $path);
|
||||||
@ -155,7 +155,7 @@ class FileSystem
|
|||||||
* @param string $data
|
* @param string $data
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function prepend($path, $data)
|
public function prepend(string $path, string $data)
|
||||||
{
|
{
|
||||||
if ($this->exists($path)) {
|
if ($this->exists($path)) {
|
||||||
return $this->put($path, $data.$this->get($path));
|
return $this->put($path, $data.$this->get($path));
|
||||||
@ -171,7 +171,7 @@ class FileSystem
|
|||||||
* @param string $data
|
* @param string $data
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function append($path, $data)
|
public function append(string $path, string $data): int
|
||||||
{
|
{
|
||||||
return file_put_contents($path, $data, FILE_APPEND);
|
return file_put_contents($path, $data, FILE_APPEND);
|
||||||
}
|
}
|
||||||
@ -183,7 +183,7 @@ class FileSystem
|
|||||||
* @param int|null $mode
|
* @param int|null $mode
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function chmod($path, $mode = null)
|
public function chmod(string $path, $mode = null)
|
||||||
{
|
{
|
||||||
if ($mode) {
|
if ($mode) {
|
||||||
return chmod($path, $mode);
|
return chmod($path, $mode);
|
||||||
@ -198,7 +198,7 @@ class FileSystem
|
|||||||
* @param string|array $paths
|
* @param string|array $paths
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function delete($paths)
|
public function delete($paths): bool
|
||||||
{
|
{
|
||||||
$paths = is_array($paths) ? $paths : func_get_args();
|
$paths = is_array($paths) ? $paths : func_get_args();
|
||||||
|
|
||||||
@ -224,7 +224,7 @@ class FileSystem
|
|||||||
* @param string $target
|
* @param string $target
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function move($path, $target)
|
public function move(string $path, string $target): bool
|
||||||
{
|
{
|
||||||
return rename($path, $target);
|
return rename($path, $target);
|
||||||
}
|
}
|
||||||
@ -236,7 +236,7 @@ class FileSystem
|
|||||||
* @param string $target
|
* @param string $target
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function copy($path, $target)
|
public function copy(string $path, string $target): bool
|
||||||
{
|
{
|
||||||
return copy($path, $target);
|
return copy($path, $target);
|
||||||
}
|
}
|
||||||
@ -248,7 +248,7 @@ class FileSystem
|
|||||||
* @param string $link
|
* @param string $link
|
||||||
* @return void|mixed
|
* @return void|mixed
|
||||||
*/
|
*/
|
||||||
public function link($target, $link)
|
public function link(string $target, string $link)
|
||||||
{
|
{
|
||||||
$isWin = strtolower(substr(PHP_OS, 0, 3)) === 'win';
|
$isWin = strtolower(substr(PHP_OS, 0, 3)) === 'win';
|
||||||
if (! $isWin) {
|
if (! $isWin) {
|
||||||
@ -266,7 +266,7 @@ class FileSystem
|
|||||||
* @param string $path
|
* @param string $path
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function name($path)
|
public function name(string $path): string
|
||||||
{
|
{
|
||||||
return pathinfo($path, PATHINFO_FILENAME);
|
return pathinfo($path, PATHINFO_FILENAME);
|
||||||
}
|
}
|
||||||
@ -277,7 +277,7 @@ class FileSystem
|
|||||||
* @param string $path
|
* @param string $path
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function basename($path)
|
public function basename(string $path): string
|
||||||
{
|
{
|
||||||
return pathinfo($path, PATHINFO_BASENAME);
|
return pathinfo($path, PATHINFO_BASENAME);
|
||||||
}
|
}
|
||||||
@ -288,7 +288,7 @@ class FileSystem
|
|||||||
* @param string $path
|
* @param string $path
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function dirname($path)
|
public function dirname(string $path): string
|
||||||
{
|
{
|
||||||
return pathinfo($path, PATHINFO_DIRNAME);
|
return pathinfo($path, PATHINFO_DIRNAME);
|
||||||
}
|
}
|
||||||
@ -299,7 +299,7 @@ class FileSystem
|
|||||||
* @param string $path
|
* @param string $path
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function extension($path)
|
public function extension(string $path): string
|
||||||
{
|
{
|
||||||
return pathinfo($path, PATHINFO_EXTENSION);
|
return pathinfo($path, PATHINFO_EXTENSION);
|
||||||
}
|
}
|
||||||
@ -310,7 +310,7 @@ class FileSystem
|
|||||||
* @param string $path
|
* @param string $path
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function type($path)
|
public function type(string $path): string
|
||||||
{
|
{
|
||||||
return filetype($path);
|
return filetype($path);
|
||||||
}
|
}
|
||||||
@ -321,7 +321,7 @@ class FileSystem
|
|||||||
* @param string $path
|
* @param string $path
|
||||||
* @return string|false
|
* @return string|false
|
||||||
*/
|
*/
|
||||||
public function mimeType($path)
|
public function mimeType(string $path)
|
||||||
{
|
{
|
||||||
return finfo_file(finfo_open(FILEINFO_MIME_TYPE), $path);
|
return finfo_file(finfo_open(FILEINFO_MIME_TYPE), $path);
|
||||||
}
|
}
|
||||||
@ -332,7 +332,7 @@ class FileSystem
|
|||||||
* @param string $path
|
* @param string $path
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function size($path)
|
public function size(string $path): int
|
||||||
{
|
{
|
||||||
return filesize($path);
|
return filesize($path);
|
||||||
}
|
}
|
||||||
@ -343,7 +343,7 @@ class FileSystem
|
|||||||
* @param string $path
|
* @param string $path
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function lastModified($path)
|
public function lastModified(string $path): int
|
||||||
{
|
{
|
||||||
return filemtime($path);
|
return filemtime($path);
|
||||||
}
|
}
|
||||||
@ -354,7 +354,7 @@ class FileSystem
|
|||||||
* @param string $directory
|
* @param string $directory
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isDirectory($directory)
|
public function isDirectory(string $directory): bool
|
||||||
{
|
{
|
||||||
return is_dir($directory);
|
return is_dir($directory);
|
||||||
}
|
}
|
||||||
@ -365,7 +365,7 @@ class FileSystem
|
|||||||
* @param string $path
|
* @param string $path
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isReadable($path)
|
public function isReadable(string $path): bool
|
||||||
{
|
{
|
||||||
return is_readable($path);
|
return is_readable($path);
|
||||||
}
|
}
|
||||||
@ -376,7 +376,7 @@ class FileSystem
|
|||||||
* @param string $path
|
* @param string $path
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isWritable($path)
|
public function isWritable(string $path): bool
|
||||||
{
|
{
|
||||||
return is_writable($path);
|
return is_writable($path);
|
||||||
}
|
}
|
||||||
@ -387,7 +387,7 @@ class FileSystem
|
|||||||
* @param string $file
|
* @param string $file
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isFile($file)
|
public function isFile(string $file): bool
|
||||||
{
|
{
|
||||||
return is_file($file);
|
return is_file($file);
|
||||||
}
|
}
|
||||||
@ -399,7 +399,7 @@ class FileSystem
|
|||||||
* @param int $flags
|
* @param int $flags
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function glob($pattern, $flags = 0)
|
public function glob(string $pattern, $flags = 0): array
|
||||||
{
|
{
|
||||||
return glob($pattern, $flags);
|
return glob($pattern, $flags);
|
||||||
}
|
}
|
||||||
@ -411,7 +411,7 @@ class FileSystem
|
|||||||
* @param bool $hidden
|
* @param bool $hidden
|
||||||
* @return \Symfony\Component\Finder\SplFileInfo[]
|
* @return \Symfony\Component\Finder\SplFileInfo[]
|
||||||
*/
|
*/
|
||||||
public function files($directory, $hidden = false)
|
public function files(string $directory, $hidden = false): array
|
||||||
{
|
{
|
||||||
return iterator_to_array(
|
return iterator_to_array(
|
||||||
Finder::create()->files()->ignoreDotFiles(! $hidden)->in($directory)->depth(0)->sortByName(),
|
Finder::create()->files()->ignoreDotFiles(! $hidden)->in($directory)->depth(0)->sortByName(),
|
||||||
@ -426,7 +426,7 @@ class FileSystem
|
|||||||
* @param bool $hidden
|
* @param bool $hidden
|
||||||
* @return \Symfony\Component\Finder\SplFileInfo[]
|
* @return \Symfony\Component\Finder\SplFileInfo[]
|
||||||
*/
|
*/
|
||||||
public function allFiles($directory, $hidden = false)
|
public function allFiles(string $directory, $hidden = false): array
|
||||||
{
|
{
|
||||||
return iterator_to_array(Finder::create()->files()->ignoreDotFiles(! $hidden)->in($directory)->sortByName(),
|
return iterator_to_array(Finder::create()->files()->ignoreDotFiles(! $hidden)->in($directory)->sortByName(),
|
||||||
false
|
false
|
||||||
@ -439,7 +439,7 @@ class FileSystem
|
|||||||
* @param string $directory
|
* @param string $directory
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function directories($directory)
|
public function directories(string $directory): array
|
||||||
{
|
{
|
||||||
$directories = [];
|
$directories = [];
|
||||||
|
|
||||||
@ -459,7 +459,7 @@ class FileSystem
|
|||||||
* @param bool $force
|
* @param bool $force
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function makeDirectory($path, $mode = 0755, $recursive = false, $force = false)
|
public function makeDirectory(string $path, $mode = 0755, $recursive = false, $force = false): bool
|
||||||
{
|
{
|
||||||
if ($force) {
|
if ($force) {
|
||||||
return @mkdir($path, $mode, $recursive);
|
return @mkdir($path, $mode, $recursive);
|
||||||
@ -476,7 +476,7 @@ class FileSystem
|
|||||||
* @param bool $overwrite
|
* @param bool $overwrite
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function moveDirectory($from, $to, $overwrite = false)
|
public function moveDirectory(string $from, string $to, $overwrite = false): bool
|
||||||
{
|
{
|
||||||
if ($overwrite && $this->isDirectory($to) && ! $this->deleteDirectory($to)) {
|
if ($overwrite && $this->isDirectory($to) && ! $this->deleteDirectory($to)) {
|
||||||
return false;
|
return false;
|
||||||
@ -493,7 +493,7 @@ class FileSystem
|
|||||||
* @param int|null $options
|
* @param int|null $options
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function copyDirectory($directory, $destination, $options = null)
|
public function copyDirectory(string $directory, string $destination, $options = null): bool
|
||||||
{
|
{
|
||||||
if (! $this->isDirectory($directory)) {
|
if (! $this->isDirectory($directory)) {
|
||||||
return false;
|
return false;
|
||||||
@ -537,7 +537,7 @@ class FileSystem
|
|||||||
* @param bool $preserve
|
* @param bool $preserve
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function deleteDirectory($directory, $preserve = false)
|
public function deleteDirectory(string $directory, $preserve = false): bool
|
||||||
{
|
{
|
||||||
if (! $this->isDirectory($directory)) {
|
if (! $this->isDirectory($directory)) {
|
||||||
return false;
|
return false;
|
||||||
@ -567,7 +567,7 @@ class FileSystem
|
|||||||
* @param string $directory
|
* @param string $directory
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function deleteDirectories($directory)
|
public function deleteDirectories(string $directory): bool
|
||||||
{
|
{
|
||||||
$allDirectories = $this->directories($directory);
|
$allDirectories = $this->directories($directory);
|
||||||
|
|
||||||
@ -588,7 +588,7 @@ class FileSystem
|
|||||||
* @param string $directory
|
* @param string $directory
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function cleanDirectory($directory)
|
public function cleanDirectory(string $directory): bool
|
||||||
{
|
{
|
||||||
return $this->deleteDirectory($directory, true);
|
return $this->deleteDirectory($directory, true);
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,10 @@ class SensitiveWord implements ValidateInterface
|
|||||||
{
|
{
|
||||||
$trie = app(Trie::class);
|
$trie = app(Trie::class);
|
||||||
|
|
||||||
|
if (!$trie->getTries()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
$word = $trie->getSensitiveWords($trie->getTries(), $value, false);
|
$word = $trie->getSensitiveWords($trie->getTries(), $value, false);
|
||||||
|
|
||||||
return !$word;
|
return !$word;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user