Example #1
0
 protected function attrsToString()
 {
     $strBuilder = new StringBuilder();
     foreach ($this->attributes as $key => $value) {
         $strBuilder->append(sprintf(' %s="%s"', $key, $value));
     }
     return $strBuilder->toString();
 }
Example #2
0
/**
 * select에 사용하는 option들을 표시
 * @param string[] $valueList 실제값 목록
 * @param string[] $nameList 보여질 이름 목록
 * @param string $selectedValue 선택된 값
 * @throws InvalidArgumentException
 */
function html_option($valueList, $nameList, $selectedValue)
{
    $strBuilder = new StringBuilder();
    $valueCount = count($valueList);
    if (count($valueList) != count($nameList)) {
        throw new InvalidArgumentException('Value and Name are not paired.');
    }
    for ($i = 0; $i < $valueCount; $i++) {
        if ($selectedValue == $valueList[$i]) {
            $strBuilder->append("<option value='{$valueList[$i]}' selected='selected'>{$nameList[$i]}</option>");
        } else {
            $strBuilder->append("<option value='{$valueList[$i]}'>{$nameList[$i]}</option>");
        }
    }
    return $strBuilder->toString();
}
Example #3
0
 public function toString()
 {
     $strBuilder = new StringBuilder();
     $strBuilder->append('<script');
     $strBuilder->append($this->attrsToString());
     if (is_null($this->content)) {
         $strBuilder->append('></script>');
         return $strBuilder->toString();
     } else {
         $strBuilder->append('>');
         $strBuilder->append($this->content);
         $strBuilder->append('</script>');
         return $strBuilder->toString();
     }
 }
Example #4
0
 public function toString()
 {
     $strBuilder = new StringBuilder();
     $strBuilder->append('<link');
     $strBuilder->append($this->attrsToString());
     if ($this->htmlContext->isXHTML) {
         $strBuilder->append('>');
     } else {
         $strBuilder->append('/>');
     }
     return $strBuilder->toString();
 }
 private function argmentsToXml($args)
 {
     $argsBuilder = new StringBuilder();
     foreach ($args as $index => $arg) {
         try {
             if (is_object($arg)) {
                 $ref = new \ReflectionObject($arg);
                 $argsBuilder->append("<Arg name=\"{$index}\" Class=\"{$ref->getName()}\">");
                 foreach ($arg as $key => $value) {
                     if (is_scalar($value)) {
                         $argsBuilder->append("<{$key}><![CDATA[");
                         $argsBuilder->append($value);
                         $argsBuilder->append("]]></{$key}>");
                     } else {
                         //$exported = var_export($value, true);
                         // $argsBuilder->append ( "<field{$key}><![CDATA[" );
                         //$argsBuilder->append ( $exported );
                         //$argsBuilder->append ( "]]></field{$key}>" );
                         // @FIXME 순한참조 문제 해결할것!
                     }
                 }
                 $argsBuilder->append("</Arg>\n");
             } elseif (!is_array($arg)) {
                 $argsBuilder->append("<Arg name=\"{$index}\"><![CDATA[");
                 $argsBuilder->append($arg);
                 $argsBuilder->append("]]></Arg>");
             } elseif (is_array($arg)) {
                 $argsBuilder->append("<Args name=\"{$index}\">");
                 // $argsBuilder->append ( $this->argmentsToXml($arg) ); // 요쪽 메모리 에러 주범!
                 $argsBuilder->append("</Args>");
             } else {
                 echo "XML Printer error 잡을것!";
             }
         } catch (WarningException $ex) {
             if (is_scalar($arg)) {
                 $argsBuilder->append("<Arg{$index}>\n");
                 $argsBuilder->append("<value><![CDATA[");
                 $argsBuilder->append($arg);
                 $argsBuilder->append("]]></value>\n");
                 $argsBuilder->append("</Arg{$index}>\n");
             } else {
                 $argsBuilder->append("<Arg{$index} notScalar='true' />\n");
             }
         }
     }
     return $argsBuilder->toString();
 }