coliving/awesome-helpers
Composer 安装命令:
composer require coliving/awesome-helpers
包简介
Helper functions I find super-duper handy.
README 文档
README
Installation
composer require coliving/awesome-helpers
Helpers
carbon
Shortcut for: new Carbon or Carbon::parse()
carbon('One year ago');
chain
Makes an ordinary object chainable.
chain(new SomeClass) ->firstMethod() ->secondMethod() ->thirdMethod(); // You can use the "carry" constant to pass the result of one method into the other: chain(new Str)->singular('cars')->ucfirst(carry)(); // Returns "Car" // Also, you can grab the result of the chain by trailing // a "()" on the end of it. (Thanks to Taylor Otwell for these two additions)
connection
Run callback under a different database connection.
$tenantPostIds = connection('tenantdb', function () { return Post::pluck('id'); });
dump_sql
Returns sql query with bindings data.
dump_sql(\DB::table('users')->where('email', "blaBla")->where('id', 1)); // returns "select * from `users` where `email` = 'blaBla' and `id` = 1"
faker
Shortcut for: $faker = Faker\Factory::create()
faker()->address; // returns random, fake address faker('address'); // alternate syntax
user
A shortcut for auth()->user()
user()->posts()->create([...]);
money
echo money(12); // echoes "$12.00" echo money(12.75); // echoes "$12.75" echo money(12.75, false); // echos "$13" echo money(12.75, true, 'en_GB'); // echos "£12.75" // Note: unless specified otherwise, money() will detect the current locale.
ok
Shortcut for response('', 204). When you don't have anything to return from an endpoint, but you want to return success.
return ok();
stopwatch
Returns the amount of time (in seconds) the provided callback took to execute. Useful for debugging and profiling.
stopwatch(function () { sleep(2); }); // returns "2.0"
str_between
Returns string between second argument
str_between('--thing--', '--'); // returns "thing" str_between('[thing]', '[', ']'); // returns "thing" Str::between('--thing--', '--'); // returns "thing" Str::between('[thing]', '[', ']'); // returns "thing"
str_extract
Returns capture groups contained in the provided regex pattern.
str_extract('Jan-01-2019', '/Jan-(.*)-2019/'); // returns "01" Str::extract('Jan-01-2019', '/Jan-(.*)-2019/'); // returns "01"
str_match
Checks the provided string against the provided regex pattern.
str_match('Jan-01-2019', '/Jan-.*-2019/'); // returns true str_match('foo bar baz', 'bar'); // returns true Str::match('Jan-1-2019', '/Jan-(.*)-2019/'); // returns true
str_validate
A simple way to use validate a string using Laravel's built-in validation system.
str_validate('calebporzio@aol.com', 'regex:/\.net$/|email|max:10'); // returns: ["Format is invalid.", "May not be greater than 10 characters."] Str::validate('calebporzio@aol.com', 'regex:/\.net$/|email|max:10'); // returns: ["Format is invalid.", "May not be greater than 10 characters."]
str_wrap
str_wrap('thing', '--'); // returns "--thing--" Str::wrap('thing', '--'); // returns "--thing--"
swap
This function swaps the values of two variables.
$startDate = '2040-01-01'; $endDate = '2020-01-01'; if ($endDate < $startDate) { swap($startDate, $endDate); } echo $startDate; // prints "2020-01-01" echo $endDate; // prints "2040-01-01"
tinker
Kind of like dd(), but will open an artisan tinker terminal session with the variables you passed in, so you can play around.
$somethingYouWantToDebug = new StdClass; tinker($somethingYouWantToDebug);
Am I missing an awesome helper function?
Submit a PR or issue with helper functions you use or ideas you have for others!
TTFN, Caleb
coliving/awesome-helpers 适用场景与选型建议
coliving/awesome-helpers 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11.16k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 07 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「calebporzio」 「awesome-helpers」 「coliving」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 coliving/awesome-helpers 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 coliving/awesome-helpers 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 coliving/awesome-helpers 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Helper functions I find super-duper handy
A simple package to parse Github Flavored Markdown in PHP
Laravel Reddit API wrapper
A simple Laravel-style way to create breadcrumbs. This is forked from davejamesmiller/laravel-breadcrumbs
统计信息
- 总下载量: 11.16k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-07-12