Primo Committ
This commit is contained in:
719
vendor/laravel/framework/src/Illuminate/View/Compilers/BladeCompiler.php
vendored
Normal file
719
vendor/laravel/framework/src/Illuminate/View/Compilers/BladeCompiler.php
vendored
Normal file
@@ -0,0 +1,719 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\View\Compilers;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Str;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class BladeCompiler extends Compiler implements CompilerInterface
|
||||
{
|
||||
use Concerns\CompilesAuthorizations,
|
||||
Concerns\CompilesComments,
|
||||
Concerns\CompilesComponents,
|
||||
Concerns\CompilesConditionals,
|
||||
Concerns\CompilesEchos,
|
||||
Concerns\CompilesErrors,
|
||||
Concerns\CompilesHelpers,
|
||||
Concerns\CompilesIncludes,
|
||||
Concerns\CompilesInjections,
|
||||
Concerns\CompilesJson,
|
||||
Concerns\CompilesLayouts,
|
||||
Concerns\CompilesLoops,
|
||||
Concerns\CompilesRawPhp,
|
||||
Concerns\CompilesStacks,
|
||||
Concerns\CompilesTranslations;
|
||||
|
||||
/**
|
||||
* All of the registered extensions.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $extensions = [];
|
||||
|
||||
/**
|
||||
* All custom "directive" handlers.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $customDirectives = [];
|
||||
|
||||
/**
|
||||
* All custom "condition" handlers.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $conditions = [];
|
||||
|
||||
/**
|
||||
* All of the registered precompilers.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $precompilers = [];
|
||||
|
||||
/**
|
||||
* The file currently being compiled.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $path;
|
||||
|
||||
/**
|
||||
* All of the available compiler functions.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $compilers = [
|
||||
// 'Comments',
|
||||
'Extensions',
|
||||
'Statements',
|
||||
'Echos',
|
||||
];
|
||||
|
||||
/**
|
||||
* Array of opening and closing tags for raw echos.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $rawTags = ['{!!', '!!}'];
|
||||
|
||||
/**
|
||||
* Array of opening and closing tags for regular echos.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $contentTags = ['{{', '}}'];
|
||||
|
||||
/**
|
||||
* Array of opening and closing tags for escaped echos.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $escapedTags = ['{{{', '}}}'];
|
||||
|
||||
/**
|
||||
* The "regular" / legacy echo string format.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $echoFormat = 'e(%s)';
|
||||
|
||||
/**
|
||||
* Array of footer lines to be added to template.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $footer = [];
|
||||
|
||||
/**
|
||||
* Array to temporary store the raw blocks found in the template.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $rawBlocks = [];
|
||||
|
||||
/**
|
||||
* The array of class component aliases and their class names.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $classComponentAliases = [];
|
||||
|
||||
/**
|
||||
* Indicates if component tags should be compiled.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $compilesComponentTags = true;
|
||||
|
||||
/**
|
||||
* Compile the view at the given path.
|
||||
*
|
||||
* @param string|null $path
|
||||
* @return void
|
||||
*/
|
||||
public function compile($path = null)
|
||||
{
|
||||
if ($path) {
|
||||
$this->setPath($path);
|
||||
}
|
||||
|
||||
if (! is_null($this->cachePath)) {
|
||||
$contents = $this->compileString($this->files->get($this->getPath()));
|
||||
|
||||
if (! empty($this->getPath())) {
|
||||
$contents = $this->appendFilePath($contents);
|
||||
}
|
||||
|
||||
$this->files->put(
|
||||
$this->getCompiledPath($this->getPath()), $contents
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Append the file path to the compiled string.
|
||||
*
|
||||
* @param string $contents
|
||||
* @return string
|
||||
*/
|
||||
protected function appendFilePath($contents)
|
||||
{
|
||||
$tokens = $this->getOpenAndClosingPhpTokens($contents);
|
||||
|
||||
if ($tokens->isNotEmpty() && $tokens->last() !== T_CLOSE_TAG) {
|
||||
$contents .= ' ?>';
|
||||
}
|
||||
|
||||
return $contents."<?php /**PATH {$this->getPath()} ENDPATH**/ ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the open and closing PHP tag tokens from the given string.
|
||||
*
|
||||
* @param string $contents
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
protected function getOpenAndClosingPhpTokens($contents)
|
||||
{
|
||||
return collect(token_get_all($contents))
|
||||
->pluck(0)
|
||||
->filter(function ($token) {
|
||||
return in_array($token, [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO, T_CLOSE_TAG]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path currently being compiled.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPath()
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the path currently being compiled.
|
||||
*
|
||||
* @param string $path
|
||||
* @return void
|
||||
*/
|
||||
public function setPath($path)
|
||||
{
|
||||
$this->path = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the given Blade template contents.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
public function compileString($value)
|
||||
{
|
||||
[$this->footer, $result] = [[], ''];
|
||||
|
||||
// First we will compile the Blade component tags. This is a precompile style
|
||||
// step which compiles the component Blade tags into @component directives
|
||||
// that may be used by Blade. Then we should call any other precompilers.
|
||||
$value = $this->compileComponentTags(
|
||||
$this->compileComments($this->storeUncompiledBlocks($value))
|
||||
);
|
||||
|
||||
foreach ($this->precompilers as $precompiler) {
|
||||
$value = call_user_func($precompiler, $value);
|
||||
}
|
||||
|
||||
// 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->rawBlocks)) {
|
||||
$result = $this->restoreRawContent($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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the blocks that do not receive compilation.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
protected function storeUncompiledBlocks($value)
|
||||
{
|
||||
if (strpos($value, '@verbatim') !== false) {
|
||||
$value = $this->storeVerbatimBlocks($value);
|
||||
}
|
||||
|
||||
if (strpos($value, '@php') !== false) {
|
||||
$value = $this->storePhpBlocks($value);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the verbatim blocks and replace them with a temporary placeholder.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
protected function storeVerbatimBlocks($value)
|
||||
{
|
||||
return preg_replace_callback('/(?<!@)@verbatim(.*?)@endverbatim/s', function ($matches) {
|
||||
return $this->storeRawBlock($matches[1]);
|
||||
}, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the PHP blocks and replace them with a temporary placeholder.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
protected function storePhpBlocks($value)
|
||||
{
|
||||
return preg_replace_callback('/(?<!@)@php(.*?)@endphp/s', function ($matches) {
|
||||
return $this->storeRawBlock("<?php{$matches[1]}?>");
|
||||
}, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a raw block and return a unique raw placeholder.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
protected function storeRawBlock($value)
|
||||
{
|
||||
return $this->getRawPlaceholder(
|
||||
array_push($this->rawBlocks, $value) - 1
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the component tags.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
protected function compileComponentTags($value)
|
||||
{
|
||||
if (! $this->compilesComponentTags) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
return (new ComponentTagCompiler(
|
||||
$this->classComponentAliases, $this
|
||||
))->compile($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the raw placeholders with the original code stored in the raw blocks.
|
||||
*
|
||||
* @param string $result
|
||||
* @return string
|
||||
*/
|
||||
protected function restoreRawContent($result)
|
||||
{
|
||||
$result = preg_replace_callback('/'.$this->getRawPlaceholder('(\d+)').'/', function ($matches) {
|
||||
return $this->rawBlocks[$matches[1]];
|
||||
}, $result);
|
||||
|
||||
$this->rawBlocks = [];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a placeholder to temporary mark the position of raw blocks.
|
||||
*
|
||||
* @param int|string $replace
|
||||
* @return string
|
||||
*/
|
||||
protected function getRawPlaceholder($replace)
|
||||
{
|
||||
return str_replace('#', $replace, '@__raw_block_#__@');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the stored footers onto the given content.
|
||||
*
|
||||
* @param string $result
|
||||
* @return string
|
||||
*/
|
||||
protected function addFooters($result)
|
||||
{
|
||||
return ltrim($result, "\n")
|
||||
."\n".implode("\n", array_reverse($this->footer));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the tokens from the template.
|
||||
*
|
||||
* @param array $token
|
||||
* @return string
|
||||
*/
|
||||
protected function parseToken($token)
|
||||
{
|
||||
[$id, $content] = $token;
|
||||
|
||||
if ($id == T_INLINE_HTML) {
|
||||
foreach ($this->compilers as $type) {
|
||||
$content = $this->{"compile{$type}"}($content);
|
||||
}
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the user defined extensions.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
protected function compileExtensions($value)
|
||||
{
|
||||
foreach ($this->extensions as $compiler) {
|
||||
$value = $compiler($value, $this);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile Blade statements that start with "@".
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
protected function compileStatements($value)
|
||||
{
|
||||
return preg_replace_callback(
|
||||
'/\B@(@?\w+(?:::\w+)?)([ \t]*)(\( ( (?>[^()]+) | (?3) )* \))?/x', function ($match) {
|
||||
return $this->compileStatement($match);
|
||||
}, $value
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a single Blade @ statement.
|
||||
*
|
||||
* @param array $match
|
||||
* @return string
|
||||
*/
|
||||
protected function compileStatement($match)
|
||||
{
|
||||
if (Str::contains($match[1], '@')) {
|
||||
$match[0] = isset($match[3]) ? $match[1].$match[3] : $match[1];
|
||||
} elseif (isset($this->customDirectives[$match[1]])) {
|
||||
$match[0] = $this->callCustomDirective($match[1], Arr::get($match, 3));
|
||||
} elseif (method_exists($this, $method = 'compile'.ucfirst($match[1]))) {
|
||||
$match[0] = $this->$method(Arr::get($match, 3));
|
||||
}
|
||||
|
||||
return isset($match[3]) ? $match[0] : $match[0].$match[2];
|
||||
}
|
||||
|
||||
/**
|
||||
* Call the given directive with the given value.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string|null $value
|
||||
* @return string
|
||||
*/
|
||||
protected function callCustomDirective($name, $value)
|
||||
{
|
||||
if (Str::startsWith($value, '(') && Str::endsWith($value, ')')) {
|
||||
$value = Str::substr($value, 1, -1);
|
||||
}
|
||||
|
||||
return call_user_func($this->customDirectives[$name], trim($value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip the parentheses from the given expression.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
public function stripParentheses($expression)
|
||||
{
|
||||
if (Str::startsWith($expression, '(')) {
|
||||
$expression = substr($expression, 1, -1);
|
||||
}
|
||||
|
||||
return $expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a custom Blade compiler.
|
||||
*
|
||||
* @param callable $compiler
|
||||
* @return void
|
||||
*/
|
||||
public function extend(callable $compiler)
|
||||
{
|
||||
$this->extensions[] = $compiler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the extensions used by the compiler.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getExtensions()
|
||||
{
|
||||
return $this->extensions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an "if" statement directive.
|
||||
*
|
||||
* @param string $name
|
||||
* @param callable $callback
|
||||
* @return void
|
||||
*/
|
||||
public function if($name, callable $callback)
|
||||
{
|
||||
$this->conditions[$name] = $callback;
|
||||
|
||||
$this->directive($name, function ($expression) use ($name) {
|
||||
return $expression !== ''
|
||||
? "<?php if (\Illuminate\Support\Facades\Blade::check('{$name}', {$expression})): ?>"
|
||||
: "<?php if (\Illuminate\Support\Facades\Blade::check('{$name}')): ?>";
|
||||
});
|
||||
|
||||
$this->directive('unless'.$name, function ($expression) use ($name) {
|
||||
return $expression !== ''
|
||||
? "<?php if (! \Illuminate\Support\Facades\Blade::check('{$name}', {$expression})): ?>"
|
||||
: "<?php if (! \Illuminate\Support\Facades\Blade::check('{$name}')): ?>";
|
||||
});
|
||||
|
||||
$this->directive('else'.$name, function ($expression) use ($name) {
|
||||
return $expression !== ''
|
||||
? "<?php elseif (\Illuminate\Support\Facades\Blade::check('{$name}', {$expression})): ?>"
|
||||
: "<?php elseif (\Illuminate\Support\Facades\Blade::check('{$name}')): ?>";
|
||||
});
|
||||
|
||||
$this->directive('end'.$name, function () {
|
||||
return '<?php endif; ?>';
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the result of a condition.
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $parameters
|
||||
* @return bool
|
||||
*/
|
||||
public function check($name, ...$parameters)
|
||||
{
|
||||
return call_user_func($this->conditions[$name], ...$parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a class-based component alias directive.
|
||||
*
|
||||
* @param string $class
|
||||
* @param string|null $alias
|
||||
* @param string $prefix
|
||||
* @return void
|
||||
*/
|
||||
public function component($class, $alias = null, $prefix = '')
|
||||
{
|
||||
if (! is_null($alias) && Str::contains($alias, '\\')) {
|
||||
[$class, $alias] = [$alias, $class];
|
||||
}
|
||||
|
||||
if (is_null($alias)) {
|
||||
$alias = Str::contains($class, '\\View\\Components\\')
|
||||
? collect(explode('\\', Str::after($class, '\\View\\Components\\')))->map(function ($segment) {
|
||||
return Str::kebab($segment);
|
||||
})->implode(':')
|
||||
: Str::kebab(class_basename($class));
|
||||
}
|
||||
|
||||
if (! empty($prefix)) {
|
||||
$alias = $prefix.'-'.$alias;
|
||||
}
|
||||
|
||||
$this->classComponentAliases[$alias] = $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an array of class-based components.
|
||||
*
|
||||
* @param array $components
|
||||
* @param string $prefix
|
||||
* @return void
|
||||
*/
|
||||
public function components(array $components, $prefix = '')
|
||||
{
|
||||
foreach ($components as $key => $value) {
|
||||
if (is_numeric($key)) {
|
||||
static::component($value, null, $prefix);
|
||||
} else {
|
||||
static::component($key, $value, $prefix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the registered class component aliases.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getClassComponentAliases()
|
||||
{
|
||||
return $this->classComponentAliases;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a component alias directive.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string|null $alias
|
||||
* @return void
|
||||
*/
|
||||
public function aliasComponent($path, $alias = null)
|
||||
{
|
||||
$alias = $alias ?: Arr::last(explode('.', $path));
|
||||
|
||||
$this->directive($alias, function ($expression) use ($path) {
|
||||
return $expression
|
||||
? "<?php \$__env->startComponent('{$path}', {$expression}); ?>"
|
||||
: "<?php \$__env->startComponent('{$path}'); ?>";
|
||||
});
|
||||
|
||||
$this->directive('end'.$alias, function ($expression) {
|
||||
return '<?php echo $__env->renderComponent(); ?>';
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an include alias directive.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string|null $alias
|
||||
* @return void
|
||||
*/
|
||||
public function include($path, $alias = null)
|
||||
{
|
||||
return $this->aliasInclude($path, $alias);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an include alias directive.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string|null $alias
|
||||
* @return void
|
||||
*/
|
||||
public function aliasInclude($path, $alias = null)
|
||||
{
|
||||
$alias = $alias ?: Arr::last(explode('.', $path));
|
||||
|
||||
$this->directive($alias, function ($expression) use ($path) {
|
||||
$expression = $this->stripParentheses($expression) ?: '[]';
|
||||
|
||||
return "<?php echo \$__env->make('{$path}', {$expression}, \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>";
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a handler for custom directives.
|
||||
*
|
||||
* @param string $name
|
||||
* @param callable $handler
|
||||
* @return void
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function directive($name, callable $handler)
|
||||
{
|
||||
if (! preg_match('/^\w+(?:::\w+)?$/x', $name)) {
|
||||
throw new InvalidArgumentException("The directive name [{$name}] is not valid. Directive names must only contain alphanumeric characters and underscores.");
|
||||
}
|
||||
|
||||
$this->customDirectives[$name] = $handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of custom directives.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCustomDirectives()
|
||||
{
|
||||
return $this->customDirectives;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new precompiler.
|
||||
*
|
||||
* @param callable $precompiler
|
||||
* @return void
|
||||
*/
|
||||
public function precompiler(callable $precompiler)
|
||||
{
|
||||
$this->precompilers[] = $precompiler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the echo format to be used by the compiler.
|
||||
*
|
||||
* @param string $format
|
||||
* @return void
|
||||
*/
|
||||
public function setEchoFormat($format)
|
||||
{
|
||||
$this->echoFormat = $format;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the "echo" format to double encode entities.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function withDoubleEncoding()
|
||||
{
|
||||
$this->setEchoFormat('e(%s, true)');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the "echo" format to not double encode entities.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function withoutDoubleEncoding()
|
||||
{
|
||||
$this->setEchoFormat('e(%s, false)');
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that component tags should not be compiled.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function withoutComponentTags()
|
||||
{
|
||||
$this->compilesComponentTags = false;
|
||||
}
|
||||
}
|
||||
74
vendor/laravel/framework/src/Illuminate/View/Compilers/Compiler.php
vendored
Executable file
74
vendor/laravel/framework/src/Illuminate/View/Compilers/Compiler.php
vendored
Executable file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\View\Compilers;
|
||||
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use InvalidArgumentException;
|
||||
|
||||
abstract class Compiler
|
||||
{
|
||||
/**
|
||||
* The Filesystem instance.
|
||||
*
|
||||
* @var \Illuminate\Filesystem\Filesystem
|
||||
*/
|
||||
protected $files;
|
||||
|
||||
/**
|
||||
* Get the cache path for the compiled views.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $cachePath;
|
||||
|
||||
/**
|
||||
* Create a new compiler instance.
|
||||
*
|
||||
* @param \Illuminate\Filesystem\Filesystem $files
|
||||
* @param string $cachePath
|
||||
* @return void
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function __construct(Filesystem $files, $cachePath)
|
||||
{
|
||||
if (! $cachePath) {
|
||||
throw new InvalidArgumentException('Please provide a valid cache path.');
|
||||
}
|
||||
|
||||
$this->files = $files;
|
||||
$this->cachePath = $cachePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path to the compiled version of a view.
|
||||
*
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
public function getCompiledPath($path)
|
||||
{
|
||||
return $this->cachePath.'/'.sha1('v2'.$path).'.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the view at the given path is expired.
|
||||
*
|
||||
* @param string $path
|
||||
* @return bool
|
||||
*/
|
||||
public function isExpired($path)
|
||||
{
|
||||
$compiled = $this->getCompiledPath($path);
|
||||
|
||||
// If the compiled file doesn't exist we will indicate that the view is expired
|
||||
// so that it can be re-compiled. Else, we will verify the last modification
|
||||
// of the views is less than the modification times of the compiled views.
|
||||
if (! $this->files->exists($compiled)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->files->lastModified($path) >=
|
||||
$this->files->lastModified($compiled);
|
||||
}
|
||||
}
|
||||
30
vendor/laravel/framework/src/Illuminate/View/Compilers/CompilerInterface.php
vendored
Executable file
30
vendor/laravel/framework/src/Illuminate/View/Compilers/CompilerInterface.php
vendored
Executable file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\View\Compilers;
|
||||
|
||||
interface CompilerInterface
|
||||
{
|
||||
/**
|
||||
* Get the path to the compiled version of a view.
|
||||
*
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
public function getCompiledPath($path);
|
||||
|
||||
/**
|
||||
* Determine if the given view is expired.
|
||||
*
|
||||
* @param string $path
|
||||
* @return bool
|
||||
*/
|
||||
public function isExpired($path);
|
||||
|
||||
/**
|
||||
* Compile the view at the given path.
|
||||
*
|
||||
* @param string $path
|
||||
* @return void
|
||||
*/
|
||||
public function compile($path);
|
||||
}
|
||||
488
vendor/laravel/framework/src/Illuminate/View/Compilers/ComponentTagCompiler.php
vendored
Normal file
488
vendor/laravel/framework/src/Illuminate/View/Compilers/ComponentTagCompiler.php
vendored
Normal file
@@ -0,0 +1,488 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\View\Compilers;
|
||||
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\View\AnonymousComponent;
|
||||
use Illuminate\View\ViewFinderInterface;
|
||||
use InvalidArgumentException;
|
||||
use ReflectionClass;
|
||||
|
||||
/**
|
||||
* @author Spatie bvba <info@spatie.be>
|
||||
* @author Taylor Otwell <taylor@laravel.com>
|
||||
*/
|
||||
class ComponentTagCompiler
|
||||
{
|
||||
/**
|
||||
* The Blade compiler instance.
|
||||
*
|
||||
* @var \Illuminate\View\Compilers\BladeCompiler
|
||||
*/
|
||||
protected $blade;
|
||||
|
||||
/**
|
||||
* The component class aliases.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $aliases = [];
|
||||
|
||||
/**
|
||||
* The "bind:" attributes that have been compiled for the current component.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $boundAttributes = [];
|
||||
|
||||
/**
|
||||
* Create new component tag compiler.
|
||||
*
|
||||
* @param array $aliases
|
||||
* @param \Illuminate\View\Compilers\BladeCompiler|null
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $aliases = [], ?BladeCompiler $blade = null)
|
||||
{
|
||||
$this->aliases = $aliases;
|
||||
|
||||
$this->blade = $blade ?: new BladeCompiler(new Filesystem, sys_get_temp_dir());
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the component and slot tags within the given string.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
public function compile(string $value)
|
||||
{
|
||||
$value = $this->compileSlots($value);
|
||||
|
||||
return $this->compileTags($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the tags within the given string.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function compileTags(string $value)
|
||||
{
|
||||
$value = $this->compileSelfClosingTags($value);
|
||||
$value = $this->compileOpeningTags($value);
|
||||
$value = $this->compileClosingTags($value);
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the opening tags within the given string.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
protected function compileOpeningTags(string $value)
|
||||
{
|
||||
$pattern = "/
|
||||
<
|
||||
\s*
|
||||
x[-\:]([\w\-\:\.]*)
|
||||
(?<attributes>
|
||||
(?:
|
||||
\s+
|
||||
[\w\-:.@]+
|
||||
(
|
||||
=
|
||||
(?:
|
||||
\\\"[^\\\"]*\\\"
|
||||
|
|
||||
\'[^\']*\'
|
||||
|
|
||||
[^\'\\\"=<>]+
|
||||
)
|
||||
)
|
||||
?)*
|
||||
\s*
|
||||
)
|
||||
(?<![\/=\-])
|
||||
>
|
||||
/x";
|
||||
|
||||
return preg_replace_callback($pattern, function (array $matches) {
|
||||
$this->boundAttributes = [];
|
||||
|
||||
$attributes = $this->getAttributesFromAttributeString($matches['attributes']);
|
||||
|
||||
return $this->componentString($matches[1], $attributes);
|
||||
}, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the self-closing tags within the given string.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
protected function compileSelfClosingTags(string $value)
|
||||
{
|
||||
$pattern = "/
|
||||
<
|
||||
\s*
|
||||
x[-\:]([\w\-\:\.]*)
|
||||
\s*
|
||||
(?<attributes>
|
||||
(?:
|
||||
\s+
|
||||
[\w\-:.@]+
|
||||
(
|
||||
=
|
||||
(?:
|
||||
\\\"[^\\\"]*\\\"
|
||||
|
|
||||
\'[^\']*\'
|
||||
|
|
||||
[^\'\\\"=<>]+
|
||||
)
|
||||
)?
|
||||
)*
|
||||
\s*
|
||||
)
|
||||
\/>
|
||||
/x";
|
||||
|
||||
return preg_replace_callback($pattern, function (array $matches) {
|
||||
$this->boundAttributes = [];
|
||||
|
||||
$attributes = $this->getAttributesFromAttributeString($matches['attributes']);
|
||||
|
||||
return $this->componentString($matches[1], $attributes)."\n@endcomponentClass ";
|
||||
}, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the Blade component string for the given component and attributes.
|
||||
*
|
||||
* @param string $component
|
||||
* @param array $attributes
|
||||
* @return string
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
protected function componentString(string $component, array $attributes)
|
||||
{
|
||||
$class = $this->componentClass($component);
|
||||
|
||||
[$data, $attributes] = $this->partitionDataAndAttributes($class, $attributes);
|
||||
|
||||
$data = $data->mapWithKeys(function ($value, $key) {
|
||||
return [Str::camel($key) => $value];
|
||||
});
|
||||
|
||||
// If the component doesn't exists as a class we'll assume it's a class-less
|
||||
// component and pass the component as a view parameter to the data so it
|
||||
// can be accessed within the component and we can render out the view.
|
||||
if (! class_exists($class)) {
|
||||
$parameters = [
|
||||
'view' => "'$class'",
|
||||
'data' => '['.$this->attributesToString($data->all(), $escapeBound = false).']',
|
||||
];
|
||||
|
||||
$class = AnonymousComponent::class;
|
||||
} else {
|
||||
$parameters = $data->all();
|
||||
}
|
||||
|
||||
return " @component('{$class}', '{$component}', [".$this->attributesToString($parameters, $escapeBound = false).'])
|
||||
<?php $component->withAttributes(['.$this->attributesToString($attributes->all()).']); ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the component class for a given component alias.
|
||||
*
|
||||
* @param string $component
|
||||
* @return string
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
protected function componentClass(string $component)
|
||||
{
|
||||
$viewFactory = Container::getInstance()->make(Factory::class);
|
||||
|
||||
if (isset($this->aliases[$component])) {
|
||||
if (class_exists($alias = $this->aliases[$component])) {
|
||||
return $alias;
|
||||
}
|
||||
|
||||
if ($viewFactory->exists($alias)) {
|
||||
return $alias;
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException(
|
||||
"Unable to locate class or view [{$alias}] for component [{$component}]."
|
||||
);
|
||||
}
|
||||
|
||||
if (class_exists($class = $this->guessClassName($component))) {
|
||||
return $class;
|
||||
}
|
||||
|
||||
if ($viewFactory->exists($view = $this->guessViewName($component))) {
|
||||
return $view;
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException(
|
||||
"Unable to locate a class or view for component [{$component}]."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Guess the class name for the given component.
|
||||
*
|
||||
* @param string $component
|
||||
* @return string
|
||||
*/
|
||||
public function guessClassName(string $component)
|
||||
{
|
||||
$namespace = Container::getInstance()
|
||||
->make(Application::class)
|
||||
->getNamespace();
|
||||
|
||||
$componentPieces = array_map(function ($componentPiece) {
|
||||
return ucfirst(Str::camel($componentPiece));
|
||||
}, explode('.', $component));
|
||||
|
||||
return $namespace.'View\\Components\\'.implode('\\', $componentPieces);
|
||||
}
|
||||
|
||||
/**
|
||||
* Guess the view name for the given component.
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
public function guessViewName($name)
|
||||
{
|
||||
$prefix = 'components.';
|
||||
|
||||
$delimiter = ViewFinderInterface::HINT_PATH_DELIMITER;
|
||||
|
||||
if (Str::contains($name, $delimiter)) {
|
||||
return Str::replaceFirst($delimiter, $delimiter.$prefix, $name);
|
||||
}
|
||||
|
||||
return $prefix.$name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Partition the data and extra attributes from the given array of attributes.
|
||||
*
|
||||
* @param string $class
|
||||
* @param array $attributes
|
||||
* @return array
|
||||
*/
|
||||
protected function partitionDataAndAttributes($class, array $attributes)
|
||||
{
|
||||
// If the class doesn't exists, we'll assume it's a class-less component and
|
||||
// return all of the attributes as both data and attributes since we have
|
||||
// now way to partition them. The user can exclude attributes manually.
|
||||
if (! class_exists($class)) {
|
||||
return [collect($attributes), collect($attributes)];
|
||||
}
|
||||
|
||||
$constructor = (new ReflectionClass($class))->getConstructor();
|
||||
|
||||
$parameterNames = $constructor
|
||||
? collect($constructor->getParameters())->map->getName()->all()
|
||||
: [];
|
||||
|
||||
return collect($attributes)->partition(function ($value, $key) use ($parameterNames) {
|
||||
return in_array(Str::camel($key), $parameterNames);
|
||||
})->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the closing tags within the given string.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
protected function compileClosingTags(string $value)
|
||||
{
|
||||
return preg_replace("/<\/\s*x[-\:][\w\-\:\.]*\s*>/", ' @endcomponentClass ', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the slot tags within the given string.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
public function compileSlots(string $value)
|
||||
{
|
||||
$value = preg_replace_callback('/<\s*x[\-\:]slot\s+(:?)name=(?<name>(\"[^\"]+\"|\\\'[^\\\']+\\\'|[^\s>]+))\s*>/', function ($matches) {
|
||||
$name = $this->stripQuotes($matches['name']);
|
||||
|
||||
if ($matches[1] !== ':') {
|
||||
$name = "'{$name}'";
|
||||
}
|
||||
|
||||
return " @slot({$name}) ";
|
||||
}, $value);
|
||||
|
||||
return preg_replace('/<\/\s*x[\-\:]slot[^>]*>/', ' @endslot', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of attributes from the given attribute string.
|
||||
*
|
||||
* @param string $attributeString
|
||||
* @return array
|
||||
*/
|
||||
protected function getAttributesFromAttributeString(string $attributeString)
|
||||
{
|
||||
$attributeString = $this->parseBindAttributes($attributeString);
|
||||
|
||||
$pattern = '/
|
||||
(?<attribute>[\w\-:.@]+)
|
||||
(
|
||||
=
|
||||
(?<value>
|
||||
(
|
||||
\"[^\"]+\"
|
||||
|
|
||||
\\\'[^\\\']+\\\'
|
||||
|
|
||||
[^\s>]+
|
||||
)
|
||||
)
|
||||
)?
|
||||
/x';
|
||||
|
||||
if (! preg_match_all($pattern, $attributeString, $matches, PREG_SET_ORDER)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return collect($matches)->mapWithKeys(function ($match) {
|
||||
$attribute = $match['attribute'];
|
||||
$value = $match['value'] ?? null;
|
||||
|
||||
if (is_null($value)) {
|
||||
$value = 'true';
|
||||
|
||||
$attribute = Str::start($attribute, 'bind:');
|
||||
}
|
||||
|
||||
$value = $this->stripQuotes($value);
|
||||
|
||||
if (Str::startsWith($attribute, 'bind:')) {
|
||||
$attribute = Str::after($attribute, 'bind:');
|
||||
|
||||
$this->boundAttributes[$attribute] = true;
|
||||
} else {
|
||||
$value = "'".$this->compileAttributeEchos($value)."'";
|
||||
}
|
||||
|
||||
return [$attribute => $value];
|
||||
})->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the "bind" attributes in a given attribute string into their fully-qualified syntax.
|
||||
*
|
||||
* @param string $attributeString
|
||||
* @return string
|
||||
*/
|
||||
protected function parseBindAttributes(string $attributeString)
|
||||
{
|
||||
$pattern = "/
|
||||
(?:^|\s+) # start of the string or whitespace between attributes
|
||||
: # attribute needs to start with a semicolon
|
||||
([\w\-:.@]+) # match the actual attribute name
|
||||
= # only match attributes that have a value
|
||||
/xm";
|
||||
|
||||
return preg_replace($pattern, ' bind:$1=', $attributeString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile any Blade echo statements that are present in the attribute string.
|
||||
*
|
||||
* These echo statements need to be converted to string concatenation statements.
|
||||
*
|
||||
* @param string $attributeString
|
||||
* @return string
|
||||
*/
|
||||
protected function compileAttributeEchos(string $attributeString)
|
||||
{
|
||||
$value = $this->blade->compileEchos($attributeString);
|
||||
|
||||
$value = $this->escapeSingleQuotesOutsideOfPhpBlocks($value);
|
||||
|
||||
$value = str_replace('<?php echo ', '\'.', $value);
|
||||
$value = str_replace('; ?>', '.\'', $value);
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape the single quotes in the given string that are outside of PHP blocks.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
protected function escapeSingleQuotesOutsideOfPhpBlocks(string $value)
|
||||
{
|
||||
return collect(token_get_all($value))->map(function ($token) {
|
||||
if (! is_array($token)) {
|
||||
return $token;
|
||||
}
|
||||
|
||||
return $token[0] === T_INLINE_HTML
|
||||
? str_replace("'", "\\'", $token[1])
|
||||
: $token[1];
|
||||
})->implode('');
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an array of attributes to a string.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param bool $escapeBound
|
||||
* @return string
|
||||
*/
|
||||
protected function attributesToString(array $attributes, $escapeBound = true)
|
||||
{
|
||||
return collect($attributes)
|
||||
->map(function (string $value, string $attribute) use ($escapeBound) {
|
||||
return $escapeBound && isset($this->boundAttributes[$attribute]) && $value !== 'true' && ! is_numeric($value)
|
||||
? "'{$attribute}' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute({$value})"
|
||||
: "'{$attribute}' => {$value}";
|
||||
})
|
||||
->implode(',');
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip any quotes from the given string.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
public function stripQuotes(string $value)
|
||||
{
|
||||
return Str::startsWith($value, ['"', '\''])
|
||||
? substr($value, 1, -1)
|
||||
: $value;
|
||||
}
|
||||
}
|
||||
102
vendor/laravel/framework/src/Illuminate/View/Compilers/Concerns/CompilesAuthorizations.php
vendored
Normal file
102
vendor/laravel/framework/src/Illuminate/View/Compilers/Concerns/CompilesAuthorizations.php
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\View\Compilers\Concerns;
|
||||
|
||||
trait CompilesAuthorizations
|
||||
{
|
||||
/**
|
||||
* Compile the can statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileCan($expression)
|
||||
{
|
||||
return "<?php if (app(\Illuminate\\Contracts\\Auth\\Access\\Gate::class)->check{$expression}): ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the cannot statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileCannot($expression)
|
||||
{
|
||||
return "<?php if (app(\Illuminate\\Contracts\\Auth\\Access\\Gate::class)->denies{$expression}): ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the canany statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileCanany($expression)
|
||||
{
|
||||
return "<?php if (app(\Illuminate\\Contracts\\Auth\\Access\\Gate::class)->any{$expression}): ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the else-can statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileElsecan($expression)
|
||||
{
|
||||
return "<?php elseif (app(\Illuminate\\Contracts\\Auth\\Access\\Gate::class)->check{$expression}): ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the else-cannot statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileElsecannot($expression)
|
||||
{
|
||||
return "<?php elseif (app(\Illuminate\\Contracts\\Auth\\Access\\Gate::class)->denies{$expression}): ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the else-canany statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileElsecanany($expression)
|
||||
{
|
||||
return "<?php elseif (app(\Illuminate\\Contracts\\Auth\\Access\\Gate::class)->any{$expression}): ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the end-can statements into valid PHP.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function compileEndcan()
|
||||
{
|
||||
return '<?php endif; ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the end-cannot statements into valid PHP.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function compileEndcannot()
|
||||
{
|
||||
return '<?php endif; ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the end-canany statements into valid PHP.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function compileEndcanany()
|
||||
{
|
||||
return '<?php endif; ?>';
|
||||
}
|
||||
}
|
||||
19
vendor/laravel/framework/src/Illuminate/View/Compilers/Concerns/CompilesComments.php
vendored
Normal file
19
vendor/laravel/framework/src/Illuminate/View/Compilers/Concerns/CompilesComments.php
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\View\Compilers\Concerns;
|
||||
|
||||
trait CompilesComments
|
||||
{
|
||||
/**
|
||||
* Compile Blade comments into an empty string.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
protected function compileComments($value)
|
||||
{
|
||||
$pattern = sprintf('/%s--(.*?)--%s/s', $this->contentTags[0], $this->contentTags[1]);
|
||||
|
||||
return preg_replace($pattern, '', $value);
|
||||
}
|
||||
}
|
||||
176
vendor/laravel/framework/src/Illuminate/View/Compilers/Concerns/CompilesComponents.php
vendored
Normal file
176
vendor/laravel/framework/src/Illuminate/View/Compilers/Concerns/CompilesComponents.php
vendored
Normal file
@@ -0,0 +1,176 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\View\Compilers\Concerns;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
trait CompilesComponents
|
||||
{
|
||||
/**
|
||||
* The component name hash stack.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $componentHashStack = [];
|
||||
|
||||
/**
|
||||
* Compile the component statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileComponent($expression)
|
||||
{
|
||||
[$component, $alias, $data] = strpos($expression, ',') !== false
|
||||
? array_map('trim', explode(',', trim($expression, '()'), 3)) + ['', '', '']
|
||||
: [trim($expression, '()'), '', ''];
|
||||
|
||||
$component = trim($component, '\'"');
|
||||
|
||||
$hash = static::newComponentHash($component);
|
||||
|
||||
if (Str::contains($component, ['::class', '\\'])) {
|
||||
return static::compileClassComponentOpening($component, $alias, $data, $hash);
|
||||
}
|
||||
|
||||
return "<?php \$__env->startComponent{$expression}; ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a new component hash for a component name.
|
||||
*
|
||||
* @param string $component
|
||||
* @return string
|
||||
*/
|
||||
public static function newComponentHash(string $component)
|
||||
{
|
||||
static::$componentHashStack[] = $hash = sha1($component);
|
||||
|
||||
return $hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a class component opening.
|
||||
*
|
||||
* @param string $component
|
||||
* @param string $alias
|
||||
* @param string $data
|
||||
* @param string $hash
|
||||
* @return string
|
||||
*/
|
||||
public static function compileClassComponentOpening(string $component, string $alias, string $data, string $hash)
|
||||
{
|
||||
return implode("\n", [
|
||||
'<?php if (isset($component)) { $__componentOriginal'.$hash.' = $component; } ?>',
|
||||
'<?php $component = $__env->getContainer()->make('.Str::finish($component, '::class').', '.($data ?: '[]').'); ?>',
|
||||
'<?php $component->withName('.$alias.'); ?>',
|
||||
'<?php if ($component->shouldRender()): ?>',
|
||||
'<?php $__env->startComponent($component->resolveView(), $component->data()); ?>',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the end-component statements into valid PHP.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function compileEndComponent()
|
||||
{
|
||||
$hash = array_pop(static::$componentHashStack);
|
||||
|
||||
return implode("\n", [
|
||||
'<?php if (isset($__componentOriginal'.$hash.')): ?>',
|
||||
'<?php $component = $__componentOriginal'.$hash.'; ?>',
|
||||
'<?php unset($__componentOriginal'.$hash.'); ?>',
|
||||
'<?php endif; ?>',
|
||||
'<?php echo $__env->renderComponent(); ?>',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the end-component statements into valid PHP.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function compileEndComponentClass()
|
||||
{
|
||||
return static::compileEndComponent()."\n".implode("\n", [
|
||||
'<?php endif; ?>',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the slot statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileSlot($expression)
|
||||
{
|
||||
return "<?php \$__env->slot{$expression}; ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the end-slot statements into valid PHP.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function compileEndSlot()
|
||||
{
|
||||
return '<?php $__env->endSlot(); ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the component-first statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileComponentFirst($expression)
|
||||
{
|
||||
return "<?php \$__env->startComponentFirst{$expression}; ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the end-component-first statements into valid PHP.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function compileEndComponentFirst()
|
||||
{
|
||||
return $this->compileEndComponent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the prop statement into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileProps($expression)
|
||||
{
|
||||
return "<?php \$attributes = \$attributes->exceptProps{$expression}; ?>
|
||||
<?php foreach (array_filter({$expression}, 'is_string', ARRAY_FILTER_USE_KEY) as \$__key => \$__value) {
|
||||
\$\$__key = \$\$__key ?? \$__value;
|
||||
} ?>
|
||||
<?php \$__defined_vars = get_defined_vars(); ?>
|
||||
<?php foreach (\$attributes as \$__key => \$__value) {
|
||||
if (array_key_exists(\$__key, \$__defined_vars)) unset(\$\$__key);
|
||||
} ?>
|
||||
<?php unset(\$__defined_vars); ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize the given component attribute value.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return mixed
|
||||
*/
|
||||
public static function sanitizeComponentAttribute($value)
|
||||
{
|
||||
return is_string($value) ||
|
||||
(is_object($value) && method_exists($value, '__toString'))
|
||||
? e($value)
|
||||
: $value;
|
||||
}
|
||||
}
|
||||
306
vendor/laravel/framework/src/Illuminate/View/Compilers/Concerns/CompilesConditionals.php
vendored
Normal file
306
vendor/laravel/framework/src/Illuminate/View/Compilers/Concerns/CompilesConditionals.php
vendored
Normal file
@@ -0,0 +1,306 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\View\Compilers\Concerns;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
trait CompilesConditionals
|
||||
{
|
||||
/**
|
||||
* Identifier for the first case in switch statement.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $firstCaseInSwitch = true;
|
||||
|
||||
/**
|
||||
* Compile the if-auth statements into valid PHP.
|
||||
*
|
||||
* @param string|null $guard
|
||||
* @return string
|
||||
*/
|
||||
protected function compileAuth($guard = null)
|
||||
{
|
||||
$guard = is_null($guard) ? '()' : $guard;
|
||||
|
||||
return "<?php if(auth()->guard{$guard}->check()): ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the else-auth statements into valid PHP.
|
||||
*
|
||||
* @param string|null $guard
|
||||
* @return string
|
||||
*/
|
||||
protected function compileElseAuth($guard = null)
|
||||
{
|
||||
$guard = is_null($guard) ? '()' : $guard;
|
||||
|
||||
return "<?php elseif(auth()->guard{$guard}->check()): ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the end-auth statements into valid PHP.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function compileEndAuth()
|
||||
{
|
||||
return '<?php endif; ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the env statements into valid PHP.
|
||||
*
|
||||
* @param string $environments
|
||||
* @return string
|
||||
*/
|
||||
protected function compileEnv($environments)
|
||||
{
|
||||
return "<?php if(app()->environment{$environments}): ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the end-env statements into valid PHP.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function compileEndEnv()
|
||||
{
|
||||
return '<?php endif; ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the production statements into valid PHP.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function compileProduction()
|
||||
{
|
||||
return "<?php if(app()->environment('production')): ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the end-production statements into valid PHP.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function compileEndProduction()
|
||||
{
|
||||
return '<?php endif; ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the if-guest statements into valid PHP.
|
||||
*
|
||||
* @param string|null $guard
|
||||
* @return string
|
||||
*/
|
||||
protected function compileGuest($guard = null)
|
||||
{
|
||||
$guard = is_null($guard) ? '()' : $guard;
|
||||
|
||||
return "<?php if(auth()->guard{$guard}->guest()): ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the else-guest statements into valid PHP.
|
||||
*
|
||||
* @param string|null $guard
|
||||
* @return string
|
||||
*/
|
||||
protected function compileElseGuest($guard = null)
|
||||
{
|
||||
$guard = is_null($guard) ? '()' : $guard;
|
||||
|
||||
return "<?php elseif(auth()->guard{$guard}->guest()): ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the end-guest statements into valid PHP.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function compileEndGuest()
|
||||
{
|
||||
return '<?php endif; ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the has-section statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileHasSection($expression)
|
||||
{
|
||||
return "<?php if (! empty(trim(\$__env->yieldContent{$expression}))): ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the section-missing statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileSectionMissing($expression)
|
||||
{
|
||||
return "<?php if (empty(trim(\$__env->yieldContent{$expression}))): ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the if statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileIf($expression)
|
||||
{
|
||||
return "<?php if{$expression}: ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the unless statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileUnless($expression)
|
||||
{
|
||||
return "<?php if (! {$expression}): ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the else-if statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileElseif($expression)
|
||||
{
|
||||
return "<?php elseif{$expression}: ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the else statements into valid PHP.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function compileElse()
|
||||
{
|
||||
return '<?php else: ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the end-if statements into valid PHP.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function compileEndif()
|
||||
{
|
||||
return '<?php endif; ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the end-unless statements into valid PHP.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function compileEndunless()
|
||||
{
|
||||
return '<?php endif; ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the if-isset statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileIsset($expression)
|
||||
{
|
||||
return "<?php if(isset{$expression}): ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the end-isset statements into valid PHP.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function compileEndIsset()
|
||||
{
|
||||
return '<?php endif; ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the switch statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileSwitch($expression)
|
||||
{
|
||||
$this->firstCaseInSwitch = true;
|
||||
|
||||
return "<?php switch{$expression}:";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the case statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileCase($expression)
|
||||
{
|
||||
if ($this->firstCaseInSwitch) {
|
||||
$this->firstCaseInSwitch = false;
|
||||
|
||||
return "case {$expression}: ?>";
|
||||
}
|
||||
|
||||
return "<?php case {$expression}: ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the default statements in switch case into valid PHP.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function compileDefault()
|
||||
{
|
||||
return '<?php default: ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the end switch statements into valid PHP.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function compileEndSwitch()
|
||||
{
|
||||
return '<?php endswitch; ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile an once block into valid PHP.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function compileOnce($id = null)
|
||||
{
|
||||
$id = $id ? $this->stripParentheses($id) : "'".(string) Str::uuid()."'";
|
||||
|
||||
return '<?php if (! $__env->hasRenderedOnce('.$id.')): $__env->markAsRenderedOnce('.$id.'); ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile an end-once block into valid PHP.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function compileEndOnce()
|
||||
{
|
||||
return '<?php endif; ?>';
|
||||
}
|
||||
}
|
||||
94
vendor/laravel/framework/src/Illuminate/View/Compilers/Concerns/CompilesEchos.php
vendored
Normal file
94
vendor/laravel/framework/src/Illuminate/View/Compilers/Concerns/CompilesEchos.php
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\View\Compilers\Concerns;
|
||||
|
||||
trait CompilesEchos
|
||||
{
|
||||
/**
|
||||
* Compile Blade echos into valid PHP.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
public function compileEchos($value)
|
||||
{
|
||||
foreach ($this->getEchoMethods() as $method) {
|
||||
$value = $this->$method($value);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the echo methods in the proper order for compilation.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getEchoMethods()
|
||||
{
|
||||
return [
|
||||
'compileRawEchos',
|
||||
'compileEscapedEchos',
|
||||
'compileRegularEchos',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the "raw" echo statements.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
protected function compileRawEchos($value)
|
||||
{
|
||||
$pattern = sprintf('/(@)?%s\s*(.+?)\s*%s(\r?\n)?/s', $this->rawTags[0], $this->rawTags[1]);
|
||||
|
||||
$callback = function ($matches) {
|
||||
$whitespace = empty($matches[3]) ? '' : $matches[3].$matches[3];
|
||||
|
||||
return $matches[1] ? substr($matches[0], 1) : "<?php echo {$matches[2]}; ?>{$whitespace}";
|
||||
};
|
||||
|
||||
return preg_replace_callback($pattern, $callback, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the "regular" echo statements.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
protected function compileRegularEchos($value)
|
||||
{
|
||||
$pattern = sprintf('/(@)?%s\s*(.+?)\s*%s(\r?\n)?/s', $this->contentTags[0], $this->contentTags[1]);
|
||||
|
||||
$callback = function ($matches) {
|
||||
$whitespace = empty($matches[3]) ? '' : $matches[3].$matches[3];
|
||||
|
||||
$wrapped = sprintf($this->echoFormat, $matches[2]);
|
||||
|
||||
return $matches[1] ? substr($matches[0], 1) : "<?php echo {$wrapped}; ?>{$whitespace}";
|
||||
};
|
||||
|
||||
return preg_replace_callback($pattern, $callback, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the escaped echo statements.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
37
vendor/laravel/framework/src/Illuminate/View/Compilers/Concerns/CompilesErrors.php
vendored
Normal file
37
vendor/laravel/framework/src/Illuminate/View/Compilers/Concerns/CompilesErrors.php
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\View\Compilers\Concerns;
|
||||
|
||||
trait CompilesErrors
|
||||
{
|
||||
/**
|
||||
* Compile the error statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileError($expression)
|
||||
{
|
||||
$expression = $this->stripParentheses($expression);
|
||||
|
||||
return '<?php $__errorArgs = ['.$expression.'];
|
||||
$__bag = $errors->getBag($__errorArgs[1] ?? \'default\');
|
||||
if ($__bag->has($__errorArgs[0])) :
|
||||
if (isset($message)) { $__messageOriginal = $message; }
|
||||
$message = $__bag->first($__errorArgs[0]); ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the enderror statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileEnderror($expression)
|
||||
{
|
||||
return '<?php unset($message);
|
||||
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
|
||||
endif;
|
||||
unset($__errorArgs, $__bag); ?>';
|
||||
}
|
||||
}
|
||||
49
vendor/laravel/framework/src/Illuminate/View/Compilers/Concerns/CompilesHelpers.php
vendored
Normal file
49
vendor/laravel/framework/src/Illuminate/View/Compilers/Concerns/CompilesHelpers.php
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\View\Compilers\Concerns;
|
||||
|
||||
trait CompilesHelpers
|
||||
{
|
||||
/**
|
||||
* Compile the CSRF statements into valid PHP.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function compileCsrf()
|
||||
{
|
||||
return '<?php echo csrf_field(); ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the "dd" statements into valid PHP.
|
||||
*
|
||||
* @param string $arguments
|
||||
* @return string
|
||||
*/
|
||||
protected function compileDd($arguments)
|
||||
{
|
||||
return "<?php dd{$arguments}; ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the "dump" statements into valid PHP.
|
||||
*
|
||||
* @param string $arguments
|
||||
* @return string
|
||||
*/
|
||||
protected function compileDump($arguments)
|
||||
{
|
||||
return "<?php dump{$arguments}; ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the method statements into valid PHP.
|
||||
*
|
||||
* @param string $method
|
||||
* @return string
|
||||
*/
|
||||
protected function compileMethod($method)
|
||||
{
|
||||
return "<?php echo method_field{$method}; ?>";
|
||||
}
|
||||
}
|
||||
82
vendor/laravel/framework/src/Illuminate/View/Compilers/Concerns/CompilesIncludes.php
vendored
Normal file
82
vendor/laravel/framework/src/Illuminate/View/Compilers/Concerns/CompilesIncludes.php
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\View\Compilers\Concerns;
|
||||
|
||||
trait CompilesIncludes
|
||||
{
|
||||
/**
|
||||
* Compile the each statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileEach($expression)
|
||||
{
|
||||
return "<?php echo \$__env->renderEach{$expression}; ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the include statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileInclude($expression)
|
||||
{
|
||||
$expression = $this->stripParentheses($expression);
|
||||
|
||||
return "<?php echo \$__env->make({$expression}, \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the include-if statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileIncludeIf($expression)
|
||||
{
|
||||
$expression = $this->stripParentheses($expression);
|
||||
|
||||
return "<?php if (\$__env->exists({$expression})) echo \$__env->make({$expression}, \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the include-when statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileIncludeWhen($expression)
|
||||
{
|
||||
$expression = $this->stripParentheses($expression);
|
||||
|
||||
return "<?php echo \$__env->renderWhen($expression, \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path'])); ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the include-unless statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileIncludeUnless($expression)
|
||||
{
|
||||
$expression = $this->stripParentheses($expression);
|
||||
|
||||
return "<?php echo \$__env->renderWhen(! $expression, \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path'])); ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the include-first statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileIncludeFirst($expression)
|
||||
{
|
||||
$expression = $this->stripParentheses($expression);
|
||||
|
||||
return "<?php echo \$__env->first({$expression}, \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>";
|
||||
}
|
||||
}
|
||||
23
vendor/laravel/framework/src/Illuminate/View/Compilers/Concerns/CompilesInjections.php
vendored
Normal file
23
vendor/laravel/framework/src/Illuminate/View/Compilers/Concerns/CompilesInjections.php
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\View\Compilers\Concerns;
|
||||
|
||||
trait CompilesInjections
|
||||
{
|
||||
/**
|
||||
* Compile the inject statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileInject($expression)
|
||||
{
|
||||
$segments = explode(',', preg_replace("/[\(\)\\\"\']/", '', $expression));
|
||||
|
||||
$variable = trim($segments[0]);
|
||||
|
||||
$service = trim($segments[1]);
|
||||
|
||||
return "<?php \${$variable} = app('{$service}'); ?>";
|
||||
}
|
||||
}
|
||||
30
vendor/laravel/framework/src/Illuminate/View/Compilers/Concerns/CompilesJson.php
vendored
Normal file
30
vendor/laravel/framework/src/Illuminate/View/Compilers/Concerns/CompilesJson.php
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\View\Compilers\Concerns;
|
||||
|
||||
trait CompilesJson
|
||||
{
|
||||
/**
|
||||
* The default JSON encoding options.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $encodingOptions = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT;
|
||||
|
||||
/**
|
||||
* Compile the JSON statement into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileJson($expression)
|
||||
{
|
||||
$parts = explode(',', $this->stripParentheses($expression));
|
||||
|
||||
$options = isset($parts[1]) ? trim($parts[1]) : $this->encodingOptions;
|
||||
|
||||
$depth = isset($parts[2]) ? trim($parts[2]) : 512;
|
||||
|
||||
return "<?php echo json_encode($parts[0], $options, $depth) ?>";
|
||||
}
|
||||
}
|
||||
116
vendor/laravel/framework/src/Illuminate/View/Compilers/Concerns/CompilesLayouts.php
vendored
Normal file
116
vendor/laravel/framework/src/Illuminate/View/Compilers/Concerns/CompilesLayouts.php
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\View\Compilers\Concerns;
|
||||
|
||||
trait CompilesLayouts
|
||||
{
|
||||
/**
|
||||
* The name of the last section that was started.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $lastSection;
|
||||
|
||||
/**
|
||||
* Compile the extends statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileExtends($expression)
|
||||
{
|
||||
$expression = $this->stripParentheses($expression);
|
||||
|
||||
$echo = "<?php echo \$__env->make({$expression}, \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>";
|
||||
|
||||
$this->footer[] = $echo;
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the section statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileSection($expression)
|
||||
{
|
||||
$this->lastSection = trim($expression, "()'\" ");
|
||||
|
||||
return "<?php \$__env->startSection{$expression}; ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the @parent directive to a placeholder.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function compileParent()
|
||||
{
|
||||
$escapedLastSection = strtr($this->lastSection, ['\\' => '\\\\', "'" => "\\'"]);
|
||||
|
||||
return "<?php echo \Illuminate\View\Factory::parentPlaceholder('{$escapedLastSection}'); ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the yield statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileYield($expression)
|
||||
{
|
||||
return "<?php echo \$__env->yieldContent{$expression}; ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the show statements into valid PHP.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function compileShow()
|
||||
{
|
||||
return '<?php echo $__env->yieldSection(); ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the append statements into valid PHP.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function compileAppend()
|
||||
{
|
||||
return '<?php $__env->appendSection(); ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the overwrite statements into valid PHP.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function compileOverwrite()
|
||||
{
|
||||
return '<?php $__env->stopSection(true); ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the stop statements into valid PHP.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function compileStop()
|
||||
{
|
||||
return '<?php $__env->stopSection(); ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the end-section statements into valid PHP.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function compileEndsection()
|
||||
{
|
||||
return '<?php $__env->stopSection(); ?>';
|
||||
}
|
||||
}
|
||||
180
vendor/laravel/framework/src/Illuminate/View/Compilers/Concerns/CompilesLoops.php
vendored
Normal file
180
vendor/laravel/framework/src/Illuminate/View/Compilers/Concerns/CompilesLoops.php
vendored
Normal file
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\View\Compilers\Concerns;
|
||||
|
||||
trait CompilesLoops
|
||||
{
|
||||
/**
|
||||
* Counter to keep track of nested forelse statements.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $forElseCounter = 0;
|
||||
|
||||
/**
|
||||
* Compile the for-else statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileForelse($expression)
|
||||
{
|
||||
$empty = '$__empty_'.++$this->forElseCounter;
|
||||
|
||||
preg_match('/\( *(.*) +as *(.*)\)$/is', $expression, $matches);
|
||||
|
||||
$iteratee = trim($matches[1]);
|
||||
|
||||
$iteration = trim($matches[2]);
|
||||
|
||||
$initLoop = "\$__currentLoopData = {$iteratee}; \$__env->addLoop(\$__currentLoopData);";
|
||||
|
||||
$iterateLoop = '$__env->incrementLoopIndices(); $loop = $__env->getLastLoop();';
|
||||
|
||||
return "<?php {$empty} = true; {$initLoop} foreach(\$__currentLoopData as {$iteration}): {$iterateLoop} {$empty} = false; ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the for-else-empty and empty statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileEmpty($expression)
|
||||
{
|
||||
if ($expression) {
|
||||
return "<?php if(empty{$expression}): ?>";
|
||||
}
|
||||
|
||||
$empty = '$__empty_'.$this->forElseCounter--;
|
||||
|
||||
return "<?php endforeach; \$__env->popLoop(); \$loop = \$__env->getLastLoop(); if ({$empty}): ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the end-for-else statements into valid PHP.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function compileEndforelse()
|
||||
{
|
||||
return '<?php endif; ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the end-empty statements into valid PHP.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function compileEndEmpty()
|
||||
{
|
||||
return '<?php endif; ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the for statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileFor($expression)
|
||||
{
|
||||
return "<?php for{$expression}: ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the for-each statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileForeach($expression)
|
||||
{
|
||||
preg_match('/\( *(.*) +as *(.*)\)$/is', $expression, $matches);
|
||||
|
||||
$iteratee = trim($matches[1]);
|
||||
|
||||
$iteration = trim($matches[2]);
|
||||
|
||||
$initLoop = "\$__currentLoopData = {$iteratee}; \$__env->addLoop(\$__currentLoopData);";
|
||||
|
||||
$iterateLoop = '$__env->incrementLoopIndices(); $loop = $__env->getLastLoop();';
|
||||
|
||||
return "<?php {$initLoop} foreach(\$__currentLoopData as {$iteration}): {$iterateLoop} ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the break statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileBreak($expression)
|
||||
{
|
||||
if ($expression) {
|
||||
preg_match('/\(\s*(-?\d+)\s*\)$/', $expression, $matches);
|
||||
|
||||
return $matches ? '<?php break '.max(1, $matches[1]).'; ?>' : "<?php if{$expression} break; ?>";
|
||||
}
|
||||
|
||||
return '<?php break; ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the continue statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileContinue($expression)
|
||||
{
|
||||
if ($expression) {
|
||||
preg_match('/\(\s*(-?\d+)\s*\)$/', $expression, $matches);
|
||||
|
||||
return $matches ? '<?php continue '.max(1, $matches[1]).'; ?>' : "<?php if{$expression} continue; ?>";
|
||||
}
|
||||
|
||||
return '<?php continue; ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the end-for statements into valid PHP.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function compileEndfor()
|
||||
{
|
||||
return '<?php endfor; ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the end-for-each statements into valid PHP.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function compileEndforeach()
|
||||
{
|
||||
return '<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the while statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileWhile($expression)
|
||||
{
|
||||
return "<?php while{$expression}: ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the end-while statements into valid PHP.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function compileEndwhile()
|
||||
{
|
||||
return '<?php endwhile; ?>';
|
||||
}
|
||||
}
|
||||
32
vendor/laravel/framework/src/Illuminate/View/Compilers/Concerns/CompilesRawPhp.php
vendored
Normal file
32
vendor/laravel/framework/src/Illuminate/View/Compilers/Concerns/CompilesRawPhp.php
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\View\Compilers\Concerns;
|
||||
|
||||
trait CompilesRawPhp
|
||||
{
|
||||
/**
|
||||
* Compile the raw PHP statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compilePhp($expression)
|
||||
{
|
||||
if ($expression) {
|
||||
return "<?php {$expression}; ?>";
|
||||
}
|
||||
|
||||
return '@php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the unset statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileUnset($expression)
|
||||
{
|
||||
return "<?php unset{$expression}; ?>";
|
||||
}
|
||||
}
|
||||
59
vendor/laravel/framework/src/Illuminate/View/Compilers/Concerns/CompilesStacks.php
vendored
Normal file
59
vendor/laravel/framework/src/Illuminate/View/Compilers/Concerns/CompilesStacks.php
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\View\Compilers\Concerns;
|
||||
|
||||
trait CompilesStacks
|
||||
{
|
||||
/**
|
||||
* Compile the stack statements into the content.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileStack($expression)
|
||||
{
|
||||
return "<?php echo \$__env->yieldPushContent{$expression}; ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the push statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compilePush($expression)
|
||||
{
|
||||
return "<?php \$__env->startPush{$expression}; ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the end-push statements into valid PHP.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function compileEndpush()
|
||||
{
|
||||
return '<?php $__env->stopPush(); ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the prepend statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compilePrepend($expression)
|
||||
{
|
||||
return "<?php \$__env->startPrepend{$expression}; ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the end-prepend statements into valid PHP.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function compileEndprepend()
|
||||
{
|
||||
return '<?php $__env->stopPrepend(); ?>';
|
||||
}
|
||||
}
|
||||
44
vendor/laravel/framework/src/Illuminate/View/Compilers/Concerns/CompilesTranslations.php
vendored
Normal file
44
vendor/laravel/framework/src/Illuminate/View/Compilers/Concerns/CompilesTranslations.php
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\View\Compilers\Concerns;
|
||||
|
||||
trait CompilesTranslations
|
||||
{
|
||||
/**
|
||||
* Compile the lang statements into valid PHP.
|
||||
*
|
||||
* @param string|null $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileLang($expression)
|
||||
{
|
||||
if (is_null($expression)) {
|
||||
return '<?php $__env->startTranslation(); ?>';
|
||||
} elseif ($expression[1] === '[') {
|
||||
return "<?php \$__env->startTranslation{$expression}; ?>";
|
||||
}
|
||||
|
||||
return "<?php echo app('translator')->get{$expression}; ?>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the end-lang statements into valid PHP.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function compileEndlang()
|
||||
{
|
||||
return '<?php echo $__env->renderTranslation(); ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the choice statements into valid PHP.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return string
|
||||
*/
|
||||
protected function compileChoice($expression)
|
||||
{
|
||||
return "<?php echo app('translator')->choice{$expression}; ?>";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user