Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 6 days 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 (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-06-29T05:06:03.000Z (over 4 years ago)
- Last Synced: 2023-03-06T12:03:57.319Z (over 1 year ago)
- Language: PHP
- Size: 1000 Bytes
- Stars: 3
- Watchers: 2
- 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'])
```