BootstrapUI\View\Helper\OptionsAwareTrait::hasAnyClass PHP Method

hasAnyClass() public method

Checks if $options['class'] contains any one of the class names.
public hasAnyClass ( array | string $classes, array $options ) : boolean
$classes array | string Name of class(es) to check.
$options array An array of HTML attributes and options.
return boolean True if any one of the class names was found.
    public function hasAnyClass($classes, array $options)
    {
        $options += ['class' => []];
        $options['class'] = $this->_toClassArray($options['class']);
        $classes = $this->_toClassArray($classes);
        foreach ($classes as $class) {
            if (in_array($class, $options['class'])) {
                return true;
            }
        }
        return false;
    }

Usage Example

 public function testHasAnyClass()
 {
     $this->assertFalse($this->object->hasAnyClass('a', []));
     $this->assertFalse($this->object->hasAnyClass('a', ['class' => 'x y z']));
     $this->assertTrue($this->object->hasAnyClass('a', ['class' => 'a b c']));
     $this->assertTrue($this->object->hasAnyClass('a w', ['class' => 'x y z a b c']));
 }