HEX
Server: LiteSpeed
System: Linux s3.sitechai.com 4.18.0-553.51.1.lve.1.el8.x86_64 #1 SMP Wed May 14 14:34:57 UTC 2025 x86_64
User: workzeni (2217)
PHP: 8.1.32
Disabled: mail, show_source, system, shell_exec, passthru, exec, eval, shell
Upload Files
File: /home/workzeni/stream-flix.workzenix.com/vendor/livewire/volt/src/Precompilers/ExtractTemplate.php
<?php

namespace Livewire\Volt\Precompilers;

use Illuminate\Support\Facades\Blade;
use Livewire\Volt\Exceptions\ReturnNewClassExecutionEndingException;
use Livewire\Volt\MountedDirectories;
use Livewire\Volt\Volt;

class ExtractTemplate
{
    use Concerns\ExtractsImports;

    /**
     * Create a new precompiler instance.
     */
    public function __construct(protected MountedDirectories $mountedDirectories) {}

    /**
     * Extracts the template from the given blade view content.
     */
    public function __invoke(string $template): string
    {
        if (! $this->shouldExtractTemplate($template)) {
            return $template;
        }

        $this->ensureNoReturnNewClassExecutionEnding($template);

        return $this->imports($template).
               $this->html($template);
    }

    /**
     * Determine if the current view is a Volt component.
     */
    protected function shouldExtractTemplate(string $template): bool
    {
        if (is_null($path = Blade::getPath())) {
            return false;
        }

        return $this->mountedDirectories->isWithinMountedDirectory($path);
    }

    /**
     * Extract the HTML from the given template.
     */
    protected function html(string $template): string
    {
        $template = trim(preg_replace('/<\?php\s*(.*?)\s*\?>/s', '', $template));

        return str($template)->beforeLast('<?php')->trim()->value();
    }

    /**
     * Ensures the given template does not contain any "return new class" execution ending.
     */
    protected function ensureNoReturnNewClassExecutionEnding(string $template): void
    {
        if (preg_match('/return\s+new\s+class\s+extends\s+Component/', $template) > 0) {
            throw new ReturnNewClassExecutionEndingException;
        }
    }
}