Compile Blade comments into valid PHP.

@param  string $value

@return string
9254
protected function compileComments($value)
    {
        $pattern = sprintf('/%s--(.*?)--%s/s', $this->contentTags[0], $this->contentTags[1]);

        return preg_replace($pattern, '<?php /*$1*/ ?>', $value);
    }
949257
public function compileString($value)
    {
        $result = '';

        // Here we will loop through all of the tokens returned by the Zend lexer and
        // parse each one into the corresponding valid PHP. We will then have this
        // template as the correctly rendered PHP that can be rendered natively.
        foreach (token_get_all($value) as $token) {
            if (is_array($token)) {
                list($id, $content) = $token;
                if ($id === T_INLINE_HTML) {
                    $content = $this->_compileStatements($content);
                    $content = $this->_compileComments($content);
                    $content = $this->_compileEchos($content);
                }
            } else {
                $content = $token;
            }

            $result .= $content;
        }

        if ($this->_hash_length) {
            $result = $this->_addFileHash($result);
        }

        return $result;
    }
274521
protected function compileMacroStart($value)
    {
        $pattern = $this->createMatcher('macro');

        $value = preg_replace($pattern, '$1<?php $__container->startMacro$2; ?>', $value);

        $pattern = $this->createMatcher('story');

        return preg_replace($pattern, '$1<?php $__container->startMacro$2; ?>', $value);
    }
1193989
private function decorateStringValue(string $value) : string
    {
        if ($value === '@this'){
            return "\$c";
        }
    
        if (preg_match('/^@id:(.*)$/s',$value,$matches)){
            $id = trim($matches[1]);
            return "\$c['" . self::escapeSingleQuote($id) . "']";
        }
    
        if (preg_match('/^@resolve:(.*)$/s',$value,$matches)){
            $target = trim($matches[1]);
            return "\$c[\$c->resolve('" . self::escapeSingleQuote($target) . "')]";
        }
    
        if (preg_match('/^@func:(.*)$/s',$value,$matches)){
            $func = trim($matches[1]);
            $this->validateCallable($func);
            return $func;
        }
        
        if (preg_match('/^@int:(.*)$/s',$value,$matches)){
            $value = trim($matches[1]);
            $value = $this->validateInteger($value);
            return $this->decorateValue($value);
        }
    
        if (preg_match('/^@float:(.*)$/s',$value,$matches)){
            $value = trim($matches[1]);
            $value = $this->validateFloat($value);
            return $this->decorateValue($value);
        }
    
        if (preg_match('/^@bool:(.*)$/s',$value,$matches)){
            $value = trim($matches[1]);
            $value = $this->validateBool($value);
            return $this->decorateValue($value);
        }
    
        if (preg_match('/^@json:(.*)$/s',$value,$matches)){
            $value = trim($matches[1]);
            $value = $this->validateJson($value);
            return $this->decorateValue($value);
        }
    
        if (preg_match('/^@env:(.*)$/s',$value,$matches)){
            $id = trim($matches[1]);
            return "(\$_ENV['" . self::escapeSingleQuote($id) . "'] ?? null)";
        }
    
        return "'" . self::escapeSingleQuote($value) . "'";
    }
928980
protected function decodeQuorum($value)
    {
        if (isset(self::$decode[$value])) {
            return self::$decode[$value];
        }

        return $value;
    }
827080
private function formatValue($value)
    {
        if ($value === '') {
            return '';
        }

        if ($value === null) {
            return '<comment>Null</comment>';
        }

        if (is_bool($value)) {
            return '<comment>' . ($value ? 'True' : 'False') . '</comment>';
        }

        if (empty($value)) {
            return '<comment>Empty</comment>';
        }

        if (is_array($value)) {
            return json_encode($value, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
        }

        if (is_object($value)) {
            return sprintf('<%s>', get_class($value));
        }

        if (is_scalar($value)) {
            return $value;
        }

        throw new InvalidArgumentException(sprintf('Do not know how to format value "%s"', print_r($value, true)));
    }
1110980
protected function compileEscapedEchos($value)
    {
        $pattern = sprintf('/(@)?%s\s*(.+?)\s*%s(\r?\n)?/s', $this->escapedTags[0], $this->escapedTags[1]);

        $callback = function ($matches) {
            $whitespace = empty($matches[3]) ? '' : $matches[3].$matches[3];

            return $matches[1] ? $matches[0] : "<?php echo e({$matches[2]}); ?>{$whitespace}";
        };

        return preg_replace_callback($pattern, $callback, $value);
    }
691332
protected function compileEscapedEchos($value)
	{
		$me = $this;

		$pattern = sprintf('/%s\s*(.+?)\s*%s/s', $this->escapedTags[0], $this->escapedTags[1]);

		$callback = function($matches) use ($me)
		{
			return '<?php echo e('.$me->compileEchoDefaults($matches[1]).'); ?>';
		};

		return preg_replace_callback($pattern, $callback, $value);
	}
1336032
public function compileString($value) {
        $result = '';

        $this->footer = [];

        // 将PHP源码按照PHP标记进行分割
        foreach (token_get_all($value) as $token) {
            $result .= is_array($token) ? $this->parseToken($token) : $token;
        }

        // 添加到尾部
        if (count($this->footer) > 0) {
            $result = ltrim($result, PHP_EOL)
                .PHP_EOL.implode(PHP_EOL, array_reverse($this->footer));
        }

        return $result;
    }
862227
protected function compileLanguage($value)
	{
		$pattern = $this->createMatcher('lang');

		$value = preg_replace($pattern, '$1<?php echo \Fly\Support\Facades\Lang::get$2; ?>', $value);

		$pattern = $this->createMatcher('choice');

		return preg_replace($pattern, '$1<?php echo \Fly\Support\Facades\Lang::choice$2; ?>', $value);
	}
1046176
public function filter($value)
    {
        if (!is_scalar($value) && !is_array($value)) {
            return $value;
        }

        // a unicode safe way of converting characters to \x00\x00 notation
        $pregQuotedSeparator = preg_quote($this->separator, '#');

        if (StringUtils::hasPcreUnicodeSupport()) {
            $patterns = [
                '#(' . $pregQuotedSeparator.')(\P{Z}{1})#u',
                '#(^\P{Z}{1})#u',
            ];
            if (!extension_loaded('mbstring')) {
                $replacements = [
                    function ($matches) {
                        return strtoupper($matches[2]);
                    },
                    function ($matches) {
                        return strtoupper($matches[1]);
                    },
                ];
            } else {
                $replacements = [
                    function ($matches) {
                        return mb_strtoupper($matches[2], 'UTF-8');
                    },
                    function ($matches) {
                        return mb_strtoupper($matches[1], 'UTF-8');
                    },
                ];
            }
        } else {
            $patterns = [
                '#(' . $pregQuotedSeparator.')([\S]{1})#',
                '#(^[\S]{1})#',
            ];
            $replacements = [
                function ($matches) {
                    return strtoupper($matches[2]);
                },
                function ($matches) {
                    return strtoupper($matches[1]);
                },
            ];
        }

        $filtered = $value;
        foreach ($patterns as $index => $pattern) {
            $filtered = preg_replace_callback($pattern, $replacements[$index], $filtered);
        }
        return $filtered;
    }
724989
protected static function highlightComment($value)
    {
        if (self::is_cli()) {
            return self::$cli_comment . $value . "\x1b[0m";
        } else {
            return '<span ' . self::$comment_attributes . '>' . $value . '</span>';
        }
    }
196569
protected static function compile_forelse($value)
	{
		preg_match_all('/(\s*)@forelse(\s*\(.*\))(\s*)/', $value, $matches);

		foreach ($matches[0] as $forelse)
		{
			preg_match('/\s*\(\s*(\S*)\s/', $forelse, $variable);

			// Once we have extracted the variable being looped against, we can add
			// an if statement to the start of the loop that checks if the count
			// of the variable being looped against is greater than zero.
			$if = "<?php if (count({$variable[1]}) > 0): ?>";

			$search = '/(\s*)@forelse(\s*\(.*\))/';

			$replace = '$1'.$if.'<?php foreach$2: ?>';

			$blade = preg_replace($search, $replace, $forelse);

			// Finally, once we have the check prepended to the loop we'll replace
			// all instances of this forelse syntax in the view content of the
			// view being compiled to Blade syntax with real PHP syntax.
			$value = str_replace($forelse, $blade, $value);
		}

		return $value;
	}
469711
public function compileString($value)
    {
        $result = '';

        if (strpos($value, '@verbatim') !== false) {
            $value = $this->storeVerbatimBlocks($value);
        }

        $this->footer = [];

        // Here we will loop through all of the tokens returned by the Zend lexer and
        // parse each one into the corresponding valid PHP. We will then have this
        // template as the correctly rendered PHP that can be rendered natively.
        foreach (token_get_all($value) as $token) {
            $result .= is_array($token) ? $this->parseToken($token) : $token;
        }

        if (! empty($this->verbatimBlocks)) {
            $result = $this->restoreVerbatimBlocks($result);
        }

        // If there are any footer lines that need to get added to a template we will
        // add them here at the end of the template. This gets used mainly for the
        // template inheritance via the extends keyword that should be appended.
        if (count($this->footer) > 0) {
            $result = $this->addFooters($result);
        }

        return $result;
    }
572763
protected static function debugFormatString($value) {
    $res = "";
    if (!empty($value)) {
      foreach (str_split($value) as $c) {
        $res .= ProtocolMessage::escapeByte($c);
      }
    }
    return '"' . $res . '"';
  }
1034081
public function compile($value, $serversOnly = false)
    {
        $compilers = $serversOnly ? $this->serverCompilers : $this->compilers;

        $value = $this->initializeVariables($value);

        foreach ($compilers as $compiler) {
            $value = $this->{"compile{$compiler}"}($value);
        }

        return $value;
    }
829025
protected function humanize($value)
    {
        // Older versions of Laravel's inflector strip out spaces
        // in the original string, so we'll first swap out all
        // spaces with underscores, then convert them back.
        $value = str_replace(' ', '_', $value);

        // First we'll convert the string to snake case. Then we'll
        // convert all dashes and underscores to spaces. Finally,
        // we'll add a space before a pound (Laravel doesn't).
        $value = Str::snake($value);

        $value = preg_replace('~(?:-|_)+~', ' ', $value);

        $value = preg_replace('~([^ ])(?:#)+~', '$1 #', $value);

        return ucfirst($value);
    }