2017 © Pedro Peláez
 

library classnames-php

A simple PHP utility for conditionally joining classNames together

image

cjstroud/classnames-php

A simple PHP utility for conditionally joining classNames together

  • Sunday, April 30, 2017
  • by cstroud
  • Repository
  • 2 Watchers
  • 1 Stars
  • 2,079 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 9 % Grown

The README.md

classnames-php

Build Status, (*1)

PHP port of the JavaScript classNames utility. https://github.com/JedWatson/classnames, (*2)

Installation

composer require cjstroud/classnames-php

The classNames can be accessed anywhere., (*3)

classNames('foo', ['bar' => true]); // 'foo bar'

Usage

The classNames function takes any number of arguments which can be a string or array. When using an array, if the value associated with a given key is falsy, that key won't be included in the output. If no value is given the true is assumed., (*4)

classNames('foo'); // 'foo'
classNames(['foo' => true]); // 'foo'
classNames('foo', ['bar' => false, 'baz' => true]); // 'foo baz'
classNames(['foo', 'bar' => true]) // 'foo bar'

// Falsy values get ignored
classNames('foo', null, 0, false, 1); // 'foo 1'

Objects and functions will be ignored, unless the object has __toString() function. If it does that will be called and the string value used., (*5)

class ExampleObject {
    function __toString()
    {
        return 'bar';
    }
}

classNames('foo', function() {}, new stdClass(), new ExampleObject()); // 'foo bar'

Laravel Blade



License

MIT. Copyright (c) 2017 Chris Stroud., (*6)

The Versions

30/04 2017

dev-master

9999999-dev

A simple PHP utility for conditionally joining classNames together

  Sources   Download

MIT

The Development Requires

by Chris Stroud

30/04 2017

1.0.0

1.0.0.0

A simple PHP utility for conditionally joining classNames together

  Sources   Download

MIT

The Development Requires

by Chris Stroud