thomas-squall/file-utils 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

thomas-squall/file-utils

最新稳定版本:0.2.8

Composer 安装命令:

composer require thomas-squall/file-utils

包简介

Utilities for file management

README 文档

README

List of available functions

  1. require_all_files
  2. require_once_all_files
  3. include_all_files
  4. include_once_all_files
  5. get_all_files
  6. get_all_dirs
  7. file_get_json
  8. file_put_json

require_all_files

Description

Requires all the files in a folder that matches the provided pattern.

Definition

require_all_files($dir, $pattern = "*.php", $callback = null)

Where:

  1. $dir is the directory where the files are located
  2. $pattern is the pattern used to find the files (*.php by default)
  3. $recursive will fetch also the child folders if set to true (default is false)
  4. $callback is the callback called per each file (null by default, the file path will be passed as parameter)

Usage

function callback($file) {
    echo "file $file has been loaded..." . EOF;
}

require_all_fields("my/dir", "*.php", "callback");

require_once_all_files

Description

Requires once all the files in a folder that matches the provided pattern.

Definition

require_once_all_files($dir, $pattern = "*.php", $callback = null)

Where:

  1. $dir is the directory where the files are located
  2. $pattern is the pattern used to find the files (*.php by default)
  3. $recursive will fetch also the child folders if set to true (default is false)
  4. $callback is the callback called per each file (null by default, the file path will be passed as parameter)

Usage

function callback($file) {
    echo "file $file has been loaded..." . EOF;
}

require_once_all_fields("my/dir", "*.php", "callback");

include_all_files

Description

Includes all the files in a folder that matches the provided pattern.

Definition

include_all_files($dir, $pattern = "*.php", $callback = null)

Where:

  1. $dir is the directory where the files are located
  2. $pattern is the pattern used to find the files (*.php by default)
  3. $recursive will fetch also the child folders if set to true (default is false)
  4. $callback is the callback called per each file (null by default, the file path will be passed as parameter)

Usage

function callback($file) {
    echo "file $file has been loaded..." . EOF;
}

include_all_fields("my/dir", "*.php", "callback");

include_once_all_files

Description

Includes once all the files in a folder that matches the provided pattern.

Definition

include_once_all_files($dir, $pattern = "*.php", $callback = null)

Where:

  1. $dir is the directory where the files are located
  2. $pattern is the pattern used to find the files (*.php by default)
  3. $recursive will fetch also the child folders if set to true (default is false)
  4. $callback is the callback called per each file (null by default, the file path will be passed as parameter)

Usage

function callback($file) {
    echo "file $file has been loaded..." . EOF;
}

include_once_all_files("my/dir", "*.php", "callback");

get_all_files

Description

Get all the files in a folder that matches the provided pattern.

Definition

get_all_files($dir, $recursive = false)

Where:

  1. $dir is the directory where the files are located
  2. $recursive will fetch also the children folders if set to true (default is false)

Usage

print_r(get_all_files("my/dir"));

get_all_dirs

Description

Returns all the directories in a given directory.

Definition

get_all_dirs($dir, $recursive = false)

Where:

  1. $dir is the directory where the files are located
  2. $recursive will fetch also the children directories if set to true (default is false)

Usage

print_r(get_all_files("my/dir"));

file_get_json

Description

Reads the content of a json file and returns it as array or object. Please Note: if the content is not a json encoded string an empty array will be returned.

Definition

file_get_json($file, $associative = true)

Where:

  1. $file is the path to the file that we want to read
  2. $associative will return the content as associative array when true, as object when false

Usage

$my_array = file_get_json("my/dir/my_file.json");

file_put_json

Description

Saves an array or an object into a json file.

Definition

file_put_json($file, $content, $pretty = true)

Where:

  1. $file is the path to the file that we want to save the content to
  2. $content is the content we want to save (array or object)
  3. $pretty will save the content prettified when true, minified when false

Usage

$my_array = [
    'fruit_1' => 'apple',
    'fruit_2' => 'pear',
    'fruit_3' => 'orange' 
];

file_put_json("my/dir/my_file.json", $my_array);

More utilities coming...

统计信息

  • 总下载量: 136
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-08-15