erenkucukersoftware / powerful-php
⚡ Laravel Helpers, Collections and Js like object oriented chaining for Native 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: 2025-03-06 10:34:19 UTC
README
⚡ Laravel Helpers, Collections and Js like object oriented chaining for Native PHP
Install
composer require erenkucukersoftware/powerful-php
🚀 Usage
Object Oriented Chaining
Example 1 :
Functional Approach
$snakeCase = strtolower( preg_replace('/(.)(?=[A-Z])/u', '$1_', preg_replace('/\s+/u', '', ucwords('HelloWorld') ) ) ); var_dump($snakeCase); // "hello_world"
Object Oriented Approach
//powerfulphp $snakeCase = pipe('Hello World') ->ucwords(_) ->preg_replace('/\s+/u', '', _) ->preg_replace('/(.)(?=[A-Z])/u', '$1_', _) ->strtolower(_) ->var_dump; // // string(11) "hello_world" //
Example 2 :
Passing Value Between Pipes
To pass a value as an argument to a function, use the underscore (_) character :
pipe('hello') ->str_replace('o', '', _) ->var_dump; // "hell"
Example 3 :
One Parameter Usage
You can omit parentheses if only one argument is used:
pipe('some') ->is_array ->dd; // bool(false)
Example 4 :
Values
$context = pipe('hello')->strtoupper; var_dump($context); // object(Fun\Pipe\Pipe)#8 (1) { ... } var_dump($context()); // string(5) "HELLO"
Example 5 :
Namespaces
Calling single function from namespace
pipe() ->use('Some\\Namespace')->foo // Call "\Some\Namespace\foo()" ->foo // Call "\foo()" ;
Calling multiple function from namespace
pipe() ->use('Some\\Namespace', fn($pipe) => $pipe ->a // Call "\Some\Namespace\a()" ->b // Call "\Some\Namespace\b()" ) ->a // Call "a()" ;
Contributing
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Author
👤 Eren Küçüker
- Website: www.erenkucuker.com
- Twitter: @yerenkucuker
- Github: @erenkucukersoftware
- LinkedIn: @yunus-eren-küçüker-609716168
Show your support
Give a ⭐️ if this project helped you!
📝 License
Copyright © 2021 Eren Küçüker.
This project is MIT licensed.