for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Domain\Tools;
/**
* @author Sebastiaan Hilbers <[email protected]>
*/
final class ClassToString
{
* Fully qualified class name of an object, without a leading backslash
* @param $object
* @return string
* @throws \InvalidArgumentException
public static function fqcn($object)
if (!is_object($object)) {
throw new \InvalidArgumentException("Expected an object");
}
return trim(get_class($object), '\\');
* Canonical class name of an object, of the form "My.Namespace.MyClass"
public static function canonical($object)
return str_replace('\\', '.', self::fqcn($object));
* Underscored and lowercased class name of an object, of the form "my.mamespace.my_class"
public static function underscore($object)
return strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', self::canonical($object)));
* The class name of an object, without the namespace
public static function short($object)
$parts = explode('\\', self::fqcn($object));
return end($parts);