pixelbrackets/not-empty

not empty() - Adds methods to determine whether a variable is blank or present - Inspired by Ruby on Rails

1.0.0 2020-08-05 13:30 UTC

This package is auto-updated.

Last update: 2021-09-09 18:52:41 UTC


README

Version Build Status Made With License

Add methods to determine whether a variable is blank or present.

Inspired by Ruby on Rails.

Idea

This package is a hackathon product. Idea was to port the Ruby on Rails methods blank and present to PHP.

PHP has the empty method, but more often I need to check whether a variable is not empty. That's why a notEmpty method is available as well.

See the list below to compare the different behaviour of these methods.

┌─────────────────────────┬─────────┬────────────┬─────────┬───────────┐
│          VALUE          │ EMPTY() │ NOTEMPTY() │ BLANK() │ PRESENT() │
├─────────────────────────┼─────────┼────────────┼─────────┼───────────┤
│ string ''               │ true    │            │ true    │           │
│ string 'acme'           │         │ true       │         │ true      │
│ string ' '              │         │ true       │ true    │           │
│ string '   '            │         │ true       │ true    │           │
│ string "\t\n"           │         │ true       │ true    │           │
│ int 0                   │ true    │            │ true    │           │
│ float 0.0               │ true    │            │ true    │           │
│ int 42                  │         │ true       │         │ true      │
│ float 3.14              │         │ true       │         │ true      │
│ string '0'              │ true    │            │ true    │           │
│ string '1337'           │         │ true       │         │ true      │
│ null                    │ true    │            │ true    │           │
│ bool true               │         │ true       │         │ true      │
│ bool false              │ true    │            │ true    │           │
│ array []                │ true    │            │ true    │           │
│ array ['acme']          │         │ true       │         │ true      │
│ object {}               │         │ true       │ true    │           │
│ object {"foo" => "bar"} │         │ true       │         │ true      │
└─────────────────────────┴─────────┴────────────┴─────────┴───────────┘

Requirements

  • PHP

Installation

Packagist Entry https://packagist.org/packages/pixelbrackets/not-empty/

Source

https://gitlab.com/pixelbrackets/not-empty/

Mirror https://github.com/pixelbrackets/not-empty/

Usage

See tests/demo.php.

# empty() === false
if (empty('acme') === false)

# notEmpty()
if (NotEmpty::notEmpty('acme'))

# strings with whitespace - are not empty, but blank
if (empty('   ') === false)

if (Blank::blank('   '))

# present is the opposite of blank
if (Present::present('acme'))

License

GNU General Public License version 2 or later

The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html.

Author

Dan Untenzu (mail@pixelbrackets.de / @pixelbrackets)

Changelog

See ./CHANGELOG.md

Contribution

This script is Open Source, so please use, patch, extend or fork it.

This package is not in active delopment, contributions are welcome though.