andrey-helldar / helpers
Requires
- php: >=7.1
- guzzlehttp/guzzle: ^6.3
- illuminate/contracts: ^5.5
- illuminate/support: ^5.5
Requires (Dev)
- phpunit/phpunit: ^7.4
This package is auto-updated.
Last update: 2022-02-01 13:09:56 UTC
README
简化开发过程的函数。
注意
此包已被废弃,不再维护。作者建议使用 andrey-helldar/support 包。
安装
要获取 Helpers 的最新版本,只需使用 Composer 需求项目
$ composer require andrey-helldar/helpers
当然,您也可以手动更新您的需求块并运行 composer update
,如果您选择这样做
{ "require": { "andrey-helldar/helpers": "^1.0" } }
如果您不使用自动发现,请将 ServiceProvider 添加到 config/app.php
中的 providers 数组
Helldar\Helpers\LaravelServiceProvider::class,
您还可以发布配置文件以更改实现(即接口到特定类)
php artisan vendor:publish --provider="Helldar\Helpers\ServiceProvider"
现在您可以使用助手或直接访问接口。
祝您享受!
文档
菜单
数组
array_item_value_max_length()
返回数组中最长元素的字符数
echo array_item_value_max_length(array $array = []) : int echo (new \Helldar\Helpers\Support\Arr(array $array = [])) ->arrayItemValueMaxLength() : int
array_add_unique()
将一个唯一的元素推送到数组的末尾
array_add_unique(array &$array, $value) (new \Helldar\Helpers\Support\Arr()) ->addUnique(&$array, $value = 'value') (new \Helldar\Helpers\Support\Arr()) ->addUnique(&$array, $value = ['value1', 'value2', ...])
array_rename_keys()
重命名数组键。作为第一个参数,传递一个回调函数,该函数确定处理值的操作。函数的输出必须是一个带有名称的字符串。
return array_rename_keys($callback, array $array = []) : array return (new \Helldar\Helpers\Support\Arr(array $array = [])) ->arrayRenameKeys($callback) : array
array_size_max_value()
获取数组中最长文本元素的长度
return array_size_max_value(array $array = []) : int return (new \Helldar\Helpers\Support\Arr((array $array = [])) ->arraySizeOfMaxValue() : int
array_sort_by_keys_array()
根据键数组指定的顺序对关联数组进行排序。
array_sort_by_keys_array($array, $sorter) : void (new \Helldar\Helpers\Support\Arr()) ->sortByKeysArray($array, $sorter) : void
Example:
$arr = ['q' => 1, 'r' => 2, 's' => 5, 'w' => 123]; array_sort_by_keys_array($arr, ['q', 'w', 'e']); print_r($arr); /* Array ( [q] => 1 [w] => 123 [r] => 2 [s] => 5 )
数字
factorial()
计算数字的阶乘
echo factorial(int $n = 0) : int echo (new \Helldar\Helpers\Support\Digits()) ->factorial(int $n = 0) : int
short_number()
将数字转换为短版本
echo short_number($n = 0, $precision = 1) : int|string echo (new \Helldar\Helpers\Support\Digits($n = 0)) ->shortNumber($precision = 1) : int|string
Example:
short_number(576); // returns: 576 short_number(1000); // returns: 1K short_number(1440); // returns: 1.4K short_number(3000000); // returns: 3M short_number(3000000000); // returns: 3B short_number(3000000000000); // returns: 3T+
Dumper
dd_sql()
转储传入的变量并结束脚本。
return dd_sql($query, bool $is_short = false, bool $is_return = false) : array|string|void return (new \Helldar\Helpers\Support\Dumper($query)) ->ddSql($is_short, $is_return) : array|string|void
文件
url_file_exists()
检查文件或目录是否存在于URL上
return url_file_exists($path) : bool return (new \Helldar\Helpers\Support\Files($path)) ->urlFileExists() : bool
Http
mix_url()
将版本化Mix文件的相对路径转换为绝对路径。
return mix_url($path) : string return (new \Helldar\Helpers\Support\Http($path)) ->mixUrl() : string
base_url()
从URL获取域名。
return base_url($url) : string return (new \Helldar\Helpers\Support\Http($url)) ->baseUrl() : string
build_url()
parse_url()的逆函数 (https://php.ac.cn/manual/en/function.parse-url.php).
$parts1 = [ 'scheme' => 'http', 'host' => 'mysite.dev', ]; $parts2 = [ 'scheme' => 'https', 'host' => 'mysite.dev', 'port' => 1234, 'user' => 'foo', 'pass' => 'bar', 'path' => '/category/subcategory', 'query' => 'page=1', 'fragment' => 'section=5', ]; return build_url($parts1) : string return (new \Helldar\Helpers\Support\Http($parts2)) ->buildUrl(); // returned 1: http://mysite.dev // returned 2: https://foo:bar@mysite.dev:1234/category/subcategory?page=1#section=5
subdomain_name()
检索当前子域名名称。
return subdomain_name(); return (new \Helldar\Helpers\Support\Http()) ->getSubdomain(); // from domain `test.mysite.local` will return `test` (string). // from domain `mysite.local` will return `null` (null).
Jsonable
将对象转换为它的JSON表示。
use Helldar\Traits\Jsonable; class MyClass { use Jsonable; public function __construct($data) { $this->setData($data); } } $obj = new MyClass($data); echo $obj->toJson();
图片
image_or_default()
检查文件是否存在,如果不存在则返回默认值
echo image_or_default(string $filename, $default = null) : string echo (new \Helldar\Helpers\Support\Images($filename)) ->imageOrDefault($default = null) : string
通知
通知助手放置在单独的包 andrey-helldar/notify-exceptions 中。
字符串
str_choice()
str_choice函数将给定的语言行翻译为屈折形式
echo str_choice(int $num, array $choice = [], string $additional = '') : string echo (new \Helldar\Helpers\Support\Str($num)) ->choice(array $choice = [], string $additional = '') : string
Example:
echo str_choice(1, ['пользователь', 'пользователя', 'пользователей']); // returned "пользователь" echo str_choice(3, ['пользователь', 'пользователя', 'пользователей']); // returned "пользователя" echo str_choice(20, ['пользователь', 'пользователя', 'пользователей']); // returned "пользователей" echo str_choice(20, ['пользователь', 'пользователя', 'пользователей'], 'здесь'); // returned "пользователей здесь"
e()
在字符串中转义HTML特殊字符
echo e($value) : string echo (new \Helldar\Helpers\Support\Str($value)) ->e() : string
de()
将特殊HTML实体转换回字符
echo de($value) : string echo (new \Helldar\Helpers\Support\Str($value)) ->de() : string
str_replace_spaces()
将多个空格替换为单个空格。
echo str_replace_spaces($value) : string echo (new \Helldar\Helpers\Support\Str($value)) ->replaceSpaces() : string
系统
is_windows()
确定当前环境是否基于Windows
return is_windows() : bool return (new \Helldar\Helpers\Support\System()) ->isWindows() : bool
is_linux()
确定当前环境是否基于Linux
return is_linux() : bool return (new \Helldar\Helpers\Support\System()) ->isLinux() : bool
版权和许可
Helper工具是由Andrey Helldar为Laravel框架5.5或更高版本编写的,并且以MIT许可证发布。有关详细信息,请参阅LICENSE文件。
翻译
文本和注释的翻译由Google翻译完成。翻译帮助+1在karma中:)