public function truncate($value, $length, $type = TruncateType::Character)
 {
     switch (CPropertyValue::ensureEnum($type, TruncateType)) {
         case TruncateType::Paragraph:
             return $this->truncateParagraph($value, $length);
         case TruncateType::Word:
             return $this->truncateWord($value, $length);
         case TruncateType::Character:
         default:
             return $this->truncateCharacter($value, $length);
     }
 }
Exemple #2
0
 public static function enumValue($class, $id)
 {
     if ($id === '' || $id === null || $id === false) {
         return '---';
     }
     $class = new ReflectionClass($class);
     $values = $class->getConstants();
     if (preg_match('/[0-9]+/', $id)) {
         $values = array_values($values);
         $id = isset($values[$id]) ? $values[$id] : '';
     }
     return self::formatLabel(CPropertyValue::ensureEnum($id, $class->name));
 }
 public function testEnsureEnum()
 {
     $this->assertTrue(CPropertyValue::ensureEnum('Left', 'TextAlign') === 'Left');
     $this->setExpectedException('CException');
     $this->assertTrue(CPropertyValue::ensureEnum('left', 'TextAlign') === 'Left');
 }