fridde / funct
常用代码块,funct/funct 的分支
This package is auto-updated.
Last update: 2024-08-29 04:42:53 UTC
README
一个 PHP 库,包含常用代码块,以加快开发速度
Funct\firstValueNotEmpty($a, $b, $c)
[] (https://github.com/phpfunct/funct/releases) [
] (LICENSE) [
] (https://travis-ci.org/phpfunct/funct) [
] (https://scrutinizer-ci.com/g/phpfunct/funct) [
] (https://scrutinizer-ci.com/g/phpfunct/funct) [
] (https://packagist.org.cn/packages/funct/funct)
- 需求
- 安装
- 使用
- 库
- 通用
- 集合
- String
- between
- camelize
- chompLeft
- chompRight
- classify
- collapseWhitespace
- contains
- countOccurrences
- dasherize
- endsWith
- includes
- isAlpha
- isAlphaNumeric
- isLower
- isNumeric
- isUpper
- latinize
- left
- len
- length
- lines
- lowerCaseFirst
- pad
- padLeft
- padRight
- repeat
- reverse
- right
- slugify
- startsWith
- strip
- stripPunctuation
- swapCase
- times
- titleize
- toLower
- toSentenceSerial
- toUpper
- truncate
- underscore
- upperCaseFirst
- Invoke
- Object
- Testing
- Contributing
- License
需求
- PHP >= 5.5
安装
通过 Composer
$ composer require funct/funct
使用
该库包含五个组: Collection、Invoke、Object、Strings 和 General。每个组都有自己的命名空间后缀(只有 General 使用根命名空间)。
要包含所有组函数,只需在文件顶部包含根命名空间。
use Funct;
对于单个组函数,您有两个选项。一个是包含根命名空间并直接使用完整命名空间进行调用,例如。
use Funct; Funct\Strings\classify('hello world');
或者只包含单个组,例如。
use Funct\Strings; Strings\classify('hello world');
如果您使用 PHP >=5.6,则可以只包含单个函数。例如。
use function Funct\Strings\classify; classify('hello world');
通用
arrayKeyNotExists($key, array $array)
检查给定的键或索引是否存在于数组中
Funct\arrayKeyNotExists(2, [1, 2]); // => true Funct\arrayKeyNotExists(1, [1, 2]); // => false
false($value)
如果值是 false,则返回 true
Funct\false(false); // => true Funct\false(true); // => false
firstValue($valueA)
从函数参数中返回第一个非 null 值
Funct\firstValue('foo_bar'); // => 'foo_bar' Funct\firstValue(null, 'foo_bar'); // => 'foo_bar' Funct\firstValue(null, null, 'foo_bar'); // => 'foo_bar'
firstValueNotEmpty($valueA, $valueB)
从函数参数中返回第一个非空值
Funct\firstValueNotEmpty('foo_bar'); // => 'foo_bar' Funct\firstValueNotEmpty('', 'foo_bar'); // => 'foo_bar' Funct\firstValueNotEmpty('', null, 'foo_bar'); // => 'foo_bar'
ifSetOr($value, $default)
如果第一个参数存在,则返回第一个参数;如果不存在,则返回第二个参数或 null
$bar = 'bar'; Funct\ifSetOr($foo); // => 'NULL' Funct\ifSetOr($foo, 'foo_bar'); // => 'foo_bar' Funct\ifSetOr($bar, 'foo_bar'); // => 'bar' ($bar value)
notEmpty($value)
如果值不为空,则返回 true
Funct\notEmpty('fooBar'); // => true Funct\notEmpty(''); // => false
notInArray($needle, $haystack, $strict = null)
检查刺针是否不在数组中
Funct\notInArray(3, [0, 1, 2]); // => true Funct\notInArray(2, [0, 1, 2]); // => false
notNull($value)
如果值不是 null,则返回 true
Funct\notNull('fooBar'); // => true Funct\notNull(null); // => false
null($value)
如果值是 null,则返回 true
Funct\null(null); // => true Funct\null('fooBar'); // => false
tempFile($prefix = 'php')
在系统临时文件夹中生成带有前缀的临时文件
Funct\tempFile('php'); // => /tmp/someFile.php
true($value)
如果值是 true,则返回 true
Funct\true(true); // => true Funct\true(false); // => false
集合
compact($collection)
返回一个包含所有假值的数组的副本
Collection\compact([0, 1, false, 2, '', 3]); // => [1, 2, 3]
countBy($collection, $callback)
将数组排序到组中,并返回每个组中对象的数量。类似于groupBy,但返回值数组而不是返回值组的计数
Collection\countBy( [1, 2, 3, 4, 5], function ($value) { return $value % 2 == 0 ? 'even': 'odd'; } ); // => ['odd' => 3, 'even' => 2] Collection\countBy( [ ['color' => 'red', 'title' => 'Foo'], ['color' => 'red', 'title' => 'Foo'], ['color' => 'red', 'title' => 'Foo'], ['color' => 'blue', 'title' => 'Bar'], ['color' => 'blue', 'title' => 'Bar'] ], 'color' ); // => ['red' => 3, 'blue => 2]
every($collection, callable $callback = null)
如果数组中的所有值都通过回调的真相测试,则返回 true
Collection\every([true, 1, null, 'yes']); // => false Collection\every([true, 1, 'yes']); // => true Collection\every( [2, 4, 6], function ($value) { return ($value % 2) === 0; } ); // => true
findWhere($collection, $value)
遍历数组并返回第一个与所列属性中的所有键值对匹配的值
Collection\findWhere( [ ['title' => 'Book of Fooos', 'author' => 'FooBar', 'year' => 1111], ['title' => 'Cymbeline', 'author' => 'Shakespeare', 'year' => 1611], ['title' => 'The Tempest', 'author' => 'Shakespeare', 'year' => 1611], ['title' => 'Book of Foos Barrrs', 'author' => 'FooBar', 'year' => 2222], ['title' => 'Still foooing', 'author' => 'FooBar', 'year' => 3333], ['title' => 'Happy Foo', 'author' => 'FooBar', 'year' => 4444], ], ['author' => 'Shakespeare', 'year' => 1611] ); // => ['title' => 'Cymbeline', 'author' => 'Shakespeare', 'year' => 1611]
first($collection)
集合的第一个值
Collection\first([1, 2, 3]); // => 1
firstN($collection, $n = 1)
Collection\firstN([1, 2, 3]); // => [1] Collection\firstN([1, 2, 3], 2); // => [1, 2]
flatten($collection, $depth = 1)
通过深度扁平化嵌套数组
Collection\flatten(['a', ['b', ['c', ['d']]]]); // => ['a', 'b', ['c', ['d']]] Collection\flatten(['a', ['b', ['c', ['d']]]], 2); // => ['a', 'b', 'c', ['d']] Collection\flatten(['a', ['b', ['c', ['d']]]], 3); // => ['a', 'b', 'c', 'd']
flattenAll($collection)
将所有数组扁平化到单级
Collection\flattenAll(['a', ['b', ['c', ['d']]]]); // => ['a', 'b', 'c', 'd']
forEvery($collection, $callable)
invoke($collection, $callable) 的别名
get($collection, $key, $default = null)
如果存在,则从集合中返回项目,否则返回 null 或默认值
$collection = ['red' => []]; $collection['blue'] = Collection\get($collection, 'blue', []); $collection['blue'][] = 'Hello World'; Collection\get($collection, 'red', ['empty']);
groupBy($collection, $callback)
将集合拆分为集合,根据运行每个值通过回调的结果进行分组。如果回调是字符串
Collection\groupBy([1.3, 2.1, 2.4], function($num) { return floor($num); }); // => [1 => [1.3], 2 => [2.1, 2.4]] Collection\groupBy(['one', 'two', 'three'], 'strlen'); // => [3 => ["one", "two"], 5 => ["three"]]
initial($collection, $n = 1)
返回数组中的所有元素,除了最后一个元素。在 arguments 对象上特别有用。传递 n 可以排除最后一个
Collection\initial([5, 4, 3, 2, 1]); // => [5, 4, 3, 2] Collection\initial([5, 4, 3, 2, 1], 2); // => [5, 4, 3]
intersection($collectionFirst, $collectionSecond)
计算所有数组的交集值列表。结果中的每个值都存在于每个
Collection\intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); // => [1, 2]
invoke($collection, callable $callback)
对列表中的每个值调用回调函数。任何额外传递的参数将转发到方法调用。
Collection\invoke(['a', 'b', 'c'], 'strtoupper'); // => ['A', 'B', 'C']
last($collection)
返回数组的最后一个元素
Collection\last([1, 2, 3]); // => 3
lastIndexOf($collection, $value)
返回值在数组中最后出现的位置索引,如果值不存在则返回 false
Collecton\lastIndexOf([1, 2, 3, 1, 2, 3], 2); // => 4
lastN($collection, $n = 1)
返回数组的最后一个元素。传递 n 将返回数组的最后 n 个元素。
Collection\lastN([1, 2, 3]); // => [3] Collection\lastN([1, 2, 3], 2); // => [2, 3]
maxValue($collection, callable $callback)
使用回调方法返回集合中的最大值
Collection\minValue( [ 10 => [ 'title' => 'a', 'size' => 1 ], 20 => [ 'title' => 'b', 'size' => 2 ], 30 => [ 'title' => 'c', 'size' => 3 ] ], function ($item) { return $item['size']; } ); // => [ 'title' => 'c', 'size' => 3 ]
merge(&$a, $b)
将所有数组合并到第一个数组中
$array = [1, 2]; Collection\merge($array, [3, 4], [5, 6]); $array // => [1, 2, 3, 4, 5, 6];
minValue($collection, callable $callback)
使用回调方法返回集合中的最小值
Collection\minValue( [ 10 => [ 'title' => 'a', 'size' => 1 ], 20 => [ 'title' => 'b', 'size' => 2 ], 30 => [ 'title' => 'c', 'size' => 3 ] ], function ($item) { return $item['size']; } ); // => [ 'title' => 'a', 'size' => 1 ]
pairs($collection)
将数组转换为[key, value]对列表。
Collection\pairs([1, 2, 3]); // => [[0, 1], [1, 2], [2, 3]]
partition($collection, callable $callback)
将数组拆分为两个数组:一个包含所有满足回调的元素,另一个包含所有不满足的元素
Collection\partition([1, 2, 3, 4, 5, 6, 7, 8, 9], function ($num) { return $num % 2 === 0; }); // => [[0, 2, 4, 6, 8], [1, 3, 5, 7, 9]]
pluck($collection, $key)
从数组数组中提取单个属性
Collection\pluck( [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ], 0 ); // => [1, 4, 7]
reject($collection, callable $callback)
返回数组中不包含通过真值测试回调的元素的值。是 array_filter 的对立面。
Collection\reject([1, 2, 3, 4, 5, 6], function($num) { return $num % 2 == 0; }); // => [1, 3, 5]
rest($collection, $from = 1)
返回数组中的其余元素。传递 from 以返回从该索引开始的数组值。
Collection\rest([5, 4, 3, 2, 1]); // => [4, 3, 2, 1]
reverse($collection, $preserveNumericKeys)
反转数组。
Collection\reverse(['a', 'b', 'c']); // ['c', 'b', 'a'] Collection\reverse(['php', 7.0, ['green', 'red']], true); // [2 => [0 => 'green', 1 => 'red'], 1 => 7.0, 0 => 'php']
size($collection, $countRecursive)
计算集合的大小,即计算集合中所有元素的数量
Collection\size(['a', 'b', 'c']); // 3 Collection\size(['a', 'b', 'c', ['d', 'e']], true); // 6
some($collection, callable $callback = null)
如果数组中的任何值通过回调真值测试,则返回 true。
Collection\some([null, 0, 'yes', false]); // => true
sortBy($collection, $sortBy, $sortFunction = 'asort')
通过返回要排序的值的回调函数返回排序后的数组
Collection\sortBy([1, 2, 3, 4, 5, 6], function ($num) { return sin($num); }); // => [5, 4, 6, 3, 1, 2]
tail($collection, $from = 1)
rest($collection, $from = 1) 的别名
toJson($collection)
返回集合的 JSON 表示形式
Collection\toJson(['a' => 1, 'b' => 2, 'c' => 3]); // {"a":1,"b":2,"c":3}
union($collectionFirst, $collectionSecond)
计算传入数组的并集:按顺序列出唯一的项,这些项存在于一个或多个数组中
Collection\union([1, 2, 3], [101, 2, 1, 10], [2, 1]); // => [1, 2, 3, 101, 10]
unzip($collection)
zip 的对立面。给定多个数组,返回一系列新数组,第一个数组包含所有
Collection\unzip([['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]]); // => ["moe", 30, true], ["larry", 40, false], ["curly", 50, false]
where($collection, $value)
遍历数组中的每个值,返回一个包含所有包含所有键值对的值的数组
Collection\findWhere( [ ['title' => 'Book of Fooos', 'author' => 'FooBar', 'year' => 1111], ['title' => 'Cymbeline', 'author' => 'Shakespeare', 'year' => 1611], ['title' => 'The Tempest', 'author' => 'Shakespeare', 'year' => 1611], ['title' => 'Book of Foos Barrrs', 'author' => 'FooBar', 'year' => 2222], ['title' => 'Still foooing', 'author' => 'FooBar', 'year' => 3333], ['title' => 'Happy Foo', 'author' => 'FooBar', 'year' => 4444], ], ['author' => 'Shakespeare', 'year' => 1611] ); // => [ 1 => ['title' => 'Cymbeline', 'author' => 'Shakespeare', 'year' => 1611], 2 => ['title' => 'The Tempest', 'author' => 'Shakespeare', 'year' => 1611] ]
without($collection, $without)
返回一个新数组,其中删除了所有实例的值。
Collection\without([1, 2, 1, 0, 3, 1, 4], 0, 1); // => [2, 3, 4]
zip($collectionFirst, $collectionSecond)
将每个数组的值与相应位置的值合并。
Collection\zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]); // => [["moe", 30, true], ["larry", 40, false], ["curly", 50, false]]
String
between($input, $left, $right)
提取两个子字符串之间的字符串
Strings\between('<a>foo</a>', '<a>', '</a>'); // => 'foo' Strings\between('<a>foo</a></a>', '<a>', '</a>'); // => 'foo' Strings\between('<a><a>foo</a></a>', '<a>', '</a>'); // => '<a>foo' Strings\between('<a>foo', '<a>', '</a>'); // => '' Strings\between('Some strings } are very {weird}, dont you think?', '{', '}'); // => 'weird' Strings\between('This is a test string', 'test'); // => ' string' Strings\between('This is a test string', '', 'test'); // => 'This is a '
camelize($input, $firstLetterUppercase = false)
将字符串转换为驼峰命名
Strings\camelize('data_rate'); //'dataRate' Strings\camelize('background-color'); //'backgroundColor' Strings\camelize('-moz-something'); //'MozSomething' Strings\camelize('_car_speed_'); //'CarSpeed' Strings\camelize('yes_we_can'); //'yesWeCan'Strings\camelize(
chompLeft($input, $prefix)
从字符串的开始删除前缀
Strings\chompLeft('foobar', 'foo'); //'bar' Strings\chompLeft('foobar', 'bar'); //'foobar'
chompRight($input, $suffix)
从字符串的末尾删除后缀
Strings\chompRight('foobar', 'bar'); // => 'foo' Strings\chompRight('foobar', 'foo'); // => 'foobar'
classify($string)
将字符串转换为驼峰化的类名。第一个字母始终是大写的
Strings\classify('className'); // => ClassName
collapseWhitespace($input)
压缩多个空格
Strings\collapseWhitespace(" String \t libraries are \n\n\t fun\n! "); // => 'String libraries are fun !'
contains($input, $substring)
检查字符串是否包含子字符串
Strings\contains('PHP is one of the best languages!', 'one'); // => true
countOccurrences($input, $substring)
计算字符串中子字符串的出现次数
Strings\countOccurrences('AN likes to program. AN does not play in the NBA.', "AN"); // => 2 Strings\countOccurrences('Does not exist.', "Flying Spaghetti Monster"); // => 0 Strings\countOccurrences('Does not exist.', "Bigfoot"); // => 0 Strings\countOccurrences('PHP is fun, therefore Node.js is fun', "fun"); // => 2 Strings\countOccurrences('funfunfun', "fun"); // => 3
dasherize($string)
将破折号和驼峰命名转换为破折号
Strings\dasherize('dataRate'); // => 'data-rate' Strings\dasherize('CarSpeed'); // => 'car-speed' Strings\dasherize('yesWeCan'); // => 'yes-we-can' Strings\dasherize('backgroundColor'); // => 'background-color'
endsWith($input, $substring)
检查字符串是否以子字符串结尾
Strings\endsWith("hello jon", 'jon'); // => true
includes($input, $substring)
contains 的别名
isAlpha($input)
检查字符串是否只包含字母
Strings\isAlpha("afaf"); // => true Strings\isAlpha('fdafaf3'); // => false Strings\isAlpha('dfdf--dfd'); // => false
isAlphaNumeric($input)
检查字符串是否只包含字母数字
Strings\isAlphaNumeric("afaf35353afaf"); // => true Strings\isAlphaNumeric("FFFF99fff"); // => true Strings\isAlphaNumeric("99"); // => true Strings\isAlphaNumeric("afff"); // => true Strings\isAlphaNumeric("Infinity"); // => true Strings\isAlphaNumeric("-Infinity"); // => false Strings\isAlphaNumeric("-33"); // => false Strings\isAlphaNumeric("aaff.."); // => false
isLower($input, $mb = false)
检查给定字符串中的字母是否全部为小写。
Strings\isLower('a'); // => true Strings\isLower('z'); // => true Strings\isLower('B'); // => false Strings\isLower('hiAN'); // => true Strings\isLower('hi AN'); // => false Strings\isLower('HelLO'); // => false
isNumeric($input)
检查字符串是否只包含数字。
Strings\isNumeric("3"); // => true Strings\isNumeric("34.22"); // => false Strings\isNumeric("-22.33"); // => false Strings\isNumeric("NaN"); // => false Strings\isNumeric("Infinity"); // => false Strings\isNumeric("-Infinity"); // => false Strings\isNumeric("AN"); // => false Strings\isNumeric("-5"); // => false Strings\isNumeric("000992424242"); // => true
isUpper($input, $mb = false)
检查给定字符串中的字母是否全部为大写。
Strings\isUpper('a'); // => false Strings\isUpper('z'); // => false Strings\isUpper('B'); // => true Strings\isUpper('HIAN'); // => true Strings\isUpper('HI AN'); // => false Strings\isUpper('HelLO'); // => true
latinize($input)
去除拉丁字符的重音。
Strings\latinize('crème brûlée'); // => 'creme brulee'
left($string, $n)
返回由n个正左侧字符表示的子字符串。
Strings\left('My name is AN', 2); // => 'My' Strings\left('Hi', 0); // => '' Strings\left('My name is AN', -2); // => 'AN', same as right(2)
len($input, $mb = false)
length($input, $mb = false)的别名;
length($input, $mb = false)
获取字符串长度。
Strings\length('rod'); // 3 Strings\length('marçal'); // 7 Strings\length('marçal', true); // 6
lines($string)
返回包含行的一个数组。跨平台兼容;
Strings\lines("My name is AN\nPHP is my fav language\r\nWhat is your fav language?"); // => [ 'My name is AN', 'PHP is my fav language', 'What is your fav language?' ]
lowerCaseFirst($input)
将字符串的第一个字符转换为小写。
Strings\lowerCaseFirst('HelloWorld'); // => 'helloWorld
pad($string, $length, $char = ' ')
使用指定的字符在字符串中间填充。char可以是字符串或数字,默认为空格;
Strings\pad('hello', 5); // 'hello' Strings\pad('hello', 10); // ' hello ' Strings\pad('hey', 7); // ' hey ' Strings\pad('hey', 5); // ' hey ' Strings\pad('hey', 4); // ' hey' Strings\pad('hey', 7, '-');// '--hey--'
padLeft($input, $length, $char = ' ')
左填充字符串;
Strings\padLeft('hello', 5); // => 'hello' Strings\padLeft('hello', 10); // => ' hello' Strings\padLeft('hello', 7); // => ' hello' Strings\padLeft('hello', 6); // => ' hello' Strings\padLeft('hello', 10, '.'); // => '.....hello'
padRight($input, $length, $char = ' ')
右填充字符串;
Strings\padRight('hello', 5); // => 'hello' Strings\padRight('hello', 10); // => 'hello ' Strings\padRight('hello', 7); // => 'hello ' Strings\padRight('hello', 6); // => 'hello ' Strings\padRight('hello', 10, '.'); // => 'hello.....'
repeat($input, $n)
times($input, $n)的别名;
reverse($input)
反转字符串;
Strings\reverse('hello world'); // => dlrow olleh
right($string, $n)
返回由n个正右侧字符表示的子字符串;
Strings\right('I AM CRAZY', 2); // => 'ZY' Strings\right('Does it work? ', 4); // => 'k? ' Strings\right('Hi', 0); // => '' Strings\right('My name is AN', -2); // => 'My', same as left(2)
slugify($string)
将文本转换为有效的URL别名。去除拉丁字符的重音;
Strings\slugify('Global Thermonuclear Warfare'); // => 'global-thermonuclear-warfare' Strings\slugify('Crème brûlée'); // => 'creme-brulee'
startsWith($input, $substring)
检查字符串是否以子字符串开头;
Strings\startsWith("AN is a software engineer", "AN"); // => true Strings\startsWith('wants to change the world', "politicians"); // => false
strip($string, $string1)
返回一个新的字符串,其中删除了所有[字符串1],[字符串2],...的出现;
Strings\strip(' 1 2 3--__--4 5 6-7__8__9--0', ' ', '_', '-'); // => '1234567890' Strings\strip('can words also be stripped out?', 'words', 'also', 'be'); // => 'can stripped out?'
stripPunctuation($string)
去除所有的标点符号;
Strings\stripPunctuation('My, st[ring] *full* of %punct)'); // => 'My string full of punct'
swapCase($string, $mb = false)
返回字符串的字母大小写颠倒版本;
Strings\swapCase('RoD eLIas'); // rOd EliAS
times($input, $n)
重复字符串n次;
Strings\times(' ', 3); // => ' ' Strings\times('*', 3); // => '***'
titleize($string, array $ignore = [])
创建字符串的标题版本。将所有单词大写并替换字符串中的某些字符;
Strings\titleize('hello world'); // => 'Hello World'
toSentence($array, $delimiter = ', ', $lastDelimiter = ' and ')
将数组连接成一个可读的句子;
Strings\toSentence(["A", "B", "C"]); // => "A, B and C"; Strings\toSentence(["A", "B", "C"], ", ", " ir "); // => "A, B ir C";
toLower($input, $mb = false)
将字符串转换为小写;
Strings\toLower('ROD ELIAS'); // rod elias
toSentenceSerial($array, $delimiter = ', ', $lastDelimiter = 'and ')
与string_to_sentence相同,但调整分隔符以使用序列逗号;
Strings\toSentenceSerial(["A", "B"]); // => "A and B" Strings\toSentenceSerial(["A", "B", "C"]); // => "A, B, and C" Strings\toSentenceSerial(["A", "B", "C"], ", ", " unt "); // => "jQuery, Mootools, unt Prototype"
toUpper($input, $mb = false)
将字符串转换为大写;
Strings\toUpper('rod elias'); // ROD ELIAS
truncate($input, $length, $chars = '…')
根据单词位置和字符计数截断字符串;
Strings\truncate('this is some long text', 3); // => '...' Strings\truncate('this is some long text', 7); // => 'this is...' Strings\truncate('this is some long text', 11); // => 'this is...' Strings\truncate('this is some long text', 12); // => 'this is some...' Strings\truncate('this is some long text', 11); // => 'this is...' Strings\truncate('this is some long text', 14, ' read more'); // => 'this is some read more'
underscore($string)
将连字符和驼峰命名法转换为下划线;
Strings\underscore('dataRate'); // => 'data_rate' Strings\underscore('CarSpeed'); // => 'car_speed' Strings\underscore('yesWeCan'); // => 'yes_we_can'
upperCaseFirst($input)
将字符串的第一个字符转换为大写;
Strings\upperCaseFirst('helloWorld'); // => 'HelloWorld
Invoke
ifCondition(callable $callable, $methodArguments = [], $condition)
如果条件为真则调用方法;
Invoke\ifCondition(function () { echo 'Hello World'; }, [], Funct\notEmpty('Hello?')); // => Hello World
ifIsset(callable $callable, $values, $key)
如果值isset则调用方法;
Invoke\ifIsset(function () { echo 'Hello World'; }, ['Hello' = > 1000], 'Hello'); // => Hello World
ifNotEmpty(callable $callable, $var)
如果值不为空则调用方法;
Invoke\ifNotEmpty(function () { echo 'Hello World'; }, 'Hello'); // => Hello World
Object
toArray($objects, $valueMethod, $keyMethod = null)
使用valueMethod作为值,使用/不使用keyMethod作为键从对象创建数组;
Object\toArray($objects, 'getValue', 'getkey'); // => ['key' => 'value']
assignIfIsset($object, $property, $array, $key)
如果键存在则从数组向对象赋值;
$array = ['bar' => 'foobar']; Object\assignIfIsset($object, 'foo', $array, 'bar'); // => $object->foo = 'foobar'
Testing
$ composer test
Contributing
有关详细信息,请参阅CONTRIBUTING和CONDUCT;
License
有关更多信息,请参阅License File。