示例#1
0
文件: Util.php 项目: matks/vivian
 public function testGetVisibleStringLength()
 {
     $testString = 'hello there !';
     $testString2 = "hello there !";
     $testString3 = "Green cannot be blue";
     $this->integer(Vivian\Util::getVisibleStringLength($testString))->isEqualTo(13)->integer(Vivian\Util::getVisibleStringLength($testString2))->isEqualTo(13)->integer(Vivian\Util::getVisibleStringLength($testString3))->isEqualTo(20);
 }
示例#2
0
 /**
  * Frame with the given Border the given string
  *
  * @param string $string
  * @param Border $border
  *
  * @return string
  */
 private static function buildFrame($string, Border $border)
 {
     $stringLength = Util::getVisibleStringLength($string);
     $line = Util::buildPatternLine($border->getLineCharacter(), $stringLength + 2);
     $firstLine = $border->getCrossCharacter() . $line . $border->getCrossCharacter();
     $mainLine = $border->getColumnCharacter() . ' ' . $string . ' ' . $border->getColumnCharacter();
     $lastLine = $firstLine;
     $result = $firstLine . PHP_EOL . $mainLine . PHP_EOL . $lastLine . PHP_EOL;
     return $result;
 }
示例#3
0
 /**
  * @param string    $key
  * @param string    $value
  * @param Structure $structure
  * @param int       $maxKeyLength
  * @param int       $maxValueLength
  *
  * @return string
  */
 private static function printStructureLine($key, $value, Structure $structure, $maxKeyLength, $maxValueLength)
 {
     $result = '';
     $insertTab = $structure->getTab() ? true : false;
     $border = $structure->getBorder();
     if ($border) {
         $keyLength = Util::getVisibleStringLength($key);
         $missingKeyLength = $maxKeyLength - $keyLength;
         $fillingKeySpace = Util::buildPatternLine(' ', $missingKeyLength);
         $valueLength = Util::getVisibleStringLength($value);
         $missingValueLength = $maxValueLength - $valueLength;
         $fillingValueSpace = Util::buildPatternLine(' ', $missingValueLength);
         $result .= $insertTab ? $structure->getTab() : '';
         $result .= $border->getColumnCharacter() . ' ' . $key . $fillingKeySpace . ' ';
         $result .= $structure->getKeyToValueCharacter() . ' ' . $value . $fillingValueSpace . ' ';
         $result .= $border->getColumnCharacter() . PHP_EOL;
     } else {
         $keyLength = Util::getVisibleStringLength($key);
         $missingKeyLength = $maxKeyLength - $keyLength;
         $fillingKeySpace = Util::buildPatternLine(' ', $missingKeyLength);
         $result .= $insertTab ? $structure->getTab() : '';
         $result .= $key . $fillingKeySpace . ' ';
         $result .= $structure->getKeyToValueCharacter() . ' ' . $value;
         $result .= PHP_EOL;
     }
     return $result;
 }