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.
 /**
  * @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;
 }
Esempio n. 2
0
 /**
  * generate()
  *
  * @return string
  */
 public function generate()
 {
     $output = '';
     if ($this->type && !in_array($this->type, self::$simple)) {
         $output .= $this->type . ' ';
     }
     if ($this->passedByReference === true) {
         $output .= '&';
     }
     $output .= '$' . $this->name;
     if ($this->defaultValue !== null) {
         $output .= ' = ';
         if (is_string($this->defaultValue)) {
             $output .= ValueGenerator::escape($this->defaultValue);
         } else {
             if ($this->defaultValue instanceof ValueGenerator) {
                 $this->defaultValue->setOutputMode(ValueGenerator::OUTPUT_SINGLE_LINE);
                 $output .= (string) $this->defaultValue;
             } else {
                 $output .= $this->defaultValue;
             }
         }
     }
     return $output;
 }
Esempio n. 3
0
 /**
  * @return string
  */
 private function generateDefaultValue()
 {
     if (null === $this->defaultValue) {
         return '';
     }
     if (is_string($this->defaultValue)) {
         return ' = ' . ValueGenerator::escape($this->defaultValue);
     }
     if ($this->defaultValue instanceof ValueGenerator) {
         $this->defaultValue->setOutputMode(ValueGenerator::OUTPUT_SINGLE_LINE);
     }
     return ' = ' . $this->defaultValue;
 }
Esempio n. 4
0
 /**
  * @group 6023
  *
  * @dataProvider getEscapedParameters
  */
 public function testEscaping($input, $expectedEscapedValue)
 {
     $this->assertSame($expectedEscapedValue, ValueGenerator::escape($input, false));
 }