Ejemplo n.º 1
0
 /**
  * Returns the constant name as a string
  *
  * @param string|int $constant The CONSTANT's value that you want the name of
  * @param bool       $flipped  If false, $constant should be the CONSTANT's name. The CONSTANT's value will be
  *                             returned instead.
  * @param bool       $pretty   If true, returned value is prettified (acme.before_event becomes "Acme Before
  *                             Event")
  *
  * @throws \InvalidArgumentException
  * @return string|int
  */
 public static function nameOf($constant, $flipped = true, $pretty = true)
 {
     $_result = null;
     foreach (static::getDefinedConstants() as $_name => $_value) {
         if ($flipped) {
             if ($_name == $constant) {
                 $_result = $_value;
                 break;
             }
         } else {
             if ($_value == $constant) {
                 $_result = $_name;
                 break;
             }
         }
     }
     if (!$_result) {
         throw new \InvalidArgumentException('A constant with the value of "' . $constant . '" does not exist.');
     }
     return !$flipped && $pretty ? Inflector::display(Inflector::neutralize($_result)) : $_result;
 }
Ejemplo n.º 2
0
 /**
  * Returns the constant name as a string
  *
  * @param string|int $constant The CONSTANT's value that you want the name of
  * @param bool       $flipped  If false, $constant should be the CONSTANT's name. The CONSTANT's value will be
  *                             returned instead.
  * @param bool       $pretty   If true, returned value is prettified (acme.before_event becomes "Acme Before
  *                             Event")
  *
  * @throws \InvalidArgumentException
  * @return string|int
  */
 public static function nameOf($constant, $flipped = true, $pretty = true)
 {
     try {
         $_name = $flipped ? static::toValue($constant) : static::toConstant($constant);
     } catch (\InvalidArgumentException $_ex) {
         throw new \InvalidArgumentException('A constant with the value of "' . $constant . '" does not exist.');
     }
     return !$flipped && $pretty ? Inflector::display(Inflector::neutralize($_name)) : $_name;
 }