Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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'])
```