erenkucukersoftware / powerful-php
⚡ Laravel 辅助工具,集合和类似 JavaScript 的面向对象链式操作原生 PHP
v1.0.0
2021-06-15 17:47 UTC
Requires
- php: ^7.4|^8.0
- ext-json: *
- ext-mbstring: *
- cocur/chain: ^0.9.0
- doctrine/inflector: ^2.0
- guzzlehttp/guzzle: ^7.3
- illuminate/collections: ^8.46
- illuminate/database: ^8.46
- illuminate/events: ^8.46
- illuminate/http: ^8.46
- illuminate/log: ^8.46
- illuminate/support: ^8.46
- illuminate/validation: ^8.46
- league/commonmark: ^1.6
- monolog/monolog: ^2.2
- nesbot/carbon: ^2.49
- phpfn/pipe: ^2.0
- phpunit/php-timer: ^5.0
- psr/log: ^1.1
- psy/psysh: @stable
- ramsey/uuid: ^4.1
- symfony/filesystem: ^5.3
- symfony/var-dumper: ^5.3
- voku/portable-ascii: ^1.5
Requires (Dev)
- nunomaduro/collision: ^5.4
This package is not auto-updated.
Last update: 2024-10-03 08:38:04 UTC
README
⚡ Laravel 辅助工具,集合和类似 JavaScript 的面向对象链式操作原生 PHP
安装
composer require erenkucukersoftware/powerful-php
🚀 使用
面向对象链式操作
示例 1
功能方法
$snakeCase = strtolower( preg_replace('/(.)(?=[A-Z])/u', '$1_', preg_replace('/\s+/u', '', ucwords('HelloWorld') ) ) ); var_dump($snakeCase); // "hello_world"
面向对象方法
//powerfulphp $snakeCase = pipe('Hello World') ->ucwords(_) ->preg_replace('/\s+/u', '', _) ->preg_replace('/(.)(?=[A-Z])/u', '$1_', _) ->strtolower(_) ->var_dump; // // string(11) "hello_world" //
示例 2
在管道之间传递值
要将值作为参数传递给函数,请使用下划线(_)字符
pipe('hello') ->str_replace('o', '', _) ->var_dump; // "hell"
示例 3
单参数使用
如果只使用一个参数,可以省略括号
pipe('some') ->is_array ->dd; // bool(false)
示例 4
值
$context = pipe('hello')->strtoupper; var_dump($context); // object(Fun\Pipe\Pipe)#8 (1) { ... } var_dump($context()); // string(5) "HELLO"
示例 5
命名空间
从命名空间调用单个函数
pipe() ->use('Some\\Namespace')->foo // Call "\Some\Namespace\foo()" ->foo // Call "\foo()" ;
从命名空间调用多个函数
pipe() ->use('Some\\Namespace', fn($pipe) => $pipe ->a // Call "\Some\Namespace\a()" ->b // Call "\Some\Namespace\b()" ) ->a // Call "a()" ;
贡献
贡献使开源社区成为一个如此美妙的学习、灵感和创造的地方。您所做的任何贡献都将受到高度赞赏。
- 分支项目
- 创建您的功能分支(
git checkout -b feature/AmazingFeature) - 提交您的更改(
git commit -m 'Add some AmazingFeature') - 将更改推送到分支(
git push origin feature/AmazingFeature) - 打开拉取请求
作者
👤 Eren Küçüker
- 网站: www.erenkucuker.com
- Twitter: @yerenkucuker
- Github: @erenkucukersoftware
- LinkedIn: @yunus-eren-küçüker-609716168
展示您的支持
如果这个项目对您有帮助,请给一个 ⭐️!
📝 许可证
版权 © 2021 Eren Küçüker。
此项目采用 MIT 许可证。