https://github.com/erenkucuker/powerful-php
⚡ Laravel Helpers, Collections and Js like object oriented chaining for Native PHP
https://github.com/erenkucuker/powerful-php
helper-functions laravel laravel-framework native-php php pipeline
Last synced: 2 months ago
JSON representation
⚡ Laravel Helpers, Collections and Js like object oriented chaining for Native PHP
- Host: GitHub
- URL: https://github.com/erenkucuker/powerful-php
- Owner: erenkucuker
- Created: 2021-06-11T13:28:31.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-06-15T18:00:02.000Z (about 4 years ago)
- Last Synced: 2025-03-06T04:06:47.422Z (4 months ago)
- Topics: helper-functions, laravel, laravel-framework, native-php, php, pipeline
- Homepage:
- Size: 2.93 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Welcome to Powerful PHP 🦾
> ⚡ Laravel Helpers, Collections and Js like object oriented chaining for Native PHP
## Install
```sh
composer require erenkucukersoftware/powerful-php
```
## 🚀 Usage### Object Oriented Chaining
#### Example 1 :
##### Functional Approach```php
$snakeCase = strtolower(
preg_replace('/(.)(?=[A-Z])/u', '$1_',
preg_replace('/\s+/u', '',
ucwords('HelloWorld')
)
)
);
var_dump($snakeCase); // "hello_world"
```##### Object Oriented Approach
```php
//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 :
```php
pipe('hello')
->str_replace('o', '', _)
->var_dump; // "hell"
```#### Example 3 :
##### One Parameter Usage
You can omit parentheses if only one argument is used:
```php
pipe('some')
->is_array
->dd; // bool(false)
```#### Example 4 :
##### Values
```php
$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
```php
pipe()
->use('Some\\Namespace')->foo // Call "\Some\Namespace\foo()"
->foo // Call "\foo()"
;```
Calling multiple function from namespace
```php
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**.
1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the Branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request## Author
👤 **Eren Küçüker**
* Website: www.erenkucuker.com
* Twitter: [@yerenkucuker](https://twitter.com/yerenkucuker)
* Github: [@erenkucukersoftware](https://github.com/erenkucukersoftware)
* LinkedIn: [@yunus-eren-küçüker-609716168](https://linkedin.com/in/yunus-eren-küçüker-609716168)## Show your support
Give a ⭐️ if this project helped you!
## 📝 License
Copyright © 2021 [Eren Küçüker](https://github.com/erenkucukersoftware).
This project is [MIT](https://opensource.org/licenses/MIT) licensed.