Latte\PhpWriter::formatWord PHP Method

formatWord() public method

Formats parameter to PHP string.
public formatWord ( $s ) : string
return string
    public function formatWord($s)
    {
        return is_numeric($s) || preg_match('#^\\$|[\'"]|^(true|TRUE)\\z|^(false|FALSE)\\z|^(null|NULL)\\z|^[\\w\\\\]{3,}::[A-Z0-9_]{2,}\\z#', $s) ? $this->formatArgs(new MacroTokens($s)) : '"' . $s . '"';
    }

Usage Example

コード例 #1
0
ファイル: UIMacros.php プロジェクト: hrach/nette-application
 /**
  * {control name[:method] [params]}
  */
 public function macroControl(MacroNode $node, PhpWriter $writer)
 {
     $words = $node->tokenizer->fetchWords();
     if (!$words) {
         throw new CompileException('Missing control name in {control}');
     }
     $name = $writer->formatWord($words[0]);
     $method = isset($words[1]) ? ucfirst($words[1]) : '';
     $method = Strings::match($method, '#^\\w*\\z#') ? "render{$method}" : "{\"render{$method}\"}";
     $tokens = $node->tokenizer;
     $pos = $tokens->position;
     $param = $writer->formatArray();
     $tokens->position = $pos;
     while ($tokens->nextToken()) {
         if ($tokens->isCurrent('=>') && !$tokens->depth) {
             $wrap = TRUE;
             break;
         }
     }
     if (empty($wrap)) {
         $param = substr($param, 1, -1);
         // removes array() or []
     }
     return "/* line {$node->startLine} */ " . ($name[0] === '$' ? "if (is_object({$name})) \$_tmp = {$name}; else " : '') . '$_tmp = $this->global->uiControl->getComponent(' . $name . '); ' . 'if ($_tmp instanceof Nette\\Application\\UI\\IRenderable) $_tmp->redrawControl(NULL, FALSE); ' . ($node->modifiers === '' ? "\$_tmp->{$method}({$param});" : $writer->write("ob_start(function () {}); \$_tmp->{$method}({$param}); echo %modify(ob_get_clean());"));
 }
All Usage Examples Of Latte\PhpWriter::formatWord