name = $name; $this->contents = $this->deferContent($contents, $attributes['defer'] ?? false); $this->attributes = $attributes; } public function name(): string { return $this->name; } public function contents(): string { return $this->contents; } public function toHtml(): string { return str_replace( 'renderAttributes()), $this->contents, ); } protected function deferContent(string $contents, $defer = false): string { if ($defer === false) { return $contents; } $svgContent = strip_tags($contents, ['circle', 'ellipse', 'line', 'path', 'polygon', 'polyline', 'rect', 'g', 'mask', 'defs', 'use']); // Force Unix line endings for hash. $hashContent = str_replace(PHP_EOL, "\n", $svgContent); $hash = 'icon-'.(is_string($defer) ? $defer : md5($hashContent)); $contents = str_replace($svgContent, strtr('', [':href' => '#'.$hash]), $contents).PHP_EOL; $svgContent = ltrim($svgContent, PHP_EOL); $contents .= << {$svgContent} @endpush @endonce BLADE; return $contents; } }