PHP code example of ecailles / dom-class-name

1. Go to this page and download the library: Download ecailles/dom-class-name 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/ */

    

ecailles / dom-class-name example snippets


use Ecailles\DomClassName\Bem\Bem;

// 'block--block-modifier'
$classname = (new Bem())
    ->block('block')->modifier('block-modifier')
    ->value();

use Ecailles\DomClassName\Bem\Bem;

// 'block--block-modifier__element--element-modifier'
$classname = (new Bem())
    ->block('block')->modifier('block-modifier')
    ->element('element')->modifier('element-modifier')
    ->value();

use Ecailles\DomClassName\Bem\Bem;

// 'block--block-modifier__element--element-modifier class1 class2'
$classname = (new Bem())
    ->block('block')->modifier('block-modifier')
    ->element('element')->modifier('element-modifier')
    ->class(['class1', 'class2'])
    ->value();

use Ecailles\DomClassName\Bem\Bem;

// ['block--block-modifier__element--element-modifier', 'class1', 'class2']
$classnames = (new Bem())
    ->block('block')->modifier('block-modifier')
    ->element('element')->modifier('element-modifier')
    ->class(['class1', 'class2'])
    ->get();

use Ecailles\DomClassName\Bem\Bem;

// 'block--block-modifier__element--element-modifier class1 class2'
$classname = (new Bem())
    ->block('block')->modifier('block-modifier')
    ->element('element')->modifier('element-modifier')
    ->class(['class1', 'class2'])
    ->value();

use Ecailles\DomClassName\Bem\Bem;

$bem = (new Bem())->block('block')->class('class');

// 'block class'
echo htmlspecialchars($bem, ENT_QUOTES, 'UTF-8');

use Ecailles\DomClassName\Bem\Bem;

// 'block--block-modifier__element--element-modifier'
$classname = (new Bem())
    ->blockModifier('block-modifier')
    ->elementModifier('element-modifier')
    ->block('block')->element('element')
    ->value();

use Ecailles\DomClassName\Bem\Bem;

$block = (new Bem())->block('block');

// 'block__element1'
$element1 = $block->clone()->element('element1')->value();

// 'block__element2'
$element2 = $block->clone()->element('element2')->value();

use Ecailles\DomClassName\Bem\Bem;

// 'prefix-block'
$classname = (new Bem())->prefix('prefix')->block('block')->value();

use Ecailles\DomClassName\Bem\Bem;

// 'prefix-block'
$classname = (new Bem('prefix'))->block('block')->value();

use Ecailles\DomClassName\Bem\Bem;

// 'prefix__block'
$classname = (new Bem())->prefix('prefix')->prefixSeparator('__')
    ->block('block')->value();

use Ecailles\DomClassName\Bem\Bem;

// 'prefix__block'
$classname = (new Bem('prefix', '__'))->block('block')->value();

use Ecailles\DomClassName\Bem\Bem;

// 'block-element'
$classname = (new Bem())->elementSeparator('-')
    ->block('block')->element('element')->value();

use Ecailles\DomClassName\Bem\Bem;

// 'block-element'
$classname = (new Bem(null, null, '-'))
    ->block('block')->element('element')->value();

use Ecailles\DomClassName\Bem\Bem;

// 'block-modifier'
$classname = (new Bem())->modifierSeparator('-')
    ->block('block')->element('modifier')->value();

use Ecailles\DomClassName\Bem\Bem;

// 'block-modifier'
$classname = (new Bem(null, null, null, '-'))
    ->block('block')->modifier('modifier')->value();