Zend\Code\Generator\ValueGenerator::escape PHP Method

escape() public static method

Quotes value for PHP code.
public static escape ( string $input, boolean $quote = true ) : string
$input string Raw string.
$quote boolean Whether add surrounding quotes or not.
return string PHP-ready code.
    public static function escape($input, $quote = true)
    {
        $output = addcslashes($input, "\\'");
        // adds quoting strings
        if ($quote) {
            $output = "'" . $output . "'";
        }
        return $output;
    }

Usage Example

コード例 #1
0
 /**
  * @return string
  */
 public function generate()
 {
     $output = $this->generateTypeHint();
     if (true === $this->passedByReference) {
         $output .= '&';
     }
     if ($this->variadic) {
         $output .= '... ';
     }
     $output .= '$' . $this->name;
     if ($this->defaultValue !== null) {
         $output .= ' = ';
         if (is_string($this->defaultValue)) {
             $output .= ValueGenerator::escape($this->defaultValue);
         } elseif ($this->defaultValue instanceof ValueGenerator) {
             $this->defaultValue->setOutputMode(ValueGenerator::OUTPUT_SINGLE_LINE);
             $output .= $this->defaultValue;
         } else {
             $output .= $this->defaultValue;
         }
     }
     return $output;
 }
All Usage Examples Of Zend\Code\Generator\ValueGenerator::escape