https://github.com/nabeghe/cally-php
Just a handy helper for callables and calling them!
https://github.com/nabeghe/cally-php
action callable callback filter invoke php phpfunction phphelper phpsupport support
Last synced: 4 months ago
JSON representation
Just a handy helper for callables and calling them!
- Host: GitHub
- URL: https://github.com/nabeghe/cally-php
- Owner: nabeghe
- License: mit
- Created: 2024-10-18T14:09:12.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-10-18T14:10:43.000Z (over 1 year ago)
- Last Synced: 2024-10-18T17:00:35.802Z (over 1 year ago)
- Topics: action, callable, callback, filter, invoke, php, phpfunction, phphelper, phpsupport, support
- Language: PHP
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Cally (Callable Helper for PHP)
> Just a handy helper for callables and calling them!
## 🫡 Usage
### 🚀 Installation
You can install the package via composer:
```bash
composer require nabeghe/cally
```
### Examples
#### Example - call:
An alternative to `call_user_func_array` where you can create an array callable
and place the arguments directly in the array.
```php
use Nabeghe\Cally\Cally;
class Math
{
public static function multiple($number1, $number2)
{
return $number1 * $number2;
}
}
$value = Cally::call([Math::class, 'multiple', 13], 14);
echo $value; // 182
```
#### Example - ob:
Execute a callable between `ob_start`, `ob_get_contents`, & `ob_end_clean`, and returns the final buffer.
```php
use Nabeghe\Cally\Cally;
$output = Cally::ob(function () {
echo 'nabeghe/cally';
});
echo $output; // nabeghe/cally
```
#### Example - action:
Invokes a series of callbacks sequentially and in order.
```php
use Nabeghe\Cally\Cally;
Cally::action([
function (&$number) {
echo "Action 1 = $number\n";
$number+=1;
},
function ($number) {
echo "Action 2 = $number\n";
},
], 13);
// Action 1 = 13
// Action 2 = 14
```
#### Example - filter:
Sequentially passes a value through a series of callbacks, updating it with each callback's output, and returns the final value.
```php
use Nabeghe\Cally\Cally;
$value = Cally::filter([
function ($value, $number) {
echo "Filter 1 = $value\n";
$value+=$number;
return $value;
},
function ($value, $number) {
echo "Filter 2 = $value\n";
$value*=$number;
return $value;
},
], 13, 14);
echo "Value = $value\n";
// Filter 1 = 13
// Filter 2 = 27
// Value = 378
```
## 📖 License
Licensed under the MIT license, see [LICENSE.md](LICENSE.md) for details.