예제 #1
0
 /**
  * Sets node's raw value that must be wrapped in templates quotes.
  * 
  * @param string $rawValue Raw value
  * 
  * @return $this
  */
 public function setRawValue($rawValue)
 {
     $rawValue = preg_replace("#^[`}]|(?:`|\\\$\\{)\$#", "", $rawValue);
     $this->setValue(Utils::unquoteLiteralString("`{$rawValue}`"));
     $this->rawValue = $rawValue;
     return $this;
 }
예제 #2
0
파일: Literal.php 프로젝트: mck89/peast
 /**
  * Sets node's raw value, for exaple for strings it's the value wrapped in
  * quotes.
  * 
  * @param string $rawValue Raw value
  * 
  * @return $this
  */
 public function setRaw($rawValue)
 {
     if ($rawValue === "null") {
         $this->setValue(null);
         $this->setKind(self::KIND_NULL);
     } elseif ($rawValue === "true" || $rawValue === "false") {
         $this->setValue($rawValue === "true");
         $this->setKind(self::KIND_BOOLEAN);
     } elseif (isset($rawValue[0]) && ($rawValue[0] === "'" || $rawValue[0] === '"')) {
         $this->setValue(Utils::unquoteLiteralString($rawValue));
         $this->setKind($rawValue[0] === "'" ? self::KIND_SINGLE_QUOTE_STRING : self::KIND_DOUBLE_QUOTE_STRING);
     } else {
         $kind = self::KIND_DECIMAL_NUMBER;
         $value = $rawValue;
         if ($value[0] === "0" && isset($value[1])) {
             $secondChar = strtolower($value[1]);
             if ($secondChar === "b") {
                 $kind = self::KIND_BINARY_NUMBER;
                 $value = bindec($value);
             } elseif ($secondChar === "x") {
                 $kind = self::KIND_HEXADECIMAL_NUMBER;
                 $value = hexdec($value);
             } elseif ($secondChar === "o" || preg_match("/^0[0-7]+\$/", $value)) {
                 $kind = self::KIND_OCTAL_NUMBER;
                 $value = octdec($value);
             }
         }
         $value = (double) $value;
         $value = strpos("{$value}", ".") === false || preg_match("/\\.0*\$/", "{$value}") ? (int) $value : (double) $value;
         $this->setKind($kind);
         $this->setValue($value);
     }
     $this->raw = $rawValue;
     return $this;
 }