https://github.com/muath-ye/php-when-unless
Using “when” and “unless” in your own classes
https://github.com/muath-ye/php-when-unless
Last synced: 4 months ago
JSON representation
Using “when” and “unless” in your own classes
- Host: GitHub
- URL: https://github.com/muath-ye/php-when-unless
- Owner: muath-ye
- Created: 2020-06-29T05:00:50.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-06-29T05:06:03.000Z (almost 5 years ago)
- Last Synced: 2025-01-03T12:44:30.415Z (5 months ago)
- Language: PHP
- Size: 1000 Bytes
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# When and Unless
For this to work, we can create a simple trait so we are able to use the helpers on anything we want. These methods will take the condition, and call a ```callable``` if it evaluates to ```true```. For ```unless```, we can just call ```when()``` but with the condition flipped:
```php
when(!$condition, $callable);
}
}
```And we can fully do things like the above. Since it receives a ```callable```, we can even call public static methods from elsewhere just because we can.
```php
$transport->when($express, [Courier::class, 'setExpress'])
```