承接 cjstroud/classnames-php 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

cjstroud/classnames-php

最新稳定版本:1.0.0

Composer 安装命令:

composer require cjstroud/classnames-php

包简介

A simple PHP utility for conditionally joining classNames together

README 文档

README

Build Status

PHP port of the JavaScript classNames utility. https://github.com/JedWatson/classnames

Installation

composer require cjstroud/classnames-php

The classNames can be accessed anywhere.

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.

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.

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

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

Laravel Blade

<div class="{{ classNames('foo', ['bar' => true]) }}"></div>

<div class="foo bar"></div>

License

MIT. Copyright (c) 2017 Chris Stroud.

统计信息

  • 总下载量: 162.55k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 21
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 20
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-04-29