pyrsmk/funktions
最新稳定版本:3.2.1
Composer 安装命令:
composer require pyrsmk/funktions
包简介
Premium PHP functions with a salt of functional programming
关键字:
README 文档
README
Funktions is a set of useful PHP functions aiming to ease your life by appending missing ones from PHP core, with a salt for functional programming. It has been heavily inspired by Ruby-ish API and augmented from real life needs from my professional use cases.
These functions are designed:
- to be immutables
- to support iterables, not only arrays
- to support all callables, not only closures
- to use generators first, because it rocks!
WARNING!!! THIS LIBRARY IS STILL UNDER HEAVY DEVELOPMENT AND IS NOT TESTED YET
Install
composer require pyrsmk/funktions
Usage
use function Funktions\array_flatten; $fruits = [ ['strawberries', 'kiwis'], [ ['oranges'], [ ['lemons'], [ 'melons', ['raspberries'] ] ] ] ]; $flatten_fruits = array_flatten($fruits);
array.php
array_diff_strict (array $array1, array $array2) : array: Strict diff between two arrays by comparing the values at the same index.array_drop (array $array, int $offset, int $length) : array: Drop a part of an array (immutablearray_splice).array_intersect_strict (array $array1, array $array2) : array: Strict insersection between two arrays by comparing the values at the same index.array_fill_multi (int $dimensions, int $size, mixed $value) : array: Initialize multi-dimensional arrays.array_flatten (array $array, ?int $min_depth = null) : array: Flatten an array by keeping an arbitrary minimum depth if necessary.array_merge_recursive_unique (array ...$arrays) : array: Contrary toarray_merge_recursive(), it merges array by replacing values of the same key instead of appending them into a new array.array_seek (array &$array, int|string $key) : void: Move the array pointer to a specified key (mutable).array_substitute (array $array, int $offset, int $length, array $replacement) : array: Improvedarray_splice()with full string keys support when replacing.glue (array $array, string $glue = '') : string: Glue array elements together, likeimplode()but with parameters in the right order.immut_array_push (array $array, ...$elements) : array: Immutablearray_push().immut_array_shuffle (array $array) : array: Immutableshuffle().immut_array_unset (array $array, int|string $key): Immutableunset().immut_array_unshift (array $array, ...$elements) : array: Immutablearray_unshift().immut_arsort (array $array, int $flags = SORT_REGULAR) : array: Immutablearsort().immut_asort (array $array, int $flags = SORT_REGULAR) : array: Immutableasort().immut_krsort (array $array, int $flags = SORT_REGULAR) : array: Immutablekrsort().immut_ksort (array $array, int $flags = SORT_REGULAR) : array: Immutableksort().immut_natcasesort (array $array) : array: Immutablenatcasesort().immut_natsort (array $array) : array: Immutablenatsort().immut_rsort (array $array, int $flags = SORT_REGULAR) : array: Immutablersort().immut_sort (array $array, int $flags = SORT_REGULAR) : array: Immutablesort().immut_uasort (array $array, callable $compare) : array: Immutableuasort().immut_uksort (array $array, callable $compare) : array: Immutableuksort().immut_usort (array $array, callable $compare) : array: Immutableusort().kmax (array $array) : mixed: Return the key of the maximum value.kmin (array $array) : mixed: Return the key of the minimum value.
color.php
hex2rgb (string $hex) : array: Convert HTML to RGB color.hsl2rgb (int $h, int $s, int $l) : array: Convert HSL to RGB color.hsv2rgb (int $h, int $s, int $v) : array: Convert HSV to RGB color.rgb2hex (int $r, int $g, int $b) : string: Convert RGB to HTML color.rgb2hsl (int $r, int $g, int $b) : array: Convert RGB to HSL color.rgb2hsv (int $r, int $g, int $b) : array: Convert RGB to HSV color.
iterable.php
all (iterable $iterable, callable $callable) : bool: Returntruewhen all elements match the callable's condition.any (iterable $iterable, callable $callable) : bool: Returntruewhen at least one element matches the callable's condition.ensure_generator ($maybe_a_generator) : Generator: Ensure that the passed value will be a generator.enumerate (iterable $iterable, ?callable $callable = null) : int: Enumerate elements in an iterable.first (iterable $iterable) : mixed: Return the first element of an iterable. Note that the iterable's pointer will be resetted.iterable_to_generator (iterable $items) : Generator: Convert an iterable to a generator.itoa (Traversable $iterator, bool $use_keys = true) : array: Alias toiterator_to_array().itog (iterable $items) : Generator: Alias toiterable_to_generator().last (iterable $iterable) : mixed: Return the last element of an iterable. Note that: if the iterable is an array, then its pointer will be resetted; if the iterable is not an array, it will be converted to one, then have in mind that a complete iteration will be done before being able to get its last element.map (iterable $iterable, callable $callable) : Generator: Likearray_map()but works on any iterable and with key/value support.none (iterable $iterable, callable $callable) : bool: Returntruewhen no element has matched the callable's condition.pluck (iterable $iterable, string ...$keys) : Generator: Extract lines from an iterable based on the requested keys.reduce (iterable $iterable, callable $callable, $initial = null): Likearray_reduce()but works on any iterable and with key/value support.reject (iterable $iterable, callable $callable) : Generator: Reject items that match the callable's condition.select (iterable $iterable, callable $callable) : Generator: Select items that match the callable's condition.value (iterable $iterable, string $key) : mixed: Retrieve a value from an iterable with a specified key. Note that it should be used with a hash or an array because iterating other an iterable for searching an element is not efficient at all.
instruction.php
condition (bool $test, callable $truthy, callable $falsy) : mixed: Return a value based on a test.loop (iterable $iterable, callable $callable) : Generator: Loop over an iterable and yield new values.rescue (callable $callable, array $exceptions) : mixed: Execute a callback and catch exceptions.
memory.php
memory_safe (callable $callable) : mixed: Collect garbage after callable execution.
number.php
above (float $value, float $min) : float: Bound a number to a minimum value.is_even (int $value) : bool: Verify if the value is even.is_odd (int $value) : bool: Verify if the value is odd.under (float $value, float $max) : float: Bound a number to a maximum value.
output.php
capture (callable $callable) : string: Capture output on a callable execution.mute (callable $callable) : mixed: Mute output on a callable execution.puts (string $text) : void: Print a one-line text.
regex.php
regex_count (string $pattern, string $text, int $flags = 0) : int: Count the number of matches for a regex in a string.regex_match (string $pattern, string $text, int $flags = 0) : Generator: Return the matches of a regex, for the first match.regex_match_all (string $pattern, string $text, int $flags = 0) : Generator: Return all the matches of a regex.regex_match_first (string $pattern, string $text, int $flags = 0) : string: Return the first occurrence of the first match of a regex.regex_test (string $pattern, string $text, int $flags = 0) : bool: Test if a regex matches against a string.
string.php
mb_lcfirst ($string, string $encoding = null) : string: Uncapitalize a string (multibyte support).mb_to_camelcase (string $string) : string: Converts a string to camelcase (multibyte support).mb_truncate (string $string, int $length, string $encoding = null) : string: Truncate a string to a specific length and append...at the end of the string (multibyte support).mb_ucfirst (string $string, string $encoding = null) : string: Capitalize a string (multibyte support).mb_ucwords (string $string, string $encoding = null) : string: Capitalize all words in a string (multibyte support).random_hash (int $length = 5) : string: Generate a random hash.uuid_v4 () : string: Generate a random v4 UUID.
system.php
human_fileperms (string $path) : string: Get human-readable file permissions.human_filesize (string $path) : string: Get human-readable file size.lessdir (string $dir) : array: Likescandir()but without.and...mimetype (string $path) : string: Get a file's mime type with several mecanism support.rrmdir (string $path) : void: Remove a directory recursively.
License
MIT.
pyrsmk/funktions 适用场景与选型建议
pyrsmk/funktions 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 742 次下载、GitHub Stars 达 1, 最近一次更新时间为 2015 年 01 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「generator」 「file」 「array」 「mimetype」 「number」 「output」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pyrsmk/funktions 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pyrsmk/funktions 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pyrsmk/funktions 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Memio's PrettyPrinter, used to generate PHP code from given Model
A set of useful PHP classes.
The file manager intended for using Laravel with CKEditor / TinyMCE / Colorbox
Trait providing methods to set class properties with an array.
Traits to build collections of specific objects
This adds functions about array. If you feel like there few php built-in functions about array, this will be useful.
统计信息
- 总下载量: 742
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 21
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-01-15