JBZoo\Utils\Str::getClassName PHP Method

getClassName() public static method

Get class name without namespace
public static getClassName ( mixed $object, boolean $toLower = false ) : mixed | string
$object mixed
$toLower boolean
return mixed | string
    public static function getClassName($object, $toLower = false)
    {
        if (is_object($object)) {
            $className = get_class($object);
        } else {
            $className = $object;
        }
        $result = $className;
        if (strpos($className, '\\') !== false) {
            $className = explode('\\', $className);
            reset($className);
            $result = end($className);
        }
        if ($toLower) {
            $result = strtolower($result);
        }
        return $result;
    }

Usage Example

Example #1
0
 public function testGetClassName()
 {
     isSame('JBZoo', Str::getClassName('JBZoo'));
     isSame('JBZoo', Str::getClassName('\\JBZoo'));
     isSame('CCK', Str::getClassName('\\JBZoo\\CCK'));
     isSame('Element', Str::getClassName('\\JBZoo\\CCK\\Element'));
     isSame('Repeatable', Str::getClassName('\\JBZoo\\CCK\\Element\\Repeatable'));
     isSame('StringTest', Str::getClassName($this));
     isSame('StringTest', Str::getClassName($this, false));
     isSame('StringTest', Str::getClassName($this, false));
     isSame('phpunit', Str::getClassName(__NAMESPACE__, true));
 }