snicco/str-arr
Composer 安装命令:
composer require snicco/str-arr
包简介
A standalone implementation of Laravel's Str and Arr classes.
README 文档
README
This package contains a subset of the illuminate/support Str and Arr
classes.
Laravel's string and array helpers are very handy utility classes
but pulling in the entire illuminate/support is not an option
when you are writing a framework-agnostic package.
The following modifications have been made:
Str:
- full multibyte support for all methods
- strict-typehints
Stris a final class- all hidden
illuminate/*dependencies are removed - full support for
@psalm.
Arr:
- strict-typehints
Arris a final class- all hidden
illuminate/*dependencies are removed Collectionreferences are replaces withArrayAccessorArrayObjectwhere applicable- full support for
@psalmand@templateannotations.
Installation
composer require snicco/str-arr
Usage
This package is pretty much self-documenting.
Check the source (Str, Arr) and tests (Str
, Arr)
Public API of Str:
use Snicco\Component\StrArr\Str; $subject = 'snicco.io'; Str::contains($subject, '.io') // true Str::containsAll($subject, ['.io', '.com']) // false Str::containsAny($subject, ['.io', '.com']) // true Str::studly('snicco str-arr'); // Snicco StrArr Str::ucfirst($subject); // Snicco.io Str::startsWith($subject, 'snicco') // true Str::endsWith($subject, '.io') // true Str::doesNotEndWith($subject, '.io') // false Str::afterFirst($subject, 'c') // co.io Str::afterLast($subject, 'c') // o.io Str::betweenFirst($subject, 'c', 'o') // o Str::betweenLast($subject, 'c', 'o') // co.io Str::beforeFirst($subject, 'o') // snicc Str::beforeLast($subject, 'o') // snicco.i Str::substr($subject, -3) // .io // This accepts any regex pattern. * will be replaced with ".*" Str::is($subject, 'snicco.*') // true Str::replaceFirst($subject, 'c', 'k') // snikco.io Str::replaceAll($subject, 'c', 'k') // snikko.io Str::pregReplace($subject, 'c', '/\.\w{2}/', '.de') // snicco.de
Public API of Arr:
use Snicco\Component\StrArr\Arr;use Snicco\Component\StrArr\Str; $array = [ 'foo' => 'bar' 'baz' => 'biz' 'boom' => [ 'bang' => 'pow' ] ] Arr::only($array, ['foo']) // ['foo'=>'bar'] // Returns the first array element Arr::first($array) // bar // Returns the first element matching the condition Arr::first( $array, fn(string $value, string $key) => Str::startsWith($key, 'f') ); // bar // With a default value Arr::first($array, fn($value) => is_int($value), 'default') // default Arr::random($array, 1) // returns one random value. Arr::toArray('foo') // ['foo'] Arr::toArray([]) // [] Arr::toArray(['foo']) // ['foo'] // Checks if all keys are strings Arr::isAssoc($array) // true Arr::isList($array) // false Arr::isList(['foo', 'bar']) // true Arr::get($array, 'foo') // bar Arr::get($array, 'bogus') // null Arr::get($array, 'bogus', 'default') // default Arr::get($array, 'boom.bang') // pow // passed by reference here Arr::set($array, 'boom.bang', 'POW'); Arr::has($array, 'foo') // true Arr::has($array, 'bogus') // false Arr::has($array, 'boom.bang') // true Arr::hasAll(['foo', 'bogus']) // false Arr::hasAny(['foo', 'bogus']) // true // Checks if the passed value is either array or ArrayAccess Arr::accessible($array) // true Arr::mergeRecursive($array, ['boom' => ['bang' => 'POW', 'new' => 'NEW']]) // [ 'foo' => 'bar' // 'baz' => 'biz' // 'boom' => [ // 'bang' => 'POW', // 'new => 'NEW' // ] // ] Arr::keyExists($array, 'foo') // true Arr::flatten($array) // ['bar', 'biz', 'pow'] Arr::except($array, ['foo', 'baz']) // [ // 'boom' => [ // 'bang' => 'POW', // 'new => 'NEW' // ] // ] // Passed by reference here Arr::remove($array, 'boom.bang'); // [ 'foo' => 'bar' // 'baz' => 'biz' // 'boom' => [] // ]
Contributing
This repository is a read-only split of the development repo of the Snicco project.
This is how you can contribute.
Reporting issues and sending pull requests
Please report issues in the Snicco monorepo.
Security
If you discover a security vulnerability, please follow our disclosure procedure.
snicco/str-arr 适用场景与选型建议
snicco/str-arr 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 22.14k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2022 年 04 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 snicco/str-arr 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 snicco/str-arr 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 22.14k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 17
- 依赖项目数: 10
- 推荐数: 0
其他信息
- 授权协议: LGPL-3.0-only
- 更新时间: 2022-04-17