Ejemplo n.º 1
0
 /**
  * Get the name of a unit. The name of a unit is its class name without a
  * "Unit"-suffix. If the class is in the namespace "Jivoo\Core\Units" or
  * "(app namespace)\Units", the namespace is removed from the name.
  * @param Unit $unit Unit.
  * @return string Unit name.
  */
 public function getName(Unit $unit)
 {
     $class = get_class($unit);
     if (Unicode::endsWith($class, 'Unit')) {
         $class = substr($class, 0, -4);
         if (Unicode::startsWith($class, 'Jivoo\\Core\\Units\\')) {
             return substr($class, strlen('Jivoo\\Core\\Units\\'));
         }
         $ns = $this->app->n() . '\\';
         if (Unicode::startsWith($class, $ns)) {
             return substr($class, strlen($ns));
         }
     }
     return $class;
 }