2017 © Pedro Peláez
 

library or-else

A trait to add orElse functions to a class

image

spatie/or-else

A trait to add orElse functions to a class

  • Friday, July 29, 2016
  • by Spatie
  • Repository
  • 5 Watchers
  • 20 Stars
  • 4 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

, (*1)

or-else

Latest Version on Packagist Software License Build Status Quality Score Total Downloads, (*2)

This package adds an orElse-trait to your project., (*3)

Spatie is a webdesign agency in Antwerp, Belgium. You'll find an overview of all our open source projects on our website., (*4)

Support us

, (*5)

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products., (*6)

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall., (*7)

Install

You can install the package via composer: ``` bash $ composer require spatie/or-else, (*8)


## Postcardware You're free to use this package (it's [MIT-licensed](LICENSE.md)), but if it makes it to your production environment you are required to send us a postcard from your hometown, mentioning which of our package(s) you are using. Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium. The best postcards will get published on the open source page on our website. ## Usage When implementing the `OrElse`-trait to a class, all methods of the class will have a `OrElse`-variant. That variant has an extra parameter that will be returned if the original function returns `null` or `false`. Consider this simple class that implements the `orElse`-trait. ```php use Spatie\OrElse\OrElse; class TestClass { use OrElse; /** * This function will return the given argument. * * @return string */ public function willReturn($value) { return $value; } }

The trait dynamically adds a willReturnOrElse-method., (*9)

$testClass = new TestClass;
$testClass->willReturn('value'); // returns 'value';
$testClass->willReturnOrElse('value', 'otherValue'); // returns 'value';
$testClass->willReturnOrElse(null, 'otherValue'); // returns 'otherValue';
$testClass->willReturnOrElse(false, 'otherValue'); // returns 'otherValue';
$testClass->willReturnOrElse(false, function() { return 'closureValue'; }); // returns 'closureValue';

Change log

Please see CHANGELOG for more information what has changed recently., (*10)

Testing

bash $ composer test, (*11)

Contributing

Please see CONTRIBUTING for details., (*12)

Security

If you've found a bug regarding security please mail security@spatie.be instead of using the issue tracker., (*13)

Credits

About Spatie

Spatie is a webdesign agency in Antwerp, Belgium. You'll find an overview of all our open source projects on our website., (*14)

License

The MIT License (MIT). Please see License File for more information., (*15)

The Versions

29/07 2016

dev-master

9999999-dev https://github.com/spatie/or-else

A trait to add orElse functions to a class

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

spatie optional or-else

17/06 2015

1.0.0

1.0.0.0 https://github.com/spatie/or-else

A trait to add orElse functions to a class

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

league or-else

12/06 2015

0.0.1

0.0.1.0 https://github.com/spatie/or-else

A trait to add orElse functions to a class

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

league or-else