PHP code example of xterr / classnames-php

1. Go to this page and download the library: Download xterr/classnames-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

xterr / classnames-php example snippets


use function xterr\ClassNames\classNames;

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

use \xterr\ClassNames\ClassNames;

$oClassNames = new \xterr\ClassNames\ClassNames;
$oClassNames('foo', ['bar' => TRUE]); // 'foo bar'

use function xterr\ClassNames\classNames;

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'

use function xterr\ClassNames\classNames;

$arr = ['b', ['c' => TRUE, 'd' => FALSE]];
classNames('a', arr); // => 'a b c'

use function xterr\ClassNames\classNames;

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

classNames(new ExampleObject()); // => 'bar'

use function xterr\ClassNames\classNames;

class ExampleObject
{
    public static function getClasses($aResultSet)
    {
        return ['bar'];
    }
    
    public function getClassesDynamic($aResultSet)
    {
        return ['baz'];
    }
}

$oObj = new ExampleObject();

classNames(function($aResultSet) { 
    return 'foo'
}, ['ExampleObject', 'getClasses'], [$oObj, 'getClassesDynamic']); // 'foo bar baz'

use function xterr\ClassNames\classNames;

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

composer